67 #ifndef _graphicsproceduralmultishape_cpp
68 #define _graphicsproceduralmultishape_cpp
70 #include "Graphics/Procedural/multishape.h"
71 #include "Graphics/Procedural/shape.h"
73 #include "Graphics/meshmanager.h"
75 #include "MathTools/mathtools.h"
89 { this->
Shapes.push_back(ToAdd); }
92 { this->
Shapes.insert(this->
Shapes.end(),ToAdd.begin(),ToAdd.end()); }
102 Ogre::ManualObject* TempMan =
new Ogre::ManualObject(
"TempMan");
106 TempMan->begin(
"BaseWhiteNoLighting",Ogre::RenderOperation::OT_LINE_STRIP);
107 (*It)._AppendToManualObject(TempMan);
118 typedef std::multimap<Vector2,Vector2,Vector2LengthCompare> Vec2MultiMap;
119 typedef std::pair<Vector2,Vector2> Vec2Pair;
124 SegMap.insert( Vec2Pair(SegIt->PointA,SegIt->PointB) );
125 SegMap.insert( Vec2Pair(SegIt->PointB,SegIt->PointA) );
127 while( !SegMap.empty() )
129 Vector2 headFirst = SegMap.begin()->first;
130 Vector2 headSecond = SegMap.begin()->second;
135 Vec2MultiMap::iterator firstSeg = SegMap.begin();
136 std::pair<Vec2MultiMap::iterator,Vec2MultiMap::iterator> correspondants2 = SegMap.equal_range(headSecond);
138 for( Vec2MultiMap::iterator Vec2It = correspondants2.first ; Vec2It != correspondants2.second ; )
140 Vec2MultiMap::iterator RemoveIt = ++Vec2It;
141 if( ( RemoveIt->second - firstSeg->first ).SquaredLength() < 1e-8 )
142 SegMap.erase(RemoveIt);
145 SegMap.erase(firstSeg);
146 Boole FoundSomething =
true;
147 while( !SegMap.empty() && FoundSomething )
149 FoundSomething =
false;
150 Vec2MultiMap::iterator next = SegMap.find(headSecond);
151 if( next != SegMap.end() ) {
152 FoundSomething =
true;
153 headSecond = next->second;
155 std::pair<Vec2MultiMap::iterator, Vec2MultiMap::iterator> correspondants = SegMap.equal_range(headSecond);
156 for( Vec2MultiMap::iterator it = correspondants.first ; it != correspondants.second ; )
158 Vec2MultiMap::iterator RemoveIt = ++it;
159 if( ( RemoveIt->second - next->first ).SquaredLength() < 1e-8)
160 SegMap.erase(RemoveIt);
164 Vec2MultiMap::iterator previous = SegMap.find(headFirst);
165 if( previous != SegMap.end() ) {
166 FoundSomething =
true;
168 headFirst = previous->second;
169 std::pair<Vec2MultiMap::iterator,Vec2MultiMap::iterator> correspondants = SegMap.equal_range(headFirst);
170 for( Vec2MultiMap::iterator it = correspondants.first ; it != correspondants.second ; )
172 Vec2MultiMap::iterator RemoveIt = ++it;
173 if( ( RemoveIt->second - previous->first ).SquaredLength() < 1e-8 )
174 SegMap.erase(RemoveIt);
176 SegMap.erase(previous);
190 for(
Whole Index = 0 ; Index < this->
Shapes.size() ; Index++ )
193 Ret.insert( Ret.end(), Points.begin(), Points.end() );
202 Integer ClosestSegmentIndex = -1;
203 Real ClosestSegmentDistance = std::numeric_limits<Real>::max();
204 Vector2 ClosestSegmentIntersection;
205 const Shape* ClosestSegmentShape = 0;
207 for(
Whole ShapeIndex = 0 ; ShapeIndex < this->
Shapes.size() ; ShapeIndex++ )
210 for(
Whole SegmentIndex = 0 ; SegmentIndex < CurrShape.
GetSegCount() ; SegmentIndex++ )
214 if( A.
Y != B.
Y && ( A.
Y - Point.
Y ) * ( B.
Y - Point.
Y ) <= 0.0 ) {
215 Vector2 Intersect( A.
X + ( Point.
Y - A.
Y ) * ( B.
X - A.
X ) / ( B.
Y - A.
Y ), Point.
Y );
216 Real Dist = MathTools::Abs( Point.
X - Intersect.
X );
217 if( Dist < ClosestSegmentDistance ) {
218 ClosestSegmentIndex = SegmentIndex;
219 ClosestSegmentDistance = Dist;
220 ClosestSegmentIntersection = Intersect;
221 ClosestSegmentShape = &CurrShape;
226 if( ClosestSegmentIndex != -1 ) {
228 if( ClosestSegmentIntersection.
SquaredDistance( ClosestSegmentShape->
GetPoint(ClosestSegmentIndex) ) < 1e-8 ) {
229 EdgePoint = ClosestSegmentIndex;
230 }
else if( ClosestSegmentIntersection.
SquaredDistance( ClosestSegmentShape->
GetPoint(ClosestSegmentIndex + 1) ) < 1e-8) {
231 EdgePoint = ClosestSegmentIndex + 1;
233 if( EdgePoint > -1 ) {
236 if( Alpha1 < Alpha2 ) {
237 ClosestSegmentIndex = EdgePoint;
239 ClosestSegmentIndex = EdgePoint - 1;
242 return ( ClosestSegmentShape->
GetNormalAfter(ClosestSegmentIndex).
X * ( Point.
X - ClosestSegmentIntersection.
X ) < 0 );
251 Real X = std::numeric_limits<Real>::min();
254 for(
Whole SIndex = 0 ; SIndex < this->
Shapes.size() ; SIndex++ )
258 for(
Whole PIndex = 0 ; PIndex < Points.size() ; PIndex++ )
260 if( X < Points[PIndex].X ) {
261 X = Points[PIndex].X;
270 if( Alpha1 < Alpha2 ) {
275 return ( Side == this->
Shapes[ShapeIndex].GetOutSide() );
289 if( !It->IsClosed() )
300 this->
Shapes.push_back(ToAdd);
307 { this->
Shapes.push_back(*it); }
312 {
return this->
Shapes[Index]; }
315 {
return this->
Shapes[Index]; }
318 {
return this->
Shapes.size(); }
Boole IsOutsideRealOutside() const
Gets whether the currently set OutSide is the real Outside.
static Vector2 Unit_Y()
Gets a vector representing the Y unit of a Vector2.
ShapeContainer::iterator ShapeIterator
Iterator type for Shape instances being stored in this class.
Vector2 GetDirectionBefore(const Whole Index) const
Gets the direction from a point to the previous point in the sequence.
Shape & AddPoint(const Vector2 &Point)
Adds a point to the shape.
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.
MultiShape()
Blank constructor.
Vector2 GetDirectionAfter(const Whole Index) const
Gets the direction of a point to the next point in the sequence.
ShapeContainer Shapes
Container storing all of the Shapes that form this MultiShape.
Point2DContainer & GetPointsReference()
Gets raw vector data of this shape as a non-const reference.
LineSegmentContainer::const_iterator ConstLineSegmentIterator
Const Iterator type for LineSegment2D instances being stored in this class.
MultiShape & AddShape(const Shape &ToAdd)
Adds a shape to this MultiShape.
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.
MultiShape & Close()
Closes each shape in this MultiShape.
Real AngleTo(const Vector2 &Other) const
Gets an oriented angle between this Vector2 and another Vector2.
Boole IsClosed() const
Gets whether or not every Shape in this MultiShape is closed.
float Real
A Datatype used to represent a real floating point number.
Boole IsPointInside(const Vector2 &Point) const
Gets whether or not a point is inside this MultiShape.
ShapeSide
An enum used to express which side to work with in Shape operations.
std::vector< Vector2 > Point2DContainer
Basic container type for the storage of 2D points.
static MeshManager * GetSingletonPtr()
Fetches a pointer to the singleton.
Real Y
Coordinate on the Y vector.
Shape & Close()
Makes this a closed shape, connecting the last point to the first point.
Real X
Coordinate on the X vector.
This is used to represent a point on a 2 dimentional area, such as a screen.
Whole GetSegCount() const
Gets the number of segments in this shape.
Point2DContainer GetPoints() const
Gets a container of all the points in this MultiShape.
void BuildFromSegmentSoup(const LineSegmentContainer &Segments)
Creates this MultiShape from a listing of segments.
Real SquaredDistance(const Vector2 &Other) const
Gets the squared distance between this and another vector.
Mesh * GenerateMesh(const String &Name, const String &Group)
Outputs a mesh representing this MultiShape.
Use the left side of the shape.
void RemoveAllShapes()
Removes all shapes from this MultiShape.
Whole GetNumShapes() const
Gets the number of shapes in this MultiShape.
std::vector< Shape > ShapeContainer
Basic container type for Shape storage in this class.
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.
~MultiShape()
Class destructor.
ShapeContainer::const_iterator ConstShapeIterator
Const Iterator type for Shape instances being stored in this class.
std::vector< LineSegment2D > LineSegmentContainer
Basic container type for LineSegment2D storage in this class.
MultiShape & AddMultiShape(const MultiShape &Other)
Append every shape of another MultiShape to this MultiShape.
A collection of interconnected 2D points used to express an arbitrary 2D shape.
Vector2 GetNormalAfter(const Whole Index) const
Gets the normal of the segment after the specified point.
Use the right side of the shape.
Shape & GetShape(const Whole Index)
Gets a shape by index.
A grouping of individual 2D shapes used to express more elaborate shapes.
std::string String
A datatype used to a series of characters.
Shape & InsertPoint(const Whole Index, const Real X, const Real Y)
Inserts a point to the shape.