67 #ifndef _graphicsproceduralroundedboxgenerator_cpp
68 #define _graphicsproceduralroundedboxgenerator_cpp
70 #include "Graphics/Procedural/Mesh/roundedboxgenerator.h"
71 #include "Graphics/Procedural/Mesh/planegenerator.h"
73 #include "MathTools/mathtools.h"
123 Real height = ( 1 - MathTools::Abs(XPos) ) * this->
BoxSize.
X + ( 1 - MathTools::Abs(YPos) ) * this->
BoxSize.
Y + ( 1 - MathTools::Abs(ZPos) ) * this->
BoxSize.
Z;
124 Vector3 OffsetPosition = centerPosition - ( vy0 * ( 0.5 * height ) );
135 Real deltaHeight = height / (
Real)numSegHeight;
142 for(
Integer i = 0 ; i <= numSegHeight ; i++ )
148 this->
AddPoint( Buffer,
Vector3( ( vx0 * x0 ) + ( vy0 * ( i * deltaHeight ) ) + ( vz0 * z0 ) + OffsetPosition ),
149 ( vx0 * x0 + vz0 * z0 ).GetNormal(),
152 if( i != numSegHeight && j != this->NumChamferSeg ) {
153 Buffer.
AddIndex( Offset + this->NumChamferSeg + 2 );
155 Buffer.
AddIndex( Offset + this->NumChamferSeg + 1 );
156 Buffer.
AddIndex( Offset + this->NumChamferSeg + 2 );
172 Vector3 OffsetPosition( ( IsXPositive ? 1 : -1 ) * .5f * this->
BoxSize.
X, ( IsYPositive ? 1 : -1 ) * .5f * this->BoxSize.Y, ( IsZPositive ? 1 : -1 ) * .5f * this->BoxSize.Z );
175 Real OffsetRingAngle = IsYPositive ? 0 : MathTools::GetHalfPi();
177 if ( IsXPositive && IsZPositive )
179 if ( ( !IsXPositive ) && IsZPositive )
180 OffsetSegAngle = 1.5f * MathTools::GetPi();
181 if ( IsXPositive && ( !IsZPositive ) )
182 OffsetSegAngle = MathTools::GetHalfPi();
183 if ( ( !IsXPositive ) && ( !IsZPositive ) )
184 OffsetSegAngle = MathTools::GetPi();
195 Real x0 = r0 * sinf( seg * deltaSegAngle + OffsetSegAngle );
196 Real z0 = r0 * cosf( seg * deltaSegAngle + OffsetSegAngle );
199 this->
AddPoint( Buffer,
Vector3( x0 + OffsetPosition.
X, y0 + OffsetPosition.
Y, z0 + OffsetPosition.
Z ),
200 Vector3( x0, y0, z0 ).GetNormal(),
203 if( ( ring != this->NumChamferSeg ) && ( seg != this->NumChamferSeg ) ) {
205 Buffer.
AddIndex( Offset + this->NumChamferSeg + 2 );
207 Buffer.
AddIndex( Offset + this->NumChamferSeg + 1 );
208 Buffer.
AddIndex( Offset + this->NumChamferSeg + 2 );
263 this->
_AddCorner( Buffer,
true,
true,
false );
264 this->
_AddCorner( Buffer,
true,
false,
true );
265 this->
_AddCorner( Buffer,
true,
false,
false );
266 this->
_AddCorner( Buffer,
false,
true,
true );
267 this->
_AddCorner( Buffer,
false,
true,
false );
268 this->
_AddCorner( Buffer,
false,
false,
true );
269 this->
_AddCorner( Buffer,
false,
false,
false );
326 if( ChamferSize <= 0.0 )
362 if( ChamferSeg == 0 )
virtual void AddToTriangleBuffer(TriangleBuffer &Buffer) const
Adds the vertices and indices as configured in this generator to a triangle buffer.
PlaneGenerator & SetNumSegY(const Whole SegY)
Sets the number of segments along local Y axis.
RoundedBoxGenerator & SetSizeZ(const Real SizeZ)
Sets the size of the box along Z axis. the size is set to 0 or less, a PARAMETERS_EXCEPTION will be t...
Vector3 CrossProduct(const Vector3 &Vec) const
This is used to calculate the crossproduct of this and another vector.
bool Boole
Generally acts a single bit, true or false.
Real X
Coordinate on the X vector.
Real Z
Coordinate on the Z vector.
T & SetVTile(const Real vTile)
Sets the V Tile.
RoundedBoxGenerator & SetNumSegX(const Whole SegX)
Sets the number of segments along X axis the number of segments is set to 0, a PARAMETERS_EXCEPTION w...
Whole NumChamferSeg
The number of segments to generate along the length of the rounded edges.
A convenience buffer that stores vertices and indices of a mesh to be generated.
virtual void AddToTriangleBuffer(TriangleBuffer &Buffer) const
Adds the vertices and indices as configured in this generator to a triangle buffer.
Real BoxChamferSize
The radius of the rounded portion of the box corners.
#define MEZZ_EXCEPTION(num, desc)
An easy way to throw exceptions with rich information.
void EstimateIndexCount(const Whole IndexCount)
Gives an estimation of the number of indices needed for this triangle buffer.
void RebaseOffset()
Rebase index offset.
int Integer
A datatype used to represent any integer close to.
T & SetScale(const Vector3 &Scaling)
Sets a scale baked into the resulting mesh.
RoundedBoxGenerator & SetChamferSize(const Real ChamferSize)
Sets the size of the chamfer, ie the radius of the rounded part the size is set to 0 or less...
RoundedBoxGenerator & SetNumSegZ(const Whole SegZ)
Sets the number of segments along Z axis the number of segments is set to 0, a PARAMETERS_EXCEPTION w...
Whole NumSegX
The number of segments to generate along the X axis for each side.
Vector3 Scale
Scale to apply to the mesh.
This implements the exception hiearchy for Mezzanine.
RoundedBoxGenerator & SetNumSegY(const Whole SegY)
Sets the number of segments along Y axis the number of segments is set to 0, a PARAMETERS_EXCEPTION w...
float Real
A Datatype used to represent a real floating point number.
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.
RoundedBoxGenerator(const Vector3 &Size, const Real ChamferSize, const Whole SegX=1, const Whole SegY=1, const Whole SegZ=1, const Whole ChamferSeg=1)
Vector constructor.
A generator class for a plane mesh.
Vector3 GetAntiPermute() const
Gets a anti-permuted copy of this vector.
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.
static Vector3 Unit_Y()
Gets a vector representing the Y unit of a Vector3.
void _AddCorner(TriangleBuffer &Buffer, Boole IsXPositive, Boole IsYPositive, Boole IsZPositive) const
Builds a "corner" of the rounded box, ie a 1/8th of a sphere.
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.
static Vector3 Neg_Unit_X()
Gets a vector representing the negative X unit of a Vector3.
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.
Real VTile
V tile for texture coords generation.
int16_t Int16
An 16-bit integer.
Thrown when parameters are checked at runtime and found invalid.
static Vector3 Unit_X()
Gets a vector representing the X unit of a Vector3.
Vector3 BoxSize
The size of the box to generate.
Real DotProduct(const Vector3 &Vec) const
This is used to calculate the dotproduct of this and another vector.
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 Vector3 Unit_Z()
Gets a vector representing the Z unit of a Vector3.
RoundedBoxGenerator & SetSizeY(const Real SizeY)
Sets the size of the box along Y axis. the size is set to 0 or less, a PARAMETERS_EXCEPTION will be t...
PlaneGenerator & SetNumSegX(const Whole SegX)
Sets the number of segements along local X axis.
TriangleBuffer & AddIndex(const Integer Index)
Adds an index to the index buffer.
Vector3 GetPermute() const
Gets a permuted copy of this vector.
This is used to represent a point in space, or a vector through space.
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 ...
void _AddEdge(TriangleBuffer &Buffer, Int16 XPos, Int16 YPos, Int16 ZPos) const
Builds an "edge" of the rounded box, ie a quarter cylinder.
Whether or not a transform has been defined and is to be used.
The bulk of the engine components go in this namspace.
unsigned long Whole
Whole is an unsigned integer, it will be at least 32bits in size.
virtual ~RoundedBoxGenerator()
Class destructor.
Whole NumSegZ
The number of segments to generate along the Z axis for each side.
T & SetUTile(const Real uTile)
Sets the U Tile.
A generator class for a rounded box mesh.
UInt8 GeneratorOpts
Storage for the boolean options to be used by this generator.
Real UTile
U tile for texture coords generation.
RoundedBoxGenerator & SetSizeX(const Real SizeX)
Sets the size of the box along X axis. the size is set to 0 or less, a PARAMETERS_EXCEPTION will be t...
static Vector3 Neg_Unit_Z()
Gets a vector representing the negative Z unit of a Vector3.
Quaternion Orientation
Orientation to apply the mesh.
Whole NumSegY
The number of segments to generate along the Y axis for each side.
RoundedBoxGenerator & SetNumChamferSeg(const Whole ChamferSeg)
Sets the number of segments along the rounded edge of the box. the number of segments is set to 0...
static Vector3 Neg_Unit_Y()
Gets a vector representing the negative Y unit of a Vector3.
RoundedBoxGenerator & SetSize(const Vector3 &Size)
Sets the size of the box. the size is set to 0 or less, a PARAMETERS_EXCEPTION will be thrown...