Ogre Procedural  0.3.0 unstable
Procedural Geometry & Textures for Ogre3D
Classes | Public Member Functions | List of all members
Procedural::Shape Class Reference

#include <ProceduralShape.h>

Public Member Functions

 Shape ()
 Default constructor. More...
 
ShapeaddPoint (const Ogre::Vector2 &pt)
 Adds a point to the shape. More...
 
ShapeaddPoint (Ogre::Real x, Ogre::Real y)
 Adds a point to the shape. More...
 
ShapeinsertPoint (size_t index, Ogre::Real x, Ogre::Real y)
 Inserts a point to the shape. More...
 
ShapeinsertPoint (size_t index, const Ogre::Vector2 &pt)
 Inserts a point to the shape. More...
 
ShapeaddPointRel (const Ogre::Vector2 &pt)
 Adds a point to the shape, relative to the last point added. More...
 
ShapeaddPointRel (Ogre::Real x, Ogre::Real y)
 Adds a point to the shape, relative to the last point added. More...
 
ShapeappendShape (const Shape &other)
 Appends another shape at the end of this one. More...
 
ShapeappendShapeRel (const Shape &other)
 Appends another shape at the end of this one, relative to the last point of this shape. More...
 
Shape extractSubShape (unsigned int first, unsigned int last)
 Extracts a part of the shape as a new shape. More...
 
Shapereverse ()
 Reverses direction of the shape The outside is preserved. More...
 
Shapereset ()
 Clears the content of the shape. More...
 
Path convertToPath () const
 Converts the shape to a path, with Y=0. More...
 
Track convertToTrack (Track::AddressingMode addressingMode=Track::AM_RELATIVE_LINEIC) const
 Outputs a track, with Key=X and Value=Y. More...
 
std::vector< Ogre::Vector2getPoints () const
 Gets a copy of raw vector data of this shape. More...
 
std::vector< Ogre::Vector2 > & getPointsReference ()
 Gets raw vector data of this shape as a non-const reference. More...
 
const std::vector< Ogre::Vector2 > & getPointsReference () const
 Gets raw vector data of this shape as a non-const reference. More...
 
const Ogre::Vector2getPoint (int i) const
 Bounds-safe method to get a point : it will allow you to go beyond the bounds. More...
 
unsigned int getBoundedIndex (int i) const
 
const std::vector< Ogre::Vector2 >::size_type getPointCount () const
 Gets number of points in current point list. More...
 
Shapeclose ()
 Makes the shape a closed shape, ie it will automatically connect the last point to the first point. More...
 
ShapesetOutSide (Side side)
 Sets which side (left or right) is on the outside of the shape. More...
 
Side getOutSide () const
 Gets which side is out. More...
 
ShapeswitchSide ()
 Switches the inside and the outside. More...
 
size_t getSegCount () const
 Gets the number of segments in that shape. More...
 
bool isClosed () const
 Gets whether the shape is closed or not. More...
 
Ogre::Vector2 getDirectionAfter (unsigned int i) const
 Returns local direction after the current point. More...
 
Ogre::Vector2 getDirectionBefore (unsigned int i) const
 Returns local direction after the current point. More...
 
Ogre::Vector2 getAvgDirection (unsigned int i) const
 Gets the average between before direction and after direction. More...
 
Ogre::Vector2 getNormalAfter (unsigned int i) const
 Gets the shape normal just after that point. More...
 
Ogre::Vector2 getNormalBefore (unsigned int i) const
 Gets the shape normal just before that point. More...
 
Ogre::Vector2 getAvgNormal (unsigned int i) const
 Gets the "normal" of that point ie an average between before and after normals. More...
 
Ogre::MeshPtr realizeMesh (const std::string &name="") const
 Outputs a mesh representing the shape. More...
 
void _appendToManualObject (Ogre::ManualObject *manual) const
 Appends the shape vertices to a manual object being edited. More...
 
bool isPointInside (const Ogre::Vector2 &point) const
 Tells whether a point is inside a shape or not. More...
 
