CUGL 2.1
Cornell University Game Library
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
cugl::physics2::PolygonObstacle Class Reference

#include <CUPolygonObstacle.h>

Inheritance diagram for cugl::physics2::PolygonObstacle:
cugl::physics2::SimpleObstacle cugl::physics2::Obstacle

Public Member Functions

 PolygonObstacle (void)
 
virtual ~PolygonObstacle ()
 
virtual bool init (const Poly2 &poly)
 
virtual bool init (const Poly2 &poly, const Vec2 origin)
 
virtual bool initWithAnchor (const Poly2 &poly, const Vec2 anchor)
 
const Size getSize () const
 
void setSize (const Size value)
 
void setSize (float width, float height)
 
float getWidth () const
 
void setWidth (float value)
 
float getHeight () const
 
void setHeight (float value)
 
const Vec2 getAnchor () const
 
void setAnchor (const Vec2 value)
 
void setAnchor (float x, float y)
 
const Poly2getPolygon () const
 
void setPolygon (const Poly2 &value)
 
virtual void createFixtures () override
 
virtual void releaseFixtures () override
 
- Public Member Functions inherited from cugl::physics2::SimpleObstacle
 SimpleObstacle ()
 
virtual ~SimpleObstacle ()
 
virtual b2BodyType getBodyType () const override
 
virtual void setBodyType (b2BodyType value) override
 
virtual Vec2 getPosition () const override
 
virtual void setPosition (const Vec2 value) override
 
virtual void setPosition (float x, float y) override
 
virtual float getX () const override
 
virtual void setX (float value) override
 
virtual float getY () const override
 
virtual void setY (float value) override
 
virtual float getAngle () const override
 
virtual void setAngle (float value) override
 
virtual Vec2 getLinearVelocity () const override
 
virtual void setLinearVelocity (const Vec2 value) override
 
virtual void setLinearVelocity (float x, float y) override
 
virtual float getVX () const override
 
virtual void setVX (float value) override
 
virtual float getVY () const override
 
virtual void setVY (float value) override
 
virtual float getAngularVelocity () const override
 
virtual void setAngularVelocity (float value) override
 
virtual bool isEnabled () const override
 
virtual void setEnabled (bool value) override
 
virtual bool isAwake () const override
 
virtual void setAwake (bool value) override
 
virtual bool isSleepingAllowed () const override
 
virtual void setSleepingAllowed (bool value) override
 
virtual bool isBullet () const override
 
virtual void setBullet (bool value) override
 
virtual bool isFixedRotation () const override
 
virtual void setFixedRotation (bool value) override
 
virtual float getGravityScale () const override
 
virtual void setGravityScale (float value) override
 
virtual float getLinearDamping () const override
 
virtual void setLinearDamping (float value) override
 
virtual float getAngularDamping () const override
 
virtual void setAngularDamping (float value) override
 
virtual void setDensity (float value) override
 
virtual void setFriction (float value) override
 
virtual void setRestitution (float value) override
 
virtual void setSensor (bool value) override
 
virtual void setFilterData (b2Filter value) override
 
virtual Vec2 getCentroid () const override
 
virtual void setCentroid (const Vec2 value) override
 
virtual void setCentroid (float x, float y) override
 
virtual float getInertia () const override
 
virtual void setInertia (float value) override
 
virtual float getMass () const override
 
virtual void setMass (float value) override
 
virtual void resetMass () override
 
virtual b2Body * getBody () override
 
virtual bool activatePhysics (b2World &world) override
 
virtual void deactivatePhysics (b2World &world) override
 
virtual void update (float delta) override
 
int getPositionSnap ()
 
void setPositionSnap (unsigned int snap)
 
int getAngleSnap ()
 
void setAngleSnap (unsigned int snap)
 
- Public Member Functions inherited from cugl::physics2::Obstacle
 Obstacle (void)
 
virtual ~Obstacle ()
 
virtual bool init ()
 
virtual bool init (const Vec2 vec)
 
void setBodyState (const b2Body &body)
 
float getDensity () const
 
float getFriction () const
 
float getRestitution () const
 
bool isSensor () const
 
b2Filter getFilterData () const
 
bool isRemoved () const
 
void markRemoved (bool value)
 
bool isDirty () const
 
void markDirty (bool value)
 
const std::function< void(Obstacle *obstacle)> & getListener () const
 
void setListener (const std::function< void(Obstacle *obstacle)> &listener)
 
std::string getName () const
 
void setName (std::string value)
 
std::string toString () const
 
Color4 getDebugColor () const
 
virtual void setDebugColor (Color4 color)
 
scene2::SceneNodegetDebugScene () const
 
scene2::WireNodegetDebugNode () const
 
virtual void setDebugScene (const std::shared_ptr< scene2::SceneNode > &node)
 
bool hasDebug ()
 

Static Public Member Functions

static std::shared_ptr< PolygonObstaclealloc (const Poly2 &poly)
 
static std::shared_ptr< PolygonObstaclealloc (const Poly2 &poly, const Vec2 origin)
 
static std::shared_ptr< PolygonObstacleallocWithAnchor (const Poly2 &poly, const Vec2 anchor)
 

Protected Member Functions

void resize (const Size size)
 
virtual void resetDebug () override
 
void resetShapes ()
 
- Protected Member Functions inherited from cugl::physics2::SimpleObstacle
virtual void updateDebug () override
 

Protected Attributes

Poly2 _polygon
 
b2PolygonShape * _shapes
 
b2Fixture ** _geoms
 
Vec2 _anchor
 
int _fixCount
 
- Protected Attributes inherited from cugl::physics2::SimpleObstacle
b2Body * _body
 
int _posSnap
 
unsigned long _posFact
 
int _angSnap
 
unsigned long _angFact
 
- Protected Attributes inherited from cugl::physics2::Obstacle
b2BodyDef _bodyinfo
 
b2FixtureDef _fixture
 
b2MassData _massdata
 
bool _masseffect
 
std::shared_ptr< scene2::SceneNode_scene
 
std::shared_ptr< scene2::WireNode_debug
 
Color4 _dcolor
 
std::string _tag
 
std::function< void(Obstacle *obstacle)> _listener
 

Detailed Description

Arbitrary polygonal-shaped model to support collisions.

The polygon can be any one that is representable by a Poly2 object. That means that it does not need to be convex, but it cannot have holes or self intersections.

Constructor & Destructor Documentation

◆ PolygonObstacle()

cugl::physics2::PolygonObstacle::PolygonObstacle ( void  )
inline

Creates an empty polygon at the origin.

NEVER USE A CONSTRUCTOR WITH NEW. If you want to allocate an object on the heap, use one of the static constructors instead.

◆ ~PolygonObstacle()

virtual cugl::physics2::PolygonObstacle::~PolygonObstacle ( )
virtual

Deletes this physics object and all of its resources.

A non-default destructor is necessary since we must release all the fixture pointers for the polygons.

Member Function Documentation

◆ alloc() [1/2]

static std::shared_ptr<PolygonObstacle> cugl::physics2::PolygonObstacle::alloc ( const Poly2 poly)
inlinestatic

Returns a (not necessarily convex) polygon

The given polygon defines an implicit coordinate space, with (0,0) at the origin. This origin will be the position of the body, and hence its rotation center.

Parameters
polyThe polygon vertices
Returns
a (not necessarily convex) polygon

◆ alloc() [2/2]

static std::shared_ptr<PolygonObstacle> cugl::physics2::PolygonObstacle::alloc ( const Poly2 poly,
const Vec2  origin 
)
inlinestatic

Returns a (not necessarily convex) polygon

The given polygon defines an implicit coordinate space. The body (and hence the rotational center) will be placed at the given origin position.

Parameters
polyThe polygon vertices
originThe rotational center with respect to the vertices
Returns
a (not necessarily convex) polygon

◆ allocWithAnchor()

static std::shared_ptr<PolygonObstacle> cugl::physics2::PolygonObstacle::allocWithAnchor ( const Poly2 poly,
const Vec2  anchor 
)
inlinestatic

Returns a (not necessarily convex) polygon

The anchor point (the rotational center) of the polygon is specified as a ratio of the bounding box. An anchor point of (0,0) is the bottom left of the bounding box. An anchor point of (1,1) is the top right of the bounding box. The anchor point does not need to be contained with the bounding box.

Parameters
polyThe polygon vertices
anchorThe rotational center of the polygon
Returns
a (not necessarily convex) polygon

◆ createFixtures()

virtual void cugl::physics2::PolygonObstacle::createFixtures ( )
overridevirtual

Create new fixtures for this body, defining the shape

This is the primary method to override for custom physics objects

Reimplemented from cugl::physics2::SimpleObstacle.

◆ getAnchor()

const Vec2 cugl::physics2::PolygonObstacle::getAnchor ( ) const
inline

Returns the rotational center of this polygon

The anchor point of the polygon is specified as ratio of the bounding box. An anchor point of (0,0) is the bottom left of the bounding box. An anchor point of (1,1) is the top right of the bounding box. The anchorpoint does not need to be contained with the bounding box.

Returns
the rotational center of this polygon

◆ getHeight()

float cugl::physics2::PolygonObstacle::getHeight ( ) const
inline

Returns the bounding box height

Returns
the bounding box height

◆ getPolygon()

const Poly2& cugl::physics2::PolygonObstacle::getPolygon ( ) const
inline

Returns the polygon defining this object

Returns
the polygon defining this object

◆ getSize()

const Size cugl::physics2::PolygonObstacle::getSize ( ) const
inline

Returns the dimensions of the bounding box

Returns
the dimensions of the bounding box

◆ getWidth()

float cugl::physics2::PolygonObstacle::getWidth ( ) const
inline

Returns the bounding box width

Returns
the bounding box width

◆ init() [1/2]

virtual bool cugl::physics2::PolygonObstacle::init ( const Poly2 poly)
inlinevirtual

Initializes a (not necessarily convex) polygon

The given polygon defines an implicit coordinate space, with (0,0) at the origin. This origin will be the position of the body, and hence its rotation center.

Parameters
polyThe polygon vertices
Returns
true if the obstacle is initialized properly, false otherwise.

◆ init() [2/2]

virtual bool cugl::physics2::PolygonObstacle::init ( const Poly2 poly,
const Vec2  origin 
)
virtual

Initializes a (not necessarily convex) polygon

The given polygon defines an implicit coordinate space. The body (and hence the rotational center) will be placed at the given origin position.

Parameters
polyThe polygon vertices
originThe rotational center with respect to the vertices
Returns
true if the obstacle is initialized properly, false otherwise.

◆ initWithAnchor()

virtual bool cugl::physics2::PolygonObstacle::initWithAnchor ( const Poly2 poly,
const Vec2  anchor 
)
virtual

Initializes a (not necessarily convex) polygon

The anchor point (the rotational center) of the polygon is specified as a ratio of the bounding box. An anchor point of (0,0) is the bottom left of the bounding box. An anchor point of (1,1) is the top right of the bounding box. The anchor point does not need to be contained with the bounding box.

Parameters
polyThe polygon vertices
anchorThe rotational center of the polygon
Returns
true if the obstacle is initialized properly, false otherwise.

◆ releaseFixtures()

virtual void cugl::physics2::PolygonObstacle::releaseFixtures ( )
overridevirtual

Release the fixtures for this body, reseting the shape

This is the primary method to override for custom physics objects

Reimplemented from cugl::physics2::SimpleObstacle.

◆ resetDebug()

virtual void cugl::physics2::PolygonObstacle::resetDebug ( )
overrideprotectedvirtual

Creates the outline of the physics fixtures in the debug node

The debug node is use to outline the fixtures attached to this object. This is very useful when the fixtures have a very different shape than the texture (e.g. a circular shape attached to a square texture).

Reimplemented from cugl::physics2::Obstacle.

◆ resetShapes()

void cugl::physics2::PolygonObstacle::resetShapes ( )
protected

Recreates the shape objects attached to this polygon.

This must be called whenever the polygon is resized.

◆ resize()

void cugl::physics2::PolygonObstacle::resize ( const Size  size)
protected

Resets the polygon vertices in the shape to match the dimension.

This is an internal method and it does not mark the physics object as dirty.

Parameters
sizeThe new dimension (width and height)

◆ setAnchor() [1/2]

void cugl::physics2::PolygonObstacle::setAnchor ( const Vec2  value)
inline

Sets the rotational center of this polygon

The anchor point of the polygon is specified as ratio of the bounding box. An anchor point of (0,0) is the bottom left of the bounding box. An anchor point of (1,1) is the top right of the bounding box. The anchorpoint does not need to be contained with the bounding box.

Parameters
valuethe rotational center of this polygon

◆ setAnchor() [2/2]

void cugl::physics2::PolygonObstacle::setAnchor ( float  x,
float  y 
)

Sets the rotational center of this polygon

The anchor point of the polygon is specified as ratio of the bounding box. An anchor point of (0,0) is the bottom left of the bounding box. An anchor point of (1,1) is the top right of the bounding box. The anchorpoint does not need to be contained with the bounding box.

Parameters
xthe x-coordinate of the rotational center
ythe y-coordinate of the rotational center

◆ setHeight()

void cugl::physics2::PolygonObstacle::setHeight ( float  value)
inline

Sets the bounding box height

The vertices are rescaled according to their vertex origin. This change cannot happen immediately. It must wait until the next update is called. The current anchor point will be preserved.

Parameters
valuethe bounding box height

◆ setPolygon()

void cugl::physics2::PolygonObstacle::setPolygon ( const Poly2 value)

Sets the polygon defining this object

This change cannot happen immediately. It must wait until the next update is called. The current anchor point will be preserved.

Parameters
valuethe polygon defining this object

◆ setSize() [1/2]

void cugl::physics2::PolygonObstacle::setSize ( const Size  value)
inline

Sets the dimensions of the bounding box

The vertices are rescaled according to their vertex origin. This change cannot happen immediately. It must wait until the next update is called. The current anchor point will be preserved.

Parameters
valuethe dimensions of the bounding box

◆ setSize() [2/2]

void cugl::physics2::PolygonObstacle::setSize ( float  width,
float  height 
)
inline

Sets the dimensions of this box

Parameters
widthThe width of this box
heightThe height of this box

◆ setWidth()

void cugl::physics2::PolygonObstacle::setWidth ( float  value)
inline

Sets the bounding box width

The vertices are rescaled according to their vertex origin. This change cannot happen immediately. It must wait until the next update is called. The current anchor point will be preserved.

Parameters
valuethe bounding box width

Member Data Documentation

◆ _anchor

Vec2 cugl::physics2::PolygonObstacle::_anchor
protected

Anchor point to synchronize with the scene graph

◆ _fixCount

int cugl::physics2::PolygonObstacle::_fixCount
protected

In case the number of polygons changes

◆ _geoms

b2Fixture** cugl::physics2::PolygonObstacle::_geoms
protected

A cache value for the fixtures (for resizing)

◆ _polygon

Poly2 cugl::physics2::PolygonObstacle::_polygon
protected

The polygon vertices (for resizing)

◆ _shapes

b2PolygonShape* cugl::physics2::PolygonObstacle::_shapes
protected

Shape information for this physics object


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