Spinning Topp Logo BlackTopp Studios
inc
boxcornergenerator.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 _graphicsproceduralboxcornergenerator_cpp
68 #define _graphicsproceduralboxcornergenerator_cpp
69 
70 #include "Graphics/Procedural/Mesh/boxcornergenerator.h"
71 
72 #include "exception.h"
73 
74 namespace Mezzanine
75 {
76  namespace Graphics
77  {
78  namespace Procedural
79  {
80  BoxCornerGenerator::BoxCornerGenerator(const Vector3& Size, const Real CornerThickness)
81  {
82  this->SetHalfExtents(Size);
83  this->SetCornerThickness(CornerThickness);
84  }
85 
86  BoxCornerGenerator::BoxCornerGenerator(const Real HalfSizeX, const Real HalfSizeY, const Real HalfSizeZ, const Real CornerThickness)
87  {
88  this->SetHalfSizeX(HalfSizeX);
89  this->SetHalfSizeY(HalfSizeY);
90  this->SetHalfSizeZ(HalfSizeZ);
91  this->SetCornerThickness(CornerThickness);
92  }
93 
95  { }
96 
97  ///////////////////////////////////////////////////////////////////////////////
98  // Utility
99 
101  {
102  Vector3 Half = this->BoxHalf;
103  Vector3 Full = this->BoxHalf * 2;
104 
105  Real Length = 0.0;
106  Real FirstSizeCheck = Half .X < Half .Y ? Half .X : Half .Y;
107  Real Smallest = FirstSizeCheck < Half .Z ? FirstSizeCheck : Half .Z;
108  if( Smallest * 2 <= FirstSizeCheck ) {
109  Length = Smallest * 0.5;
110  }else{
111  Length = Smallest * 0.25;
112  }
113  Buffer.RebaseOffset();
114  Buffer.EstimateVertexCount( 54 * 8 ); //Verts per corner times the number of corners
115  Buffer.EstimateIndexCount( 54 * 8 ); //Verts per corner times the number of corners
116 
117  // Create a list of data we can play around with
118  std::vector<Procedural::Vertex> BoxVertices;
119  //Vertex //Normal //TextureCoord
120  // Forward Face // 0 /
121  BoxVertices.push_back( Vertex( Vector3(-Half.X,Half.Y,Half.Z), Vector3(0,0,1), Vector2(0,0) ) );
122  BoxVertices.push_back( Vertex( Vector3(-Half.X,Half.Y - Length,Half.Z), Vector3(0,0,1), Vector2(0,0.5) ) );
123  BoxVertices.push_back( Vertex( Vector3(-Half.X + this->BoxThick,Half.Y - Length,Half.Z), Vector3(0,0,1), Vector2(this->BoxThick / Full.X,0.5) ) );
124  BoxVertices.push_back( Vertex( Vector3(-Half.X + this->BoxThick,Half.Y - this->BoxThick,Half.Z), Vector3(0,0,1), Vector2(this->BoxThick / Full.X,this->BoxThick / Full.Y) ) );
125  BoxVertices.push_back( Vertex( Vector3(-Half.X + Length,Half.Y - this->BoxThick,Half.Z), Vector3(0,0,1), Vector2(0.5,this->BoxThick / Full.Y) ) );
126  BoxVertices.push_back( Vertex( Vector3(-Half.X + Length,Half.Y,Half.Z), Vector3(0,0,1), Vector2(0.5,0) ) );
127  // Upward Face // 6 */
128  BoxVertices.push_back( Vertex( Vector3(-Half.X,Half.Y,Half.Z), Vector3(0,1,0), Vector2(0,1) ) );
129  BoxVertices.push_back( Vertex( Vector3(-Half.X + Length,Half.Y,Half.Z), Vector3(0,1,0), Vector2(0.5,1) ) );
130  BoxVertices.push_back( Vertex( Vector3(-Half.X + Length,Half.Y,Half.Z - this->BoxThick), Vector3(0,1,0), Vector2(0.5,1 - (this->BoxThick / Full.Y) ) ) );
131  BoxVertices.push_back( Vertex( Vector3(-Half.X + this->BoxThick,Half.Y,Half.Z - this->BoxThick), Vector3(0,1,0), Vector2(this->BoxThick / Full.X,1 - (this->BoxThick / Full.Y) ) ) );
132  BoxVertices.push_back( Vertex( Vector3(-Half.X + this->BoxThick,Half.Y,Half.Z - Length), Vector3(0,1,0), Vector2(this->BoxThick / Full.X,0.5) ) );
133  BoxVertices.push_back( Vertex( Vector3(-Half.X,Half.Y,Half.Z - Length), Vector3(0,1,0), Vector2(0,0.5) ) );
134  // Left Face // 12 */
135  BoxVertices.push_back( Vertex( Vector3(-Half.X,Half.Y,Half.Z), Vector3(-1,0,0), Vector2(1,0) ) );
136  BoxVertices.push_back( Vertex( Vector3(-Half.X,Half.Y,Half.Z - Length), Vector3(-1,0,0), Vector2(0.5,0) ) );
137  BoxVertices.push_back( Vertex( Vector3(-Half.X,Half.Y - this->BoxThick,Half.Z - Length), Vector3(-1,0,0), Vector2(0.5,this->BoxThick / Full.Y) ) );
138  BoxVertices.push_back( Vertex( Vector3(-Half.X,Half.Y - this->BoxThick,Half.Z - this->BoxThick), Vector3(-1,0,0), Vector2(1 - (this->BoxThick / Full.X),this->BoxThick / Full.Y) ) );
139  BoxVertices.push_back( Vertex( Vector3(-Half.X,Half.Y - Length,Half.Z - this->BoxThick), Vector3(-1,0,0), Vector2(1 - (this->BoxThick / Full.X),0.5) ) );
140  BoxVertices.push_back( Vertex( Vector3(-Half.X,Half.Y - Length,Half.Z), Vector3(-1,0,0), Vector2(1,0.5) ) );
141  // Backward Faces // 18 */
142  BoxVertices.push_back( Vertex( Vector3(-Half.X + Length,Half.Y,Half.Z - this->BoxThick), Vector3(0,0,-1), Vector2(0.5,0) ) );
143  BoxVertices.push_back( Vertex( Vector3(-Half.X + Length,Half.Y - this->BoxThick,Half.Z - this->BoxThick), Vector3(0,0,-1), Vector2(0.5,this->BoxThick / Full.Y) ) );
144  BoxVertices.push_back( Vertex( Vector3(-Half.X + this->BoxThick,Half.Y - this->BoxThick,Half.Z - this->BoxThick), Vector3(0,0,-1), Vector2(1 - (this->BoxThick / Full.X),this->BoxThick / Full.Y) ) );
145  BoxVertices.push_back( Vertex( Vector3(-Half.X + this->BoxThick,Half.Y,Half.Z - this->BoxThick), Vector3(0,0,-1), Vector2(1 - (this->BoxThick / Full.X),0) ) );
146  BoxVertices.push_back( Vertex( Vector3(-Half.X + this->BoxThick,Half.Y,Half.Z - Length), Vector3(0,0,-1), Vector2(1 - (this->BoxThick / Full.X),0) ) );
147  BoxVertices.push_back( Vertex( Vector3(-Half.X + this->BoxThick,Half.Y - this->BoxThick,Half.Z - Length), Vector3(0,0,-1), Vector2(1 - (this->BoxThick / Full.X),this->BoxThick / Full.Y) ) );
148  BoxVertices.push_back( Vertex( Vector3(-Half.X,Half.Y - this->BoxThick,Half.Z - Length), Vector3(0,0,-1), Vector2(1,this->BoxThick / Full.Y) ) );
149  BoxVertices.push_back( Vertex( Vector3(-Half.X,Half.Y,Half.Z - Length), Vector3(0,0,-1), Vector2(1,0) ) );
150  BoxVertices.push_back( Vertex( Vector3(-Half.X + this->BoxThick,Half.Y - this->BoxThick,Half.Z - this->BoxThick), Vector3(0,0,-1), Vector2(1 - (this->BoxThick / Full.X),this->BoxThick / Full.Y) ) );
151  BoxVertices.push_back( Vertex( Vector3(-Half.X + this->BoxThick,Half.Y - Length,Half.Z - this->BoxThick), Vector3(0,0,-1), Vector2(1 - (this->BoxThick / Full.X),0.5) ) );
152  BoxVertices.push_back( Vertex( Vector3(-Half.X,Half.Y - Length,Half.Z - this->BoxThick), Vector3(0,0,-1), Vector2(1,0.5) ) );
153  BoxVertices.push_back( Vertex( Vector3(-Half.X,Half.Y - this->BoxThick,Half.Z - this->BoxThick), Vector3(0,0,-1), Vector2(1,this->BoxThick / Full.Y) ) );
154  // Downward Faces // 30 */
155  BoxVertices.push_back( Vertex( Vector3(-Half.X + this->BoxThick,Half.Y - this->BoxThick,Half.Z), Vector3(0,-1,0), Vector2(this->BoxThick / Full.X,0) ) );
156  BoxVertices.push_back( Vertex( Vector3(-Half.X + this->BoxThick,Half.Y - this->BoxThick,Half.Z - this->BoxThick), Vector3(0,-1,0), Vector2(this->BoxThick / Full.X,this->BoxThick / Full.Y) ) );
157  BoxVertices.push_back( Vertex( Vector3(-Half.X + Length,Half.Y - this->BoxThick,Half.Z - this->BoxThick), Vector3(0,-1,0), Vector2(0.5,this->BoxThick / Full.Y) ) );
158  BoxVertices.push_back( Vertex( Vector3(-Half.X + Length,Half.Y - this->BoxThick,Half.Z), Vector3(0,-1,0), Vector2(0.5,0) ) );
159  BoxVertices.push_back( Vertex( Vector3(-Half.X,Half.Y - Length,Half.Z), Vector3(0,-1,0), Vector2(0,0) ) );
160  BoxVertices.push_back( Vertex( Vector3(-Half.X,Half.Y - Length,Half.Z - this->BoxThick), Vector3(0,-1,0), Vector2(0,this->BoxThick / Full.Y) ) );
161  BoxVertices.push_back( Vertex( Vector3(-Half.X + this->BoxThick,Half.Y - Length,Half.Z - this->BoxThick), Vector3(0,-1,0), Vector2(this->BoxThick / Full.X,this->BoxThick / Full.Y) ) );
162  BoxVertices.push_back( Vertex( Vector3(-Half.X + this->BoxThick,Half.Y - Length,Half.Z), Vector3(0,-1,0), Vector2(this->BoxThick / Full.X,0) ) );
163  BoxVertices.push_back( Vertex( Vector3(-Half.X,Half.Y - this->BoxThick,Half.Z - this->BoxThick), Vector3(0,-1,0), Vector2(0,this->BoxThick / Full.Y) ) );
164  BoxVertices.push_back( Vertex( Vector3(-Half.X,Half.Y - this->BoxThick,Half.Z - Length), Vector3(0,-1,0), Vector2(0,0.5) ) );
165  BoxVertices.push_back( Vertex( Vector3(-Half.X + this->BoxThick,Half.Y - this->BoxThick,Half.Z - Length), Vector3(0,-1,0), Vector2(this->BoxThick / Full.X,0.5) ) );
166  BoxVertices.push_back( Vertex( Vector3(-Half.X + this->BoxThick,Half.Y - this->BoxThick,Half.Z - this->BoxThick), Vector3(0,-1,0), Vector2(this->BoxThick / Full.X,this->BoxThick / Full.Y) ) );
167  // Right Faces // 42 */
168  BoxVertices.push_back( Vertex( Vector3(-Half.X + this->BoxThick,Half.Y,Half.Z - this->BoxThick), Vector3(1,0,0), Vector2(this->BoxThick / Full.X,0) ) );
169  BoxVertices.push_back( Vertex( Vector3(-Half.X + this->BoxThick,Half.Y - this->BoxThick,Half.Z - this->BoxThick), Vector3(1,0,0), Vector2(this->BoxThick / Full.X,this->BoxThick / Full.Y) ) );
170  BoxVertices.push_back( Vertex( Vector3(-Half.X + this->BoxThick,Half.Y - this->BoxThick,Half.Z - Length), Vector3(1,0,0), Vector2(0.5,this->BoxThick / Full.Y) ) );
171  BoxVertices.push_back( Vertex( Vector3(-Half.X + this->BoxThick,Half.Y,Half.Z - Length), Vector3(1,0,0), Vector2(0.5,0) ) );
172  BoxVertices.push_back( Vertex( Vector3(-Half.X + Length,Half.Y,Half.Z), Vector3(1,0,0), Vector2(0,0) ) );
173  BoxVertices.push_back( Vertex( Vector3(-Half.X + Length,Half.Y - this->BoxThick,Half.Z), Vector3(1,0,0), Vector2(0,this->BoxThick / Full.Y) ) );
174  BoxVertices.push_back( Vertex( Vector3(-Half.X + Length,Half.Y - this->BoxThick,Half.Z - this->BoxThick), Vector3(1,0,0), Vector2(this->BoxThick / Full.X,this->BoxThick / Full.Y) ) );
175  BoxVertices.push_back( Vertex( Vector3(-Half.X + Length,Half.Y,Half.Z - this->BoxThick), Vector3(1,0,0), Vector2(this->BoxThick / Full.X,0) ) );
176  BoxVertices.push_back( Vertex( Vector3(-Half.X + this->BoxThick,Half.Y - this->BoxThick,Half.Z), Vector3(1,0,0), Vector2(0,this->BoxThick / Full.Y) ) );
177  BoxVertices.push_back( Vertex( Vector3(-Half.X + this->BoxThick,Half.Y - Length,Half.Z), Vector3(1,0,0), Vector2(0,0.5) ) );
178  BoxVertices.push_back( Vertex( Vector3(-Half.X + this->BoxThick,Half.Y - Length,Half.Z - this->BoxThick), Vector3(1,0,0), Vector2(this->BoxThick / Full.X,0.5) ) );
179  BoxVertices.push_back( Vertex( Vector3(-Half.X + this->BoxThick,Half.Y - this->BoxThick,Half.Z - this->BoxThick), Vector3(1,0,0), Vector2(this->BoxThick / Full.X,this->BoxThick / Full.Y) ) );
180 
181  // Each of the flips we need to make
182  std::vector<Vector3> Flips;
183  Flips.push_back( Vector3(1,1,1) );
184  Flips.push_back( Vector3(1,1,-1) );
185  Flips.push_back( Vector3(1,-1,1) );
186  Flips.push_back( Vector3(-1,1,1) );
187  Flips.push_back( Vector3(1,-1,-1) );
188  Flips.push_back( Vector3(-1,1,-1) );
189  Flips.push_back( Vector3(-1,-1,1) );
190  Flips.push_back( Vector3(-1,-1,-1) );
191 
192  // Flip this set of points against the list of flips
193  for( std::vector<Vector3>::iterator CurrentFlip = Flips.begin() ; CurrentFlip != Flips.end() ; ++CurrentFlip )
194  {
195  for( std::vector<Procedural::Vertex>::iterator CurrentVertex = BoxVertices.begin() ; CurrentVertex != BoxVertices.end() ; ++CurrentVertex )
196  {
197  this->AddPoint( Buffer,
198  (*CurrentVertex).Position * (*CurrentFlip),
199  (*CurrentVertex).Normal * (*CurrentFlip),
200  (*CurrentVertex).UV );
201  }
202  }
203 
204  // Create Index's
205  for( Whole FlipCount = 0 ; FlipCount<Flips.size() ; ++FlipCount )
206  {
207  Whole ShapeIndex = FlipCount * BoxVertices.size();
208 
209  // Top-Left-Front Forward Face
210  if( 1 == Flips.at(FlipCount).Z ) { // draw them in backward order if this shape is flipped on the Z axis
211  //Forward Face Unflipped
212  Buffer.AddTriangle( 0 + ShapeIndex, 1 + ShapeIndex, 2 + ShapeIndex ); // These things could be replaced by a series of loops, but this was simpler
213  Buffer.AddTriangle( 0 + ShapeIndex, 2 + ShapeIndex, 3 + ShapeIndex );
214  Buffer.AddTriangle( 0 + ShapeIndex, 3 + ShapeIndex, 4 + ShapeIndex );
215  Buffer.AddTriangle( 0 + ShapeIndex, 4 + ShapeIndex, 5 + ShapeIndex );
216  //Backward Faces Unflipped
217  Buffer.AddTriangle( 18 + ShapeIndex, 19 + ShapeIndex, 20 + ShapeIndex );
218  Buffer.AddTriangle( 18 + ShapeIndex, 20 + ShapeIndex, 21 + ShapeIndex );
219  Buffer.AddTriangle( 22 + ShapeIndex, 23 + ShapeIndex, 24 + ShapeIndex );
220  Buffer.AddTriangle( 22 + ShapeIndex, 24 + ShapeIndex, 25 + ShapeIndex );
221  Buffer.AddTriangle( 26 + ShapeIndex, 27 + ShapeIndex, 28 + ShapeIndex );
222  Buffer.AddTriangle( 26 + ShapeIndex, 28 + ShapeIndex, 29 + ShapeIndex );
223  }else{
224  //Forward Face Flipped
225  Buffer.AddTriangle( 0 + ShapeIndex, 1 + ShapeIndex, 2 + ShapeIndex );
226  Buffer.AddTriangle( 0 + ShapeIndex, 3 + ShapeIndex, 4 + ShapeIndex );
227  Buffer.AddTriangle( 0 + ShapeIndex, 2 + ShapeIndex, 3 + ShapeIndex );
228  Buffer.AddTriangle( 0 + ShapeIndex, 4 + ShapeIndex, 5 + ShapeIndex );
229  //Backward Faces Flipped
230  Buffer.AddTriangle( 26 + ShapeIndex, 28 + ShapeIndex, 29 + ShapeIndex );
231  Buffer.AddTriangle( 26 + ShapeIndex, 27 + ShapeIndex, 28 + ShapeIndex );
232  Buffer.AddTriangle( 22 + ShapeIndex, 24 + ShapeIndex, 25 + ShapeIndex );
233  Buffer.AddTriangle( 22 + ShapeIndex, 23 + ShapeIndex, 24 + ShapeIndex );
234  Buffer.AddTriangle( 18 + ShapeIndex, 20 + ShapeIndex, 21 + ShapeIndex );
235  Buffer.AddTriangle( 18 + ShapeIndex, 19 + ShapeIndex, 20 + ShapeIndex );
236  }
237 
238  if( 1 == Flips.at(FlipCount).Y ) { // draw them in backward order if this shape is flipped on the Y axis
239  // Upward Face Unflipped
240  Buffer.AddTriangle( 6 + ShapeIndex, 7 + ShapeIndex, 8 + ShapeIndex );
241  Buffer.AddTriangle( 6 + ShapeIndex, 8 + ShapeIndex, 9 + ShapeIndex );
242  Buffer.AddTriangle( 6 + ShapeIndex, 9 + ShapeIndex, 10 + ShapeIndex );
243  Buffer.AddTriangle( 6 + ShapeIndex, 10 + ShapeIndex, 11 + ShapeIndex );
244  // Downward Faces Unflipped
245  Buffer.AddTriangle( 30 + ShapeIndex, 31 + ShapeIndex, 32 + ShapeIndex );
246  Buffer.AddTriangle( 30 + ShapeIndex, 32 + ShapeIndex, 33 + ShapeIndex );
247  Buffer.AddTriangle( 34 + ShapeIndex, 35 + ShapeIndex, 36 + ShapeIndex );
248  Buffer.AddTriangle( 34 + ShapeIndex, 36 + ShapeIndex, 37 + ShapeIndex );
249  Buffer.AddTriangle( 38 + ShapeIndex, 39 + ShapeIndex, 40 + ShapeIndex );
250  Buffer.AddTriangle( 38 + ShapeIndex, 40 + ShapeIndex, 41 + ShapeIndex );
251  }else{
252  // Upward Face Flipped
253  Buffer.AddTriangle( 6 + ShapeIndex, 10 + ShapeIndex, 11 + ShapeIndex );
254  Buffer.AddTriangle( 6 + ShapeIndex, 9 + ShapeIndex, 10 + ShapeIndex );
255  Buffer.AddTriangle( 6 + ShapeIndex, 8 + ShapeIndex, 9 + ShapeIndex );
256  Buffer.AddTriangle( 6 + ShapeIndex, 7 + ShapeIndex, 8 + ShapeIndex );
257  // Downward Faces Flipped
258  Buffer.AddTriangle( 38 + ShapeIndex, 40 + ShapeIndex, 41 + ShapeIndex );
259  Buffer.AddTriangle( 38 + ShapeIndex, 39 + ShapeIndex, 40 + ShapeIndex );
260  Buffer.AddTriangle( 34 + ShapeIndex, 36 + ShapeIndex, 37 + ShapeIndex );
261  Buffer.AddTriangle( 34 + ShapeIndex, 35 + ShapeIndex, 36 + ShapeIndex );
262  Buffer.AddTriangle( 30 + ShapeIndex, 32 + ShapeIndex, 33 + ShapeIndex );
263  Buffer.AddTriangle( 30 + ShapeIndex, 31 + ShapeIndex, 32 + ShapeIndex );
264  }
265 
266  if( 1 == Flips.at(FlipCount).X ) { // draw them in backward order if this shape is flipped on the X axis
267  // Left Face Unflipped
268  Buffer.AddTriangle( 12 + ShapeIndex, 13 + ShapeIndex, 14 + ShapeIndex );
269  Buffer.AddTriangle( 12 + ShapeIndex, 14 + ShapeIndex, 15 + ShapeIndex );
270  Buffer.AddTriangle( 12 + ShapeIndex, 15 + ShapeIndex, 16 + ShapeIndex );
271  Buffer.AddTriangle( 12 + ShapeIndex, 16 + ShapeIndex, 17 + ShapeIndex );
272  // Right Faces Unflipped
273  Buffer.AddTriangle( 42 + ShapeIndex, 43 + ShapeIndex, 44 + ShapeIndex );
274  Buffer.AddTriangle( 42 + ShapeIndex, 44 + ShapeIndex, 45 + ShapeIndex );
275  Buffer.AddTriangle( 46 + ShapeIndex, 47 + ShapeIndex, 48 + ShapeIndex );
276  Buffer.AddTriangle( 46 + ShapeIndex, 48 + ShapeIndex, 49 + ShapeIndex );
277  Buffer.AddTriangle( 50 + ShapeIndex, 51 + ShapeIndex, 52 + ShapeIndex );
278  Buffer.AddTriangle( 50 + ShapeIndex, 52 + ShapeIndex, 53 + ShapeIndex );
279  }else{
280  // Left Face Unflipped
281  Buffer.AddTriangle( 12 +ShapeIndex, 16 + ShapeIndex, 17 + ShapeIndex );
282  Buffer.AddTriangle( 12 +ShapeIndex, 15 + ShapeIndex, 16 + ShapeIndex );
283  Buffer.AddTriangle( 12 +ShapeIndex, 14 + ShapeIndex, 15 + ShapeIndex );
284  Buffer.AddTriangle( 12 +ShapeIndex, 13 + ShapeIndex, 14 + ShapeIndex );
285  // Right Faces Unflipped
286  Buffer.AddTriangle( 50 + ShapeIndex, 52 + ShapeIndex, 53 + ShapeIndex );
287  Buffer.AddTriangle( 50 + ShapeIndex, 51 + ShapeIndex, 52 + ShapeIndex );
288  Buffer.AddTriangle( 46 + ShapeIndex, 48 + ShapeIndex, 49 + ShapeIndex );
289  Buffer.AddTriangle( 46 + ShapeIndex, 47 + ShapeIndex, 48 + ShapeIndex );
290  Buffer.AddTriangle( 42 + ShapeIndex, 44 + ShapeIndex, 45 + ShapeIndex );
291  Buffer.AddTriangle( 42 + ShapeIndex, 43 + ShapeIndex, 44 + ShapeIndex );
292  }
293  }
294  }
295 
296  ///////////////////////////////////////////////////////////////////////////////
297  // Configuration
298 
300  {
301  if( HalfSizeX <= 0.0 )
302  MEZZ_EXCEPTION(ExceptionBase::PARAMETERS_EXCEPTION,"Size on an axis for a generated box-corner mesh must be greater than zero.");
303 
304  this->BoxHalf.X = HalfSizeX;
305  return *this;
306  }
307 
309  {
310  if( HalfSizeY <= 0.0 )
311  MEZZ_EXCEPTION(ExceptionBase::PARAMETERS_EXCEPTION,"Size on an axis for a generated box-corner mesh must be greater than zero.");
312 
313  this->BoxHalf.Y = HalfSizeY;
314  return *this;
315  }
316 
318  {
319  if( HalfSizeZ <= 0.0 )
320  MEZZ_EXCEPTION(ExceptionBase::PARAMETERS_EXCEPTION,"Size on an axis for a generated box-corner mesh must be greater than zero.");
321 
322  this->BoxHalf.Z = HalfSizeZ;
323  return *this;
324  }
325 
327  {
328  this->SetHalfSizeX(HalfExtents.X);
329  this->SetHalfSizeY(HalfExtents.Y);
330  this->SetHalfSizeZ(HalfExtents.Z);
331  return *this;
332  }
333 
335  {
336  if( CornerThickness == 0 )
337  MEZZ_EXCEPTION(ExceptionBase::PARAMETERS_EXCEPTION,"Number of segments for generated box-corner mesh must be greater than zero.");
338 
339  this->BoxThick = CornerThickness;
340  return *this;
341  }
342  }//Procedural
343  }//Graphics
344 }//Mezzanine
345 
346 #endif
BoxCornerGenerator & SetCornerThickness(const Real CornerThickness)
Sets how far into the box from the edge for each axis the corner component will be sized for...
Real BoxThick
The thickness of boxes that will be generated in each corner for each axis.
Real X
Coordinate on the X vector.
Definition: vector3.h:85
Real Z
Coordinate on the Z vector.
Definition: vector3.h:89
BoxCornerGenerator & 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...
A convenience buffer that stores vertices and indices of a mesh to be generated.
A generator class for a mesh composed of boxes that outline the corner edges of a larger box...
#define MEZZ_EXCEPTION(num, desc)
An easy way to throw exceptions with rich information.
Definition: exception.h:3048
void EstimateIndexCount(const Whole IndexCount)
Gives an estimation of the number of indices needed for this triangle buffer.
A simple definition for a Vertex to be used when procedurally generating meshes.
Vector3 BoxHalf
The size of the box to generate.
This implements the exception hiearchy for Mezzanine.
float Real
A Datatype used to represent a real floating point number.
Definition: datatypes.h:141
BoxCornerGenerator & SetHalfExtents(const Vector3 &HalfExtents)
Sets the half size of the box.
void EstimateVertexCount(const Whole VertexCount)
Gives an estimation of the number of vertices need for this triangle buffer.
This is used to represent a point on a 2 dimentional area, such as a screen.
Definition: vector2.h:63
TriangleBuffer & AddTriangle(const Integer Index1, const Integer Index2, const Integer Index3)
Adds a triangle to the index buffer.
Real Y
Coordinate on the Y vector.
Definition: vector3.h:87
BoxCornerGenerator & 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...
void AddPoint(TriangleBuffer &Buffer, const Vector3 &Loc, const Vector3 &Norm, const Vector2 &UV) const
Adds a new point to a triangle buffer, using the format defined for that MeshGenerator.
Thrown when parameters are checked at runtime and found invalid.
Definition: exception.h:108
This is used to represent a point in space, or a vector through space.
Definition: vector3.h:77
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
BoxCornerGenerator(const Vector3 &HalfExtents, const Real CornerThickness)
Vector constructor.
virtual void AddToTriangleBuffer(TriangleBuffer &Buffer) const
Adds the vertices and indices as configured in this generator to a triangle buffer.
BoxCornerGenerator & 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...