MultiShape booleanIntersect (const Shape &other) const
 Computes the intersection between this shape and another one. More...
 
MultiShape booleanUnion (const Shape &other) const
 Computes the union between this shape and another one. More...
 
MultiShape booleanDifference (const Shape &other) const
 Computes the difference between this shape and another one. More...
 
Side findRealOutSide () const
 On a closed shape, find if the outside is located on the right or on the left. More...
 
bool isOutsideRealOutside () const
 Determines whether the outside as defined by user equals "real" outside. More...
 
Shape mergeKeysWithTrack (const Track &track) const
 Creates a shape with the keys of this shape and extra keys coming from a track. More...
 
Shapetranslate (const Ogre::Vector2 &translation)
 Applies the given translation to all the points already defined. More...
 
Shapetranslate (Ogre::Real translationX, Ogre::Real translationY)
 Applies the given translation to all the points already defined. More...
 
Shaperotate (Ogre::Radian angle)
 Applies the given rotation to all the points already defined. More...
 
Shapescale (Ogre::Real amount)
 Applies the given scale to all the points already defined. More...
 
Shapescale (Ogre::Real scaleX, Ogre::Real scaleY)
 Applies the given scale to all the points already defined. More...
 
Shapescale (const Ogre::Vector2 &amount)
 Applies the given scale to all the points already defined. More...
 
Shapereflect (const Ogre::Vector2 &normal)
 Reflect all points in this shape against a zero-origined line with a given normal. More...
 
Shapemirror (bool flip=false)
 Create a symetric copy at the origin point. More...
 
Shapemirror (Ogre::Real x, Ogre::Real y, bool flip=false)
 Create a symetric copy at a given point. More...
 
ShapemirrorAroundPoint (Ogre::Vector2 point, bool flip=false)
 Create a symetric copy at a given point. More...
 
ShapemirrorAroundAxis (const Ogre::Vector2 &axis, bool flip=false)
 Create a symetric copy at a given axis. More...
 
Ogre::Real getTotalLength () const
 Returns the total lineic length of that shape. More...
 
Ogre::Vector2 getPosition (unsigned int i, Ogre::Real coord) const
 Gets a position on the shape with index of the point and a percentage of position on the segment. More...
 
Ogre::Vector2 getPosition (Ogre::Real coord) const
 Gets a position on the shape from lineic coordinate. More...
 
Ogre::Real findBoundingRadius () const
 Computes the radius of a bounding circle centered on the origin. More...
 
MultiShape thicken (Ogre::Real amount)
 Applies a "thickness" to a shape, ie a bit like the extruder, but in 2D. More...
 

Detailed Description

Describes a succession of interconnected 2D points. It can be closed or not, and there's always an outside and an inside

Constructor & Destructor Documentation

◆ Shape()

Procedural::Shape::Shape ( )

Default constructor.

Member Function Documentation

◆ _appendToManualObject()

void Procedural::Shape::_appendToManualObject ( Ogre::ManualObject manual) const

Appends the shape vertices to a manual object being edited.

◆ addPoint() [1/2]

Shape& Procedural::Shape::addPoint ( const Ogre::Vector2 pt)

◆ addPoint() [2/2]

Shape& Procedural::Shape::addPoint ( Ogre::Real  x,
Ogre::Real  y 
)

Adds a point to the shape.

◆ addPointRel() [1/2]

Shape& Procedural::Shape::addPointRel ( const Ogre::Vector2 pt)

Adds a point to the shape, relative to the last point added.

◆ addPointRel() [2/2]

Shape& Procedural::Shape::addPointRel ( Ogre::Real  x,
Ogre::Real  y 
)

Adds a point to the shape, relative to the last point added.

◆ appendShape()

Shape& Procedural::Shape::appendShape ( const Shape other)

Appends another shape at the end of this one.

◆ appendShapeRel()

Shape& Procedural::Shape::appendShapeRel ( const Shape other)

Appends another shape at the end of this one, relative to the last point of this shape.

◆ booleanDifference()

MultiShape Procedural::Shape::booleanDifference ( const Shape other) const

