Spinning Topp Logo BlackTopp Studios
inc
boxgenerator.cpp
1 // © Copyright 2010 - 2016 BlackTopp Studios Inc.
2 /* This file is part of The Mezzanine Engine.
3 
4  The Mezzanine Engine is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  The Mezzanine Engine is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with The Mezzanine Engine. If not, see <http://www.gnu.org/licenses/>.
16 */
17 /* The original authors have included a copy of the license specified above in the
18  'Docs' folder. See 'gpl.txt'
19 */
20 /* We welcome the use of the Mezzanine engine to anyone, including companies who wish to
21  Build professional software and charge for their product.
22 
23  However there are some practical restrictions, so if your project involves
24  any of the following you should contact us and we will try to work something
25  out:
26  - DRM or Copy Protection of any kind(except Copyrights)
27  - Software Patents You Do Not Wish to Freely License
28  - Any Kind of Linking to Non-GPL licensed Works
29  - Are Currently In Violation of Another Copyright Holder's GPL License
30  - If You want to change our code and not add a few hundred MB of stuff to
31  your distribution
32 
33  These and other limitations could cause serious legal problems if you ignore
34  them, so it is best to simply contact us or the Free Software Foundation, if
35  you have any questions.
36 
37  Joseph Toppi - toppij@gmail.com
38  John Blackwood - makoenergy02@gmail.com
39 */
40 /*
41  -----------------------------------------------------------------------------
42  This source file is part of ogre-procedural
43 
44  For the latest info, see http://code.google.com/p/ogre-procedural/
45 
46  Copyright (c) 2010-2013 Michael Broutin
47 
48  Permission is hereby granted, free of charge, to any person obtaining a copy
49  of this software and associated documentation files (the "Software"), to deal
50  in the Software without restriction, including without limitation the rights
51  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
52  copies of the Software, and to permit persons to whom the Software is
53  furnished to do so, subject to the following conditions:
54 
55  The above copyright notice and this permission notice shall be included in
56  all copies or substantial portions of the Software.
57 
58  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
59  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
60  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
61  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
62  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
63  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
64  THE SOFTWARE.
65  -----------------------------------------------------------------------------
66  */
67 #ifndef _graphicsproceduralboxgenerator_cpp
68 #define _graphicsproceduralboxgenerator_cpp
69 
70 #include "Graphics/Procedural/Mesh/boxgenerator.h"
71 #include "Graphics/Procedural/Mesh/planegenerator.h"
72 
73 #include "exception.h"
74 
75 namespace Mezzanine
76 {
77  namespace Graphics
78  {
79  namespace Procedural
80  {
81  const String BoxGenerator::TAG_NEGX = "box.negx";
82  const String BoxGenerator::TAG_NEGY = "box.negy";
83  const String BoxGenerator::TAG_NEGZ = "box.negz";
84  const String BoxGenerator::TAG_X = "box.x";
85  const String BoxGenerator::TAG_Y = "box.y";
86  const String BoxGenerator::TAG_Z = "box.z";
87 
88  BoxGenerator::BoxGenerator(const Vector3& HalfExtents, const Whole SegX, const Whole SegY, const Whole SegZ)
89  {
90  this->SetHalfExtents(HalfExtents);
91  this->SetNumSegX(SegX);
92  this->SetNumSegY(SegY);
93  this->SetNumSegZ(SegZ);
94  }
95 
96  BoxGenerator::BoxGenerator(const Real HalfSizeX, const Real HalfSizeY, const Real HalfSizeZ, const Whole SegX, const Whole SegY, const Whole SegZ)
97  {
98  this->SetHalfSizeX(HalfSizeX);
99  this->SetHalfSizeY(HalfSizeY);
100  this->SetHalfSizeZ(HalfSizeZ);
101  this->SetNumSegX(SegX);
102  this->SetNumSegY(SegY);
103  this->SetNumSegZ(SegZ);
104  }
105 
107  { }
108 
109  ///////////////////////////////////////////////////////////////////////////////
110  // Utility
111 
113  {
114  PlaneGenerator PG;
115  PG.SetUTile(this->UTile).SetVTile(this->VTile);
116  if( this->GeneratorOpts | GO_Transform ) {
117  PG.SetScale(this->Scale);
118  PG.SetOrientation(this->Orientation);
119  }
120 
121  PG.SetNumSegX(this->NumSegY).SetNumSegY(this->NumSegX).SetSizeX(this->BoxHalf.Y).SetSizeY(this->BoxHalf.X)
123  .SetPosition( this->Scale * ( this->Position + ( this->Orientation * Vector3::Neg_Unit_Z() ) * ( this->BoxHalf.Z * 0.5 ) ) )
124  .AddToTriangleBuffer(Buffer);
125 
126  PG.SetNumSegX(this->NumSegY).SetNumSegY(this->NumSegX).SetSizeX(this->BoxHalf.Y).SetSizeY(this->BoxHalf.X)
128  .SetPosition( this->Scale * ( this->Position + ( this->Orientation * Vector3::Unit_Z() ) * ( this->BoxHalf.Z * 0.5 ) ) )
129  .AddToTriangleBuffer(Buffer);
130 
131  PG.SetNumSegX(this->NumSegZ).SetNumSegY(this->NumSegX).SetSizeX(this->BoxHalf.Z).SetSizeY(this->BoxHalf.X)
133  .SetPosition( this->Scale * ( this->Position + ( this->Orientation * Vector3::Neg_Unit_Y() ) * ( this->BoxHalf.Y * 0.5 ) ) )
134  .AddToTriangleBuffer(Buffer);
135 
136  PG.SetNumSegX(this->NumSegZ).SetNumSegY(this->NumSegX).SetSizeX(this->BoxHalf.Z).SetSizeY(this->BoxHalf.X)
138  .SetPosition( this->Scale * ( this->Position + ( this->Orientation * Vector3::Unit_Y() ) * ( this->BoxHalf.Y * 0.5 ) ) )
139  .AddToTriangleBuffer(Buffer);
140 
141  PG.SetNumSegX(this->NumSegZ).SetNumSegY(this->NumSegY).SetSizeX(this->BoxHalf.Z).SetSizeY(this->BoxHalf.Y)
143  .SetPosition( this->Scale * ( this->Position + ( this->Orientation * Vector3::Neg_Unit_X() ) * ( this->BoxHalf.X * 0.5 ) ) )
144  .AddToTriangleBuffer(Buffer);
145 
146  PG.SetNumSegX(this->NumSegZ).SetNumSegY(this->NumSegY).SetSizeX(this->BoxHalf.Z).SetSizeY(this->BoxHalf.Y)
148  .SetPosition( this->Scale * ( this->Position + ( this->Orientation * Vector3::Unit_X() ) * ( this->BoxHalf.X * 0.5 ) ) )
149  .AddToTriangleBuffer(Buffer);
150  }
151 
152  ///////////////////////////////////////////////////////////////////////////////
153  // Configuration
154 
156  {
157  if( HalfSizeX <= 0.0 )
158  MEZZ_EXCEPTION(ExceptionBase::PARAMETERS_EXCEPTION,"Size on an axis for a generated box mesh must be greater than zero.");
159 
160  this->BoxHalf.X = HalfSizeX;
161  return *this;
162  }
163 
165  {
166  if( HalfSizeY <= 0.0 )
167  MEZZ_EXCEPTION(ExceptionBase::PARAMETERS_EXCEPTION,"Size on an axis for a generated box mesh must be greater than zero.");
168 
169  this->BoxHalf.Y = HalfSizeY;
170  return *this;
171  }
172 
174  {
175  if( HalfSizeZ <= 0.0 )
176  MEZZ_EXCEPTION(ExceptionBase::PARAMETERS_EXCEPTION,"Size on an axis for a generated box mesh must be greater than zero.");
177 
178  this->BoxHalf.Z = HalfSizeZ;
179  return *this;
180  }
181 
183  {
184  this->SetHalfSizeX(HalfExtents.X);
185  this->SetHalfSizeY(HalfExtents.Y);
186  this->SetHalfSizeZ(HalfExtents.Z);
187  return *this;
188  }
189 
191  {
192  if( SegX == 0 )
193  MEZZ_EXCEPTION(ExceptionBase::PARAMETERS_EXCEPTION,"Number of segments for generated box mesh must be greater than zero.");
194 
195  this->NumSegX = SegX;
196  return *this;
197  }
198 
200  {
201  if( SegY == 0 )
202  MEZZ_EXCEPTION(ExceptionBase::PARAMETERS_EXCEPTION,"Number of segments for generated box mesh must be greater than zero.");
203 
204  this->NumSegY = SegY;
205  return *this;
206  }
207 
209  {
210  if( SegZ == 0 )
211  MEZZ_EXCEPTION(ExceptionBase::PARAMETERS_EXCEPTION,"Number of segments for generated box mesh must be greater than zero.");
212 
213  this->NumSegZ = SegZ;
214  return *this;
215  }
216  }//Procedural
217  }//Graphics
218 }//Mezzanine
219 
220 #endif
PlaneGenerator & SetNumSegY(const Whole SegY)
Sets the number of segments along local Y axis.
Real X
Coordinate on the X vector.
Definition: vector3.h:85
A generator class for a box mesh.
Definition: boxgenerator.h:82
Real Z
Coordinate on the Z vector.
Definition: vector3.h:89
T & SetVTile(const Real vTile)
Sets the V Tile.
A convenience buffer that stores vertices and indices of a mesh to be generated.
BoxGenerator & SetHalfSizeY(const Real HalfSizeY)
Sets the half size along the Y axis. the size is set to 0 or less, a PARAMETERS_EXCEPTION will be thr...
Vector3 BoxHalf
The size of the box to generate.
Definition: boxgenerator.h:100
virtual void AddToTriangleBuffer(TriangleBuffer &Buffer) const
Adds the vertices and indices as configured in this generator to a triangle buffer.
BoxGenerator & SetNumSegZ(const Whole SegZ)
Sets the number of segments along Z axis.
static const String TAG_Z
A String containing the name of the Z face of the box.
Definition: boxgenerator.h:96
#define MEZZ_EXCEPTION(num, desc)
An easy way to throw exceptions with rich information.
Definition: exception.h:3048
T & SetScale(const Vector3 &Scaling)
Sets a scale baked into the resulting mesh.
static const String TAG_Y
A String containing the name of the Y face of the box.
Definition: boxgenerator.h:94
Whole NumSegX
The number of segments to generate along the X axis for each face.
Definition: boxgenerator.h:103
BoxGenerator & SetHalfExtents(const Vector3 &HalfExtents)
Sets the half size of the box.
This implements the exception hiearchy for Mezzanine.
float Real
A Datatype used to represent a real floating point number.
Definition: datatypes.h:141
static const String TAG_NEGX
A String containing the name of the Negative X face of the box.
Definition: boxgenerator.h:86
T & SetPosition(const Vector3 &Loc)
Sets a translation baked into the resulting mesh.
T & SetOrientation(const Quaternion &Ori)
Sets an orientation baked into the resulting mesh.
Whole NumSegZ
The number of segments to generate along the Z axis for each face.
Definition: boxgenerator.h:109
static const String TAG_NEGZ
A String containing the name of the Negative Z face of the box.
Definition: boxgenerator.h:90
A generator class for a plane mesh.
Whole NumSegY
The number of segments to generate along the Y axis for each face.
Definition: boxgenerator.h:106
static Vector3 Unit_Y()
Gets a vector representing the Y unit of a Vector3.
Definition: vector3.cpp:134
PlaneGenerator & SetNormal(const Vector3 &Norm)
Sets the normal of the plane. the normal is zero length a PARAMETERS_EXCEPTION will be thrown...
Real Y
Coordinate on the Y vector.
Definition: vector3.h:87
BoxGenerator(const Vector3 &HalfExtents, const Whole SegX=1, const Whole SegY=1, const Whole SegZ=1)
Vector constructor.
static Vector3 Neg_Unit_X()
Gets a vector representing the negative X unit of a Vector3.
Definition: vector3.cpp:140
static const String TAG_X
A String containing the name of the X face of the box.
Definition: boxgenerator.h:92
Real VTile
V tile for texture coords generation.
Thrown when parameters are checked at runtime and found invalid.
Definition: exception.h:108
static Vector3 Unit_X()
Gets a vector representing the X unit of a Vector3.
Definition: vector3.cpp:131
BoxGenerator & SetNumSegX(const Whole SegX)
Sets the number of segments along X axis.
PlaneGenerator & SetSizeX(const Real SizeX)
Sets the size of this plane on the X axis. the size passed in is zero or less a PARAMETERS_EXCEPTION ...
static const String TAG_NEGY
A String containing the name of the Negative Y face of the box.
Definition: boxgenerator.h:88
static Vector3 Unit_Z()
Gets a vector representing the Z unit of a Vector3.
Definition: vector3.cpp:137
PlaneGenerator & SetNumSegX(const Whole SegX)
Sets the number of segements along local X axis.
This is used to represent a point in space, or a vector through space.
Definition: vector3.h:77
PlaneGenerator & SetSizeY(const Real SizeY)
Sets the size of this plane on the Y axis. the size passed in is zero or less a PARAMETERS_EXCEPTION ...
Whether or not a transform has been defined and is to be used.
Definition: meshgenerator.h:95
The bulk of the engine components go in this namspace.
Definition: actor.cpp:56
unsigned long Whole
Whole is an unsigned integer, it will be at least 32bits in size.
Definition: datatypes.h:151
T & SetUTile(const Real uTile)
Sets the U Tile.
BoxGenerator & SetHalfSizeX(const Real HalfSizeX)
Sets the half size along the X axis. the size is set to 0 or less, a PARAMETERS_EXCEPTION will be thr...
virtual void AddToTriangleBuffer(TriangleBuffer &Buffer) const
Adds the vertices and indices as configured in this generator to a triangle buffer.
UInt8 GeneratorOpts
Storage for the boolean options to be used by this generator.
Real UTile
U tile for texture coords generation.
BoxGenerator & SetHalfSizeZ(const Real HalfSizeZ)
Sets the half size along the Z axis. the size is set to 0 or less, a PARAMETERS_EXCEPTION will be thr...
static Vector3 Neg_Unit_Z()
Gets a vector representing the negative Z unit of a Vector3.
Definition: vector3.cpp:146
std::string String
A datatype used to a series of characters.
Definition: datatypes.h:159
Quaternion Orientation
Orientation to apply the mesh.
static Vector3 Neg_Unit_Y()
Gets a vector representing the negative Y unit of a Vector3.
Definition: vector3.cpp:143
BoxGenerator & SetNumSegY(const Whole SegY)
Sets the number of segments along Y axis.