67 #ifndef _graphicsproceduralpath_cpp
68 #define _graphicsproceduralpath_cpp
70 #include "Graphics/Procedural/path.h"
71 #include "Graphics/Procedural/shape.h"
73 #include "Graphics/meshmanager.h"
75 #include "MathTools/mathtools.h"
107 typedef std::multimap<Vector3,Vector3,Vector3LengthCompare> Vec3MultiMap;
108 typedef Vec3MultiMap::iterator Vec3MapIterator;
109 typedef std::pair<Vec3MapIterator, Vec3MapIterator> Vec3MapRange;
110 typedef std::pair<Vector3,Vector3> Vec3Pair;
112 Vec3MultiMap SegmentMap;
115 SegmentMap.insert( Vec3Pair( SegIt->PointA, SegIt->PointB ) );
116 SegmentMap.insert( Vec3Pair( SegIt->PointB, SegIt->PointA ) );
118 while( !SegmentMap.empty() )
120 Vector3 HeadFirst = SegmentMap.begin()->first;
121 Vector3 HeadSecond = SegmentMap.begin()->second;
125 Vec3MapIterator FirstSeg = SegmentMap.begin();
126 Vec3MapRange Correspondants2 = SegmentMap.equal_range(HeadSecond);
127 for( Vec3MapIterator CorrIt = Correspondants2.first ; CorrIt != Correspondants2.second ; )
129 Vec3MapIterator RemoveIt = CorrIt++;
130 if( ( RemoveIt->second - FirstSeg->first ).SquaredLength() < 1e-8 ) {
131 SegmentMap.erase(RemoveIt);
134 SegmentMap.erase(FirstSeg);
135 Boole FoundSomething =
true;
136 while( !SegmentMap.empty() && FoundSomething )
138 FoundSomething =
false;
139 Vec3MapIterator Next = SegmentMap.find(HeadSecond);
140 if( Next != SegmentMap.end() ) {
141 FoundSomething =
true;
142 HeadSecond = Next->second;
144 Vec3MapRange Correspondants = SegmentMap.equal_range(HeadSecond);
145 for( Vec3MapIterator CorrIt = Correspondants.first ; CorrIt != Correspondants.second ; )
147 Vec3MapIterator RemoveIt = CorrIt++;
148 if( ( RemoveIt->second - Next->first ).SquaredLength() < 1e-8 ) {
149 SegmentMap.erase(RemoveIt);
152 SegmentMap.erase(Next);
154 Vec3MapIterator Previous = SegmentMap.find(HeadFirst);
155 if( Previous != SegmentMap.end() ) {
156 FoundSomething =
true;
158 HeadFirst = Previous->second;
159 Vec3MapRange Correspondants = SegmentMap.equal_range(HeadFirst);
160 for( Vec3MapIterator CorrIt = Correspondants.first ; CorrIt != Correspondants.second ; )
162 Vec3MapIterator RemoveIt = CorrIt++;
163 if( ( RemoveIt->second - Previous->first ).SquaredLength() < 1e-8 ) {
164 SegmentMap.erase(RemoveIt);
167 SegmentMap.erase(Previous);
175 GeneratedPaths.push_back(CurrPath);
181 Ogre::ManualObject* TempMan =
new Ogre::ManualObject(
"TempMan");
182 TempMan->begin(
"BaseWhiteNoLighting",Ogre::RenderOperation::OT_LINE_STRIP);
185 { TempMan->position( (*PointIt).GetOgreVector3() ); }
201 if( this->
Points.empty() ) {
207 { (*PointIt) += refVector; }
216 for(
Whole Index = First ; Index < Last ; ++Index )
223 return ( this->
Points.size() - 1 ) + ( this->
Closed ? 1 : 0 );
229 for(
Whole Index = 0 ; Index < this->
Points.size() ; ++Index )
230 { Length += ( this->
Points[ Index + 1 ] - this->
Points[ Index ] ).Length(); }
232 Length += ( this->
Points.back() - *(this->
Points.begin()) ).Length();
240 for(
Whole Index = 0 ; Index < PointIndex ; ++Index )
241 { Length += ( this->
Points[ Index + 1 ] - this->
Points[ Index ] ).Length(); }
243 Length += ( this->
Points.back() - *(this->
Points.begin()) ).Length();
251 { (*PointIt) = PointIt->
Reflect(Normal); }
257 std::reverse( this->
Points.begin(), this->
Points.end() );
277 this->
Points.push_back(ToAdd);
295 this->
Points.insert( this->
Points.begin() + Index, Point );
302 return this->
Points.at( MathTools::WrappedModulo(Index, this->
Points.size()) );
320 { (*PointIt) += Trans; }
331 return this->
Scale(Scaling,Scaling,Scaling);
338 (*PointIt).X *= ScaleX;
339 (*PointIt).Y *= ScaleY;
340 (*PointIt).Z *= ScaleZ;
347 return this->
Scale(Scaling.
X,Scaling.
Y,Scaling.
Z);
357 if( !this->
Closed && Index == this->
Points.size() - 1 && Index > 0 ) {
368 if( !this->
Closed && Index == 1 ) {
387 { RetShape.
AddPoint( PointIt->X, PointIt->Y ); }
Path ExtractSubPath(const Whole First, const Whole Last)
Extracts a part of the path as a new path.
Mesh * GenerateMesh(const String &Name, const String &Group) const
Outputs a mesh representing this path.
Shape & AddPoint(const Vector2 &Point)
Adds a point to the shape.
bool Boole
Generally acts a single bit, true or false.
Vector3 GetNormal() const
This returns the normal for this relative to the origin.
Real GetTotalLength() const
Gets the total length of all segments in this path.
Point3DContainer & GetPoints()
Gets all of the points in this path.
std::vector< Vector3 > Point3DContainer
Basic container type for the storage of 3D points.
Real X
Coordinate on the X vector.
Real Z
Coordinate on the Z vector.
static void BuildFromSegmentSoup(const LineSeg3DVec &Segments, PathContainer &GeneratedPaths)
Generates one or more paths from a series of segments.
This class is used to check and modify the properties of a graphics mesh.
int Integer
A datatype used to represent any integer close to.
Vector3 GetAvgDirection(const Whole Index) const
Gets the averaged direction from the specified point to both the next and previous points in the sequ...
Real GetLengthAtPoint(const Whole PointIndex) const
Gets the total length to the point in this path at an index.
Point3DContainer::iterator Point3DIterator
Iterator type for a Point3DContainer.
Shape ConvertToShape() const
Converts the path to a 2D shape, dropping the Z component.
LineSeg3DVec::const_iterator ConstLineSeg3DIterator
Const Iterator type for a LineSeg3DVec.
float Real
A Datatype used to represent a real floating point number.
Real SquaredDistance(const Vector3 &OtherVec) const
Gets the squared distance between this and another vector.
Point3DContainer Points
A container storing all of the points in this path.
Path & AddPoint(const Vector3 &ToAdd)
Adds a point to this path.
static MeshManager * GetSingletonPtr()
Fetches a pointer to the singleton.
Shape & Close()
Makes this a closed shape, connecting the last point to the first point.
Boole IsClosed() const
Gets whether or not the final point in this path connects to the first point.
Path & Reflect(const Vector3 &Normal)
Reflect all points in this path against a zero-origined plane with a given normal.
Boole Closed
Whether or not the end of this path connects to the beginning of this path.
Path & Reverse()
Reverses direction/ordering of the segments in this path.
Real Y
Coordinate on the Y vector.
std::vector< Path > PathContainer
Basic container type for the storage of Paths.
Path & Scale(const Real Scaling)
Applies the given scale to all the points in this path.
const Vector3 & GetPoint(const Integer Index) const
Safely gets a point in this path.
Vector3 GetDirectionBefore(const Whole Index) const
Gets the direction from a point to the previous point in the sequence.
Path & AppendPath(const Path &Other)
Appends all the points from another path to this path.
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.
Integer GetSegCount() const
Gets the number of segments in this path.
Path & Close()
Connects the last point in this path to the first point.
std::vector< LineSegment3D > LineSeg3DVec
Basic container type for the storage of 3D line segments.
Point3DContainer::const_iterator ConstPoint3DIterator
Const Iterator type for a Point3DContainer.
Path & Translate(const Vector3 &Trans)
Applies the given translation to all the points in this path.
A collection of interconnected 2D points used to express an arbitrary 2D shape.
A collection of interconnected 3D points used to express path through 3D space.
std::string String
A datatype used to a series of characters.
Path & InsertPoint(const Whole Index, const Real X, const Real Y, const Real Z)
Inserts a point to the path.
Path & AppendPathRel(const Path &Other)
Appends all the points from another path to this path with their positions relative to the position o...
Vector3 GetDirectionAfter(const Whole Index) const
Gets the direction of a point to the next point in the sequence.