Computes the difference between this shape and another one.

Both shapes must be closed.

Start shapes
Difference of the two shapes
Parameters
otherThe shape against which the diffenrence is computed
Returns
The difference of two shapes, as a new shape
Exceptions
Ogre::InvalidStateExceptionCurrent shapes must be closed and has to contain at least 2 points!
Ogre::InvalidParametersExceptionOther shapes must be closed and has to contain at least 2 points!

◆ booleanIntersect()

MultiShape Procedural::Shape::booleanIntersect ( const Shape other) const

Computes the intersection between this shape and another one.

Both shapes must be closed.

Start shapes
Intersection of the two shapes
Parameters
otherThe shape against which the intersection is computed
Returns
The intersection of two shapes, as a new shape
Exceptions
Ogre::InvalidStateExceptionCurrent shapes must be closed and has to contain at least 2 points!
Ogre::InvalidParametersExceptionOther shapes must be closed and has to contain at least 2 points!

◆ booleanUnion()

MultiShape Procedural::Shape::booleanUnion ( const Shape other) const

Computes the union between this shape and another one.

Both shapes must be closed.

Start shapes
Union of the two shapes
Parameters
otherThe shape against which the union is computed
Returns
The union of two shapes, as a new shape
Exceptions
Ogre::InvalidStateExceptionCurrent shapes must be closed and has to contain at least 2 points!
Ogre::InvalidParametersExceptionOther shapes must be closed and has to contain at least 2 points!

◆ close()

Shape& Procedural::Shape::close ( )

Makes the shape a closed shape, ie it will automatically connect the last point to the first point.

Referenced by extractSubShape(), Procedural::RectangleShape::realizeShape(), Procedural::CircleShape::realizeShape(), Procedural::EllipseShape::realizeShape(), and Procedural::TriangleShape::realizeShape().

◆ convertToPath()

Path Procedural::Shape::convertToPath ( ) const

Converts the shape to a path, with Y=0.

◆ convertToTrack()

Track Procedural::Shape::convertToTrack ( Track::AddressingMode  addressingMode = Track::AM_RELATIVE_LINEIC) const

Outputs a track, with Key=X and Value=Y.

◆ extractSubShape()

Shape Procedural::Shape::extractSubShape ( unsigned int  first,
unsigned int  last 
)

Extracts a part of the shape as a new shape.

Parameters
firstfirst index to be in the new shape
lastlast index to be in the new shape

References addPoint(), close(), and setOutSide().

◆ findBoundingRadius()

Ogre::Real Procedural::Shape::findBoundingRadius ( ) const

Computes the radius of a bounding circle centered on the origin.

References Ogre::Math::Sqrt().

◆ findRealOutSide()

Side Procedural::Shape::findRealOutSide ( ) const

On a closed shape, find if the outside is located on the right or on the left.

If the outside can easily be guessed in your context, you'd rather use setOutside(), which doesn't need any computation.

◆ getAvgDirection()

Ogre::Vector2 Procedural::Shape::getAvgDirection ( unsigned int  i) const

Gets the average between before direction and after direction.

References Vector< 2, Real >::normalisedCopy().

◆ getAvgNormal()

Ogre::Vector2 Procedural::Shape::getAvgNormal ( unsigned int  i) const

Gets the "normal" of that point ie an average between before and after normals.

References Procedural::SIDE_RIGHT.

◆ getBoundedIndex()

unsigned int Procedural::Shape::getBoundedIndex ( int  i) const

◆ getDirectionAfter()

Ogre::Vector2 Procedural::Shape::getDirectionAfter ( unsigned int  i) const

Returns local direction after the current point.

References Vector< 2, Real >::normalisedCopy().

◆ getDirectionBefore()

Ogre::Vector2 Procedural::Shape::getDirectionBefore ( unsigned int  i) const

Returns local direction after the current point.

References Vector< 2, Real >::normalisedCopy().

◆ getNormalAfter()

Ogre::Vector2 Procedural::Shape::getNormalAfter ( unsigned int  i) const

Gets the shape normal just after that point.

