67 #ifndef _graphicsprocedurallathe_cpp
68 #define _graphicsprocedurallathe_cpp
70 #include "Graphics/Procedural/Mesh/lathe.h"
73 #include "Graphics/Procedural/shape.h"
74 #include "Graphics/Procedural/multishape.h"
75 #include "Graphics/Procedural/triangulator.h"
77 #include "MathTools/constants.h"
87 MultiShapeToLathe(NULL),
90 AngleEnd(MathTools::GetTwoPi()),
96 ShapeToLathe(ToLathe),
97 MultiShapeToLathe(NULL),
98 NumSegments(Segments > 2 ? Segments : 3),
100 AngleEnd(MathTools::GetTwoPi()),
107 MultiShapeToLathe(ToLathe),
108 NumSegments(Segments > 2 ? Segments : 3),
110 AngleEnd(MathTools::GetTwoPi()),
135 MultishapeCopy.
Close();
146 for(
Whole CurrPoint = 0 ; CurrPoint < Points.size() ; ++CurrPoint )
148 Vector2 Point2D = Points[CurrPoint];
152 this->
AddPoint(Buffer, Quat * Point3D, Quat * Normal, Point2D);
155 for(
Whole CurrIndex = 0 ; CurrIndex < Indexes.size() / 3 ; ++CurrIndex )
157 Buffer.
AddIndex( Indexes[CurrIndex*3] );
158 Buffer.
AddIndex( Indexes[CurrIndex*3+1] );
159 Buffer.
AddIndex( Indexes[CurrIndex*3+2] );
164 for(
Whole CurrPoint = 0 ; CurrPoint < Points.size() ; ++CurrPoint )
166 Vector2 Point2D = Points[CurrPoint];
170 this->
AddPoint(Buffer, Quat * Point3D, Quat * Normal, Point2D);
173 for(
Whole CurrIndex = 0 ; CurrIndex < Indexes.size() / 3 ; ++CurrIndex )
175 Buffer.
AddIndex( Indexes[CurrIndex*3] );
176 Buffer.
AddIndex( Indexes[CurrIndex*3+2] );
177 Buffer.
AddIndex( Indexes[CurrIndex*3+1] );
183 if( ToLathe == NULL ) {
200 TempEnd += MathTools::GetTwoPi();
203 for(
Integer LatheSegIndex = 0 ; LatheSegIndex < NumLatheSegments ; ++LatheSegIndex )
207 Angle = LatheSegIndex /
static_cast<Real>( this->
NumSegments ) * MathTools::GetTwoPi();
214 for(
Integer ShapeSegIndex = 0 ; ShapeSegIndex <= NumShapeSegments ; ++ShapeSegIndex )
219 Vector3 VertPos(SegStart.
X,SegStart.
Y,0);
220 Vector3 Normal3D(SegNormal.
X,SegNormal.
Y,0);
223 Normal3D = -Normal3D;
226 this->
AddPoint(Buffer, Quat * VertPos, Quat * Normal3D,
Vector2( LatheSegIndex / static_cast<Real>( this->
NumSegments ), ShapeSegIndex / static_cast<Real>( NumShapeSegments ) ) );
228 if( ShapeSegIndex < NumShapeSegments && LatheSegIndex < NumLatheSegments - 1 ) {
230 Buffer.
AddTriangle(Offset + NumShapeSegments + 2, Offset, Offset + NumShapeSegments + 1);
231 Buffer.
AddTriangle(Offset + NumShapeSegments + 2, Offset + 1, Offset);
233 Buffer.
AddTriangle(Offset + NumShapeSegments + 2, Offset + NumShapeSegments + 1, Offset);
234 Buffer.
AddTriangle(Offset + NumShapeSegments + 2, Offset, Offset + 1);
309 this->
Closed = ShapeClosed;
315 this->
Capped = ShapeCapped;
Boole Closed
Whether or not the Lathe is configured to rotate a full 360 degrees.
Real AngleBegin
The angle at which the rotation will start.
Vector2 Perpendicular() const
Generates a Vector2 that is perpendicular to this vector.
bool Boole
Generally acts a single bit, true or false.
const Vector2 & GetPoint(const Integer Index) const
Gets a point by index which can be out of bounds and will wrap.
virtual ~Lathe()
Class destructor.
A convenience buffer that stores vertices and indices of a mesh to be generated.
Procedural::ShapeSide GetOutSide() const
Gets which side is the OutSide of this shape.
void SetFromAxisAngle(const Real &Angle, const Vector3 &Axis)
Generates and sets the values of this quaternion to describe a rotation from an axis and angle on tha...
#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.
MultiShape & Close()
Closes each shape in this MultiShape.
Triangulator & SetShapeToTriangulate(const Shape *TriShape)
Sets shape to triangulate.
void GenerateCaps(TriangleBuffer &Buffer) const
Creates the caps at the ends of the rotated shape.
Vector2 GetAvgDirection(const Whole Index) const
Gets the averaged direction from the specified point to both the next and previous points in the sequ...
Lathe & SetAngleEnd(const Real End)
Sets the endng angle for the rotation.
Whole NumSegments
The number of segments to have when rotating the shape to produce the Mesh. Large number of segments ...
float Real
A Datatype used to represent a real floating point number.
std::vector< Integer > IndexContainer
A container of Integers used to represent the indicies of a shape.
std::vector< Vector2 > Point2DContainer
Basic container type for the storage of 2D points.
Real Y
Coordinate on the Y vector.
Shape & Close()
Makes this a closed shape, connecting the last point to the first point.
Lathe & SetMultiShapeToLathe(MultiShape *ToLathe)
Sets the MultiShape to to be Lathe'd.
Real X
Coordinate on the X 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.
Vector3 & Normalize()
This will change this point into it's own normal relative to the origin.
Whole GetSegCount() const
Gets the number of segments in this shape.
TriangleBuffer & AddTriangle(const Integer Index1, const Integer Index2, const Integer Index3)
Adds a triangle to the index buffer.
Lathe & SetNumSegments(const Whole Segments)
Sets the number of segments in the rotation to generate. the number of segments is being set to a num...
Lathe & SetAngleBegin(const Real Begin)
Sets the starting angle for the rotation.
Lathe & SetShapeToLathe(Shape *ToLathe)
Sets the Shape to to be Lathe'd.
Lathe & SetClosed(const Boole ShapeClosed)
Sets whether or not the start and end segments should be connected.
A generator class that implements the Delaunay Triangulation algorithm.
Thrown when the available information should have worked but failed for unknown reasons.
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.
MultiShape * MultiShapeToLathe
A pointer to the MultiShape that will be used to generate a Mesh.
void Triangulate(IndexContainer &Indexes, Point2DContainer &Vertices) const
Executes the Constrained Delaunay Triangulation algorithm. INVALID_STATE_EXCEPTION will be thrown if ...
Whole GetNumShapes() const
Gets the number of shapes in this MultiShape.
Lathe & SetCapped(const Boole ShapeCapped)
Sets whether or not the outside ends of the rotated shape should be enclosed.
static Vector3 Unit_Z()
Gets a vector representing the Z unit of a Vector3.
TriangleBuffer & AddIndex(const Integer Index)
Adds an index to the index buffer.
This is used to represent a point in space, or a vector through space.
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.
Triangulator & SetMultiShapeToTriangulate(const MultiShape *TriMultiShape)
Sets multi shape to triangulate.
virtual void AddToTriangleBuffer(TriangleBuffer &Buffer) const
Adds the vertices and indices as configured in this generator to a triangle buffer.
Lathe()
Class constructor.
This is used to store information about rotation in 3d space.
Boole Capped
Whether or not the ends should be capped if the shape isn't rotated a full 360 degrees.
A collection of interconnected 2D points used to express an arbitrary 2D shape.
Use the right side of the shape.
Shape & GetShape(const Whole Index)
Gets a shape by index.
Real AngleEnd
The angle at which the rotation will end.
A grouping of individual 2D shapes used to express more elaborate shapes.
Shape * ShapeToLathe
A pointer to the Shape that will be used to generate a Mesh.
static Vector3 Neg_Unit_Z()
Gets a vector representing the negative Z unit of a Vector3.
A generator that produces a Mesh by rotating a 2D shape around the Y axis.
void GenerateBody(TriangleBuffer &Buffer, const Shape *ToLathe) const
Creates the main body of the lathe'd shape.