CUGL 2.5
Cornell University Game Library
|
#include <CUPolygonObstacle.h>
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 Poly2 & | getPolygon () const |
void | setPolygon (const Poly2 &value) |
virtual void | createFixtures () override |
virtual void | releaseFixtures () override |
virtual bool | init () |
virtual bool | init (const Vec2 vec) |
Public Member Functions inherited from cugl::physics2::Obstacle | |
Obstacle (void) | |
virtual | ~Obstacle () |
virtual bool | init () |
virtual bool | init (const Vec2 vec) |
virtual b2BodyType | getBodyType () const |
virtual void | setBodyType (b2BodyType value) |
virtual Vec2 | getPosition () const |
virtual void | setPosition (const Vec2 value) |
virtual void | setPosition (float x, float y) |
virtual float | getX () const |
virtual void | setX (float value) |
virtual float | getY () const |
virtual void | setY (float value) |
virtual float | getAngle () const |
virtual void | setAngle (float value) |
virtual Vec2 | getLinearVelocity () const |
virtual void | setLinearVelocity (const Vec2 value) |
virtual void | setLinearVelocity (float x, float y) |
virtual float | getVX () const |
virtual void | setVX (float value) |
virtual float | getVY () const |
virtual void | setVY (float value) |
virtual float | getAngularVelocity () const |
virtual void | setAngularVelocity (float value) |
virtual bool | isEnabled () const |
virtual void | setEnabled (bool value) |
virtual bool | isAwake () const |
virtual void | setAwake (bool value) |
virtual bool | isSleepingAllowed () const |
virtual void | setSleepingAllowed (bool value) |
virtual bool | isBullet () const |
virtual void | setBullet (bool value) |
virtual bool | isFixedRotation () const |
virtual void | setFixedRotation (bool value) |
virtual float | getGravityScale () const |
virtual void | setGravityScale (float value) |
virtual float | getLinearDamping () const |
virtual void | setLinearDamping (float value) |
virtual float | getAngularDamping () const |
virtual void | setAngularDamping (float value) |
void | setBodyState (const b2Body &body) |
float | getDensity () const |
virtual void | setDensity (float value) |
float | getFriction () const |
virtual void | setFriction (float value) |
float | getRestitution () const |
virtual void | setRestitution (float value) |
bool | isSensor () const |
virtual void | setSensor (bool value) |
b2Filter | getFilterData () const |
virtual void | setFilterData (b2Filter value) |
virtual Vec2 | getCentroid () const |
virtual void | setCentroid (const Vec2 value) |
virtual void | setCentroid (float x, float y) |
virtual float | getInertia () const |
virtual void | setInertia (float value) |
virtual float | getMass () const |
virtual void | setMass (float value) |
virtual void | resetMass () |
bool | isRemoved () const |
void | markRemoved (bool value) |
bool | isDirty () const |
void | markDirty (bool value) |
void | setShared (bool shared) |
bool | isShared () const |
void | clearSharingDirtyBits () |
bool | hasDirtyType () const |
bool | hasDirtyPosition () const |
bool | hasDirtyVelocity () const |
bool | hasDirtyAngle () const |
bool | hasDirtyAngularVelocity () const |
bool | hasDirtyBool () const |
bool | hasDirtyFloat () const |
virtual b2Body * | getBody () |
virtual bool | activatePhysics (b2World &world) |
virtual void | deactivatePhysics (b2World &world) |
virtual void | createFixtures () |
virtual void | releaseFixtures () |
virtual void | update (float delta) |
const std::function< void(Obstacle *obstacle)> & | getListener () const |
void | setListener (const std::function< void(Obstacle *obstacle)> &listener) |
int | getPositionSnap () |
void | setPositionSnap (unsigned int snap) |
int | getAngleSnap () |
void | setAngleSnap (unsigned int snap) |
std::string | getName () const |
void | setName (std::string value) |
std::string | toString () const |
Color4 | getDebugColor () const |
virtual void | setDebugColor (Color4 color) |
scene2::SceneNode * | getDebugScene () const |
scene2::WireNode * | getDebugNode () const |
virtual void | setDebugScene (const std::shared_ptr< scene2::SceneNode > &node) |
bool | hasDebug () |
Static Public Member Functions | |
static std::shared_ptr< PolygonObstacle > | alloc (const Poly2 &poly) |
static std::shared_ptr< PolygonObstacle > | alloc (const Poly2 &poly, const Vec2 origin) |
static std::shared_ptr< PolygonObstacle > | allocWithAnchor (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::Obstacle | |
virtual void | resetDebug () |
virtual void | updateDebug () |
Protected Attributes | |
Poly2 | _polygon |
b2PolygonShape * | _shapes |
b2Fixture ** | _geoms |
Vec2 | _anchor |
int | _fixCount |
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 |
b2Body * | _body |
int | _posSnap |
unsigned long | _posFact |
int | _angSnap |
unsigned long | _angFact |
bool | _shared |
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.
|
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.
|
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.
|
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.
poly | The polygon vertices |
|
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.
poly | The polygon vertices |
origin | The rotational center with respect to the vertices |
|
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.
poly | The polygon vertices |
anchor | The rotational center of the polygon |
|
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::Obstacle.
|
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.
|
inline |
Returns the bounding box height
|
inline |
Returns the polygon defining this object
|
inline |
Returns the dimensions of the bounding box
|
inline |
Returns the bounding box width
|
inlinevirtual |
Initializes a new physics object at the origin.
Reimplemented from cugl::physics2::Obstacle.
|
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.
poly | The polygon vertices |
|
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.
poly | The polygon vertices |
origin | The rotational center with respect to the vertices |
|
virtual |
Initializes a new physics object at the given point
vec | Initial position in world coordinates |
Reimplemented from cugl::physics2::Obstacle.
|
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.
poly | The polygon vertices |
anchor | The rotational center of the polygon |
|
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::Obstacle.
|
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.
|
protected |
Recreates the shape objects attached to this polygon.
This must be called whenever the polygon is resized.
|
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.
size | The new dimension (width and height) |
|
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.
value | the rotational center of this polygon |
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.
x | the x-coordinate of the rotational center |
y | the y-coordinate of the rotational center |
|
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.
value | the bounding box height |
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.
value | the polygon defining this object |
|
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.
value | the dimensions of the bounding box |
|
inline |
Sets the dimensions of this box
width | The width of this box |
height | The height of this box |
|
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.
value | the bounding box width |
|
protected |
Anchor point to synchronize with the scene graph
|
protected |
In case the number of polygons changes
|
protected |
A cache value for the fixtures (for resizing)
|
protected |
The polygon vertices (for resizing)
|
protected |
Shape information for this physics object