References Procedural::SIDE_RIGHT.

◆ getNormalBefore()

Ogre::Vector2 Procedural::Shape::getNormalBefore ( unsigned int  i) const

Gets the shape normal just before that point.

References Procedural::SIDE_RIGHT.

◆ getOutSide()

Side Procedural::Shape::getOutSide ( ) const

Gets which side is out.

◆ getPoint()

const Ogre::Vector2& Procedural::Shape::getPoint ( int  i) const

Bounds-safe method to get a point : it will allow you to go beyond the bounds.

◆ getPointCount()

const std::vector<Ogre::Vector2>::size_type Procedural::Shape::getPointCount ( ) const

Gets number of points in current point list.

◆ getPoints()

std::vector<Ogre::Vector2> Procedural::Shape::getPoints ( ) const

Gets a copy of raw vector data of this shape.

◆ getPointsReference() [1/2]

std::vector<Ogre::Vector2>& Procedural::Shape::getPointsReference ( )

Gets raw vector data of this shape as a non-const reference.

◆ getPointsReference() [2/2]

const std::vector<Ogre::Vector2>& Procedural::Shape::getPointsReference ( ) const

Gets raw vector data of this shape as a non-const reference.

◆ getPosition() [1/2]

Ogre::Vector2 Procedural::Shape::getPosition ( Ogre::Real  coord) const

Gets a position on the shape from lineic coordinate.

Parameters
coordlineic coordinate
Exceptions
Ogre::InvalidStateExceptionThe shape must at least contain 2 points

References Ogre::Exception::ERR_INVALID_STATE, getPosition(), and OGRE_EXCEPT.

◆ getPosition() [2/2]

Ogre::Vector2 Procedural::Shape::getPosition ( unsigned int  i,
Ogre::Real  coord 
) const

Gets a position on the shape with index of the point and a percentage of position on the segment.

Parameters
iindex of the segment
coorda number between 0 and 1 meaning the percentage of position on the segment
Exceptions
Ogre::InvalidParametersExceptioni is out of bounds
Ogre::InvalidParametersExceptioncoord must be comprised between 0 and 1

References Ogre::Exception::ERR_INVALIDPARAMS, and OGRE_EXCEPT.

◆ getSegCount()

size_t Procedural::Shape::getSegCount ( ) const

Gets the number of segments in that shape.

◆ getTotalLength()

Ogre::Real Procedural::Shape::getTotalLength ( ) const

Returns the total lineic length of that shape.

◆ insertPoint() [1/2]

Shape& Procedural::Shape::insertPoint ( size_t  index,
const Ogre::Vector2 pt 
)

Inserts a point to the shape.

Parameters
indexthe index before the inserted point
ptnew point's position

◆ insertPoint() [2/2]

Shape& Procedural::Shape::insertPoint ( size_t  index,
Ogre::Real  x,
Ogre::Real  y 
)

Inserts a point to the shape.

Parameters
indexthe index before the inserted point
xnew point's x coordinate
ynew point's y coordinate

◆ isClosed()

bool Procedural::Shape::isClosed ( ) const

Gets whether the shape is closed or not.

◆ isOutsideRealOutside()

bool Procedural::Shape::isOutsideRealOutside ( ) const

Determines whether the outside as defined by user equals "real" outside.

◆ isPointInside()

bool Procedural::Shape::isPointInside ( const Ogre::Vector2 point) const

Tells whether a point is inside a shape or not.

Parameters
pointThe point to check
Returns
true if the point is inside this shape, false otherwise

◆ mergeKeysWithTrack()

Shape Procedural::Shape::mergeKeysWithTrack ( const Track track) const

Creates a shape with the keys of this shape and extra keys coming from a track.

Parameters
trackthe track to merge keys with
Returns
a new Shape coming from the merge between original shape and the track

◆ mirror() [1/2]

Shape& Procedural::Shape::mirror ( bool  flip = false)

Create a symetric copy at the origin point.

Parameters
fliptrue if function should start mirroring with the last point in list (default false)

◆ mirror() [2/2]

Shape& Procedural::Shape::mirror ( Ogre::Real  x,
Ogre::Real  y,
bool  flip = false 
)

Create a symetric copy at a given point.

Parameters
xx coordinate of point where to mirror
yy coordinate of point where to mirror
fliptrue if function should start mirroring with the last point in list (default false)

◆ mirrorAroundAxis()

Shape& Procedural::Shape::mirrorAroundAxis ( const Ogre::Vector2 axis,
bool  flip = false 
)

Create a symetric copy at a given axis.

Parameters
axisAxis where to mirror
fliptrue if function should start mirroring with the first point in list (default false)

References Vector< 2, Real >::normalisedCopy(), and Vector< 2, Real >::reflect().

◆ mirrorAroundPoint()

Shape& Procedural::Shape::mirrorAroundPoint ( Ogre::Vector2  point,
bool  flip = false 
)

Create a symetric copy at a given point.

Parameters
pointPoint where to mirror
fliptrue if function should start mirroring with the last point in list (default false)

◆ realizeMesh()

Ogre::MeshPtr Procedural::Shape::realizeMesh ( const std::string &  name = "") const

Outputs a mesh representing the shape.

Mostly for debugging purposes

◆ reflect()

Shape& Procedural::Shape::reflect ( const Ogre::Vector2 normal)

Reflect all points in this shape against a zero-origined line with a given normal.

Parameters
normalthe normal

References reflect().

Referenced by reflect().

◆ reset()

Shape& Procedural::Shape::reset ( )

Clears the content of the shape.

◆ reverse()

Shape& Procedural::Shape::reverse ( )

Reverses direction of the shape The outside is preserved.

◆ rotate()

Shape& Procedural::Shape::rotate ( Ogre::Radian  angle)

Applies the given rotation to all the points already defined.

Has strictly no effect on the points defined after that

Parameters
angleangle of rotation

References Ogre::Math::Cos(), Ogre::Math::Sin(), and Ogre::Radian::valueRadians().

◆ scale() [1/3]

Shape& Procedural::Shape::scale ( const Ogre::Vector2 amount)

Applies the given scale to all the points already defined.

Has strictly no effect on the points defined after that

Parameters
amountof scale

◆ scale() [2/3]

Shape& Procedural::Shape::scale ( Ogre::Real  amount)

Applies the given scale to all the points already defined.

Has strictly no effect on the points defined after that

Parameters
amountamount of scale

◆ scale() [3/3]

Shape& Procedural::Shape::scale ( Ogre::Real  scaleX,
Ogre::Real  scaleY 
)

Applies the given scale to all the points already defined.

Has strictly no effect on the points defined after that

Parameters
scaleXamount of scale in the X direction
scaleYamount of scale in the Y direction

◆ setOutSide()

Shape& Procedural::Shape::setOutSide ( Side  side)

Sets which side (left or right) is on the outside of the shape.

It is used for such things as normal generation Default is right, which corresponds to placing points anti-clockwise.

Referenced by extractSubShape().

◆ switchSide()

Shape& Procedural::Shape::switchSide ( )

Switches the inside and the outside.

References Procedural::SIDE_LEFT, and Procedural::SIDE_RIGHT.

◆ thicken()

MultiShape Procedural::Shape::thicken ( Ogre::Real  amount)

Applies a "thickness" to a shape, ie a bit like the extruder, but in 2D.

Start shape (before thicken)
Result (after thicken)

◆ translate() [1/2]

Shape& Procedural::Shape::translate ( const Ogre::Vector2 translation)

Applies the given translation to all the points already defined.

Has strictly no effect on the points defined after that

Parameters
translationthe translation vector

Referenced by Procedural::TriangleShape::realizeShape().

◆ translate() [2/2]

Shape& Procedural::Shape::translate ( Ogre::Real  translationX,
Ogre::Real  translationY 
)

Applies the given translation to all the points already defined.

Has strictly no effect on the points defined after that

Parameters
translationXX component of the translation vector
translationYY component of the translation vector

References translate().


The documentation for this class was generated from the following file: