Cornell Cocos
Cornell Extensions to Cocos2d
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Friends | List of all members
Obstacle Class Reference

#include <CUObstacle.h>

Inheritance diagram for Obstacle:
ComplexObstacle SimpleObstacle BoxObstacle CapsuleObstacle PolygonObstacle WheelObstacle

Public Member Functions

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 isActive () const
 
virtual void setActive (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)
 
const Vec2 & getDrawScale () const
 
virtual void setDrawScale (const Vec2 &value)
 
virtual void setDrawScale (float x, float y)
 
Node * getSceneNode () const
 
void setSceneNode (Node *node)
 
WireNodegetDebugNode () const
 
void setDebugNode (WireNode *node)
 
virtual b2Body * getBody () const
 
virtual bool activatePhysics (b2World &world)
 
virtual void deactivatePhysics (b2World &world)
 
virtual void update (float delta)
 
string getName () const
 
void setName (string value)
 
string toString () const
 
virtual ~Obstacle ()
 
virtual bool init ()
 
virtual bool init (const Vec2 &vec)
 

Public Attributes

CC_CONSTRUCTOR_ACCESS __pad0__: Obstacle(void)
 

Protected Member Functions

virtual void resetSceneNode ()
 
virtual void positionSceneNode ()
 
virtual void resetDebugNode ()
 
virtual void positionDebugNode ()
 

Protected Attributes

b2BodyDef _bodyinfo
 
b2FixtureDef _fixture
 
b2MassData _massdata
 
Vec2 _drawScale
 
bool _masseffect
 
Node * _node
 
WireNode_debug
 
string _tag
 

Friends

ostream & operator<< (ostream &os, const Obstacle &obj)
 

Detailed Description

Base model class to support collisions.

Instances represents a body and/or a group of bodies. There should be NO game controlling logic code in a physics objects. That should reside in the Controllers.

This abstract class has no Body or Shape information and should never be instantiated directly. Instead, you should instantiate either SimpleObstacle or or ComplexObstacle. This class only exists to unify common functionality. In particular, it wraps the body and and fixture information into a single interface.

Many of the method comments in this class are taken from the Box2d manual by Erin Catto (2011).

Constructor & Destructor Documentation

Obstacle::~Obstacle ( )
virtual

Deletes this physics object and all of its resources.

We have to make the destructor public so that we can polymorphically delete physics objects.

A non-default destructor is necessary since we must release all claims on scene graph nodes.

Member Function Documentation

virtual bool Obstacle::activatePhysics ( b2World &  world)
inlinevirtual

Creates the physics Body(s) for this object, adding them to the world.

Implementations of this method should NOT retain a reference to World. That is a tight coupling that we should avoid.

Parameters
worldBox2D world to store body
Returns
true if object allocation succeeded

Reimplemented in ComplexObstacle, and SimpleObstacle.

virtual void Obstacle::deactivatePhysics ( b2World &  world)
inlinevirtual

Destroys the physics Body(s) of this object if applicable, removing them from the world.

Parameters
worldBox2D world that stores body

Reimplemented in ComplexObstacle, and SimpleObstacle.

virtual float Obstacle::getAngle ( ) const
inlinevirtual

Returns the angle of rotation for this body (about the center).

The value returned is in radians

Returns
the angle of rotation for this body

Reimplemented in ComplexObstacle, and SimpleObstacle.

virtual float Obstacle::getAngularDamping ( ) const
inlinevirtual

Returns the angular damping for this body.

Angular damping is use to reduce the angular velocity. Damping is different than friction because friction only occurs with contact. Damping is not a replacement for friction and the two effects should be used together.

Damping parameters should be between 0 and infinity, with 0 meaning no damping, and infinity meaning full damping. Normally you will use a damping value between 0 and 0.1.

Returns
the angular damping for this body.

Reimplemented in ComplexObstacle, and SimpleObstacle.

virtual float Obstacle::getAngularVelocity ( ) const
inlinevirtual

Returns the angular velocity for this physics body

The rate of change is measured in radians per step

Returns
the angular velocity for this physics body

Reimplemented in ComplexObstacle, and SimpleObstacle.

virtual b2Body* Obstacle::getBody ( ) const
inlinevirtual

Returns the Box2D body for this object.

You use this body to add joints and apply forces. We return a pointer instead of a reference because this value could be none.

Returns
the Box2D body for this object.

Reimplemented in ComplexObstacle, and SimpleObstacle.

virtual b2BodyType Obstacle::getBodyType ( ) const
inlinevirtual

Returns the body type for Box2D physics

If you want to lock a body in place (e.g. a platform) set this value to STATIC. KINEMATIC allows the object to move (and some limited collisions), but ignores external forces (e.g. gravity). DYNAMIC makes this is a full-blown physics object.

Returns
the body type for Box2D physics

Reimplemented in ComplexObstacle, and SimpleObstacle.

virtual Vec2 Obstacle::getCentroid ( ) const
inlinevirtual

Returns the center of mass of this body

This method converts from a Box2D vector type to a Cocos2D vector type. This cuts down on the confusion between vector types. It also means that changes to the returned vector will have no effect on this object.

Returns
the center of mass for this physics body

Reimplemented in ComplexObstacle, and SimpleObstacle.

WireNode* Obstacle::getDebugNode ( ) const
inline

Returns the scene graph node for debugging purposes.

The debug node is used 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).

The scene graph is completely decoupled from the physics system. The node does not have to be the same size as the physics body. We only guarantee that the node is positioned correctly according to the drawing scale.

Returns
the scene graph node for debugging purposes.
float Obstacle::getDensity ( ) const
inline

Returns the density of this body

The density is typically measured in usually in kg/m^2. The density can be zero or positive. You should generally use similar densities for all your fixtures. This will improve stacking stability.

Returns
the density of this body
const Vec2& Obstacle::getDrawScale ( ) const
inline

Returns the drawing scale for this physics object

The drawing scale is the number of pixels to draw before Box2D unit. Because mass is a function of area in Box2D, we typically want the physics objects to be small. So we decouple that scale from the physics object. However, we must track the scale difference to communicate with the scene graph.

We allow for the scaling factor to be non-uniform.

Returns
the drawing scale for this physics object
b2Filter Obstacle::getFilterData ( ) const
inline

Returns the filter data for this object (or null if there is none)

Collision filtering allows you to prevent collision between fixtures. For example, say you make a character that rides a bicycle. You want the bicycle to collide with the terrain and the character to collide with the terrain, but you don't want the character to collide with the bicycle (because they must overlap). Box2D supports such collision filtering using categories and groups.

Returns
the filter data for this object (or null if there is none)
float Obstacle::getFriction ( ) const
inline

Returns the friction coefficient of this body

The friction parameter is usually set between 0 and 1, but can be any non-negative value. A friction value of 0 turns off friction and a value of 1 makes the friction strong. When the friction force is computed between two shapes, Box2D must combine the friction parameters of the two parent fixtures. This is done with the geometric mean.

Returns
the friction coefficient of this body
virtual float Obstacle::getGravityScale ( ) const
inlinevirtual

Returns the gravity scale to apply to this body

This allows isolated objects to float. Be careful with this, since increased gravity can decrease stability.

Returns
the gravity scale to apply to this body

Reimplemented in ComplexObstacle, and SimpleObstacle.

virtual float Obstacle::getInertia ( ) const
inlinevirtual

Returns the rotational inertia of this body

For static bodies, the mass and rotational inertia are set to zero. When a body has fixed rotation, its rotational inertia is zero.

Returns
the rotational inertia of this body

Reimplemented in ComplexObstacle, and SimpleObstacle.

virtual float Obstacle::getLinearDamping ( ) const
inlinevirtual

Returns the linear damping for this body.

Linear damping is use to reduce the linear velocity. Damping is different than friction because friction only occurs with contact. Damping is not a replacement for friction and the two effects should be used together.

Damping parameters should be between 0 and infinity, with 0 meaning no damping, and infinity meaning full damping. Normally you will use a damping value between 0 and 0.1. Most people avoid linear damping because it makes bodies look floaty.

Returns
the linear damping for this body.

Reimplemented in ComplexObstacle, and SimpleObstacle.

virtual Vec2 Obstacle::getLinearVelocity ( ) const
inlinevirtual

Returns the linear velocity for this physics body

This method converts from a Box2D vector type to a Cocos2D vector type. This cuts down on the confusion between vector types. It also means that changes to the returned vector will have no effect on this object.

Returns
the linear velocity for this physics body

Reimplemented in ComplexObstacle, and SimpleObstacle.

virtual float Obstacle::getMass ( ) const
inlinevirtual

Returns the mass of this body

The value is usually in kilograms.

Returns
the mass of this body

Reimplemented in ComplexObstacle, and SimpleObstacle.

string Obstacle::getName ( ) const
inline

Returns the physics object tag.

A tag is a string attached to an object, in order to identify it in debugging.

Returns
the physics object tag.
virtual Vec2 Obstacle::getPosition ( ) const
inlinevirtual

Returns the current position for this physics body

This method converts from a Box2D vector type to a Cocos2D vector type. This cuts down on the confusion between vector types. It also means that changes to the returned vector will have no effect on this object.

Returns
the current position for this physics body

Reimplemented in ComplexObstacle, and SimpleObstacle.

float Obstacle::getRestitution ( ) const
inline

Returns the restitution of this body

Restitution is used to make objects bounce. The restitution value is usually set to be between 0 and 1. Consider dropping a ball on a table. A value of zero means the ball won't bounce. This is called an inelastic collision. A value of one means the ball's velocity will be exactly reflected. This is called a perfectly elastic collision.

Returns
the restitution of this body
Node* Obstacle::getSceneNode ( ) const
inline

Returns the scene graph node for drawing purposes.

The scene graph is completely decoupled from the physics system. The node does not have to be the same size as the physics body. We only guarantee that the node is positioned correctly according to the drawing scale.

Returns
the scene graph node for drawing purposes.
virtual float Obstacle::getVX ( ) const
inlinevirtual

Returns the x-velocity for this physics body

Returns
the x-velocity for this physics body

Reimplemented in ComplexObstacle, and SimpleObstacle.

virtual float Obstacle::getVY ( ) const
inlinevirtual

Returns the y-velocity for this physics body

Returns
the y-velocity for this physics body

Reimplemented in ComplexObstacle, and SimpleObstacle.

virtual float Obstacle::getX ( ) const
inlinevirtual

Returns the x-coordinate for this physics body

Returns
the x-coordinate for this physics body

Reimplemented in ComplexObstacle, and SimpleObstacle.

virtual float Obstacle::getY ( ) const
inlinevirtual

Returns the y-coordinate for this physics body

Returns
the y-coordinate for this physics body

Reimplemented in ComplexObstacle, and SimpleObstacle.

virtual bool Obstacle::init ( )
inlinevirtual

Initializes a new physics object at the origin.

Returns
true if the obstacle is initialized properly, false otherwise.

Reimplemented in CapsuleObstacle, BoxObstacle, and WheelObstacle.

bool Obstacle::init ( const Vec2 &  vec)
virtual

Initializes a new physics object at the given point

Parameters
vecInitial position in world coordinates
Returns
true if the obstacle is initialized properly, false otherwise.

Reimplemented in CapsuleObstacle, BoxObstacle, and WheelObstacle.

virtual bool Obstacle::isActive ( ) const
inlinevirtual

Returns true if the body is active

An inactive body not participate in collision or dynamics. This state is similar to sleeping except the body will not be woken by other bodies and the body's fixtures will not be placed in the broad-phase. This means the body will not participate in collisions, ray casts, etc.

Returns
true if the body is active

Reimplemented in ComplexObstacle, and SimpleObstacle.

virtual bool Obstacle::isAwake ( ) const
inlinevirtual

Returns true if the body is awake

An sleeping body is one that has come to rest and the physics engine has decided to stop simulating it to save CPU cycles. If a body is awake and collides with a sleeping body, then the sleeping body wakes up. Bodies will also wake up if a joint or contact attached to them is destroyed. You can also wake a body manually.

Returns
true if the body is awake

Reimplemented in ComplexObstacle, and SimpleObstacle.

virtual bool Obstacle::isBullet ( ) const
inlinevirtual

Returns true if this body is a bullet

By default, Box2D uses continuous collision detection (CCD) to prevent dynamic bodies from tunneling through static bodies. Normally CCD is not used between dynamic bodies. This is done to keep performance reasonable. In some game scenarios you need dynamic bodies to use CCD. For example, you may want to shoot a high speed bullet at a stack of dynamic bricks. Without CCD, the bullet might tunnel through the bricks.

Fast moving objects in Box2D can be labeled as bullets. Bullets will perform CCD with both static and dynamic bodies. You should decide what bodies should be bullets based on your game design.

Returns
true if this body is a bullet

Reimplemented in ComplexObstacle, and SimpleObstacle.

bool Obstacle::isDirty ( ) const
inline

Returns true if the shape information must be updated.

Attributes tied to the geometry (and not just forces/position) must wait for collisions to complete before they are reset. Shapes (and their properties) are reset in the update method.

Returns
true if the shape information must be updated.
virtual bool Obstacle::isFixedRotation ( ) const
inlinevirtual

Returns true if this body be prevented from rotating

This is very useful for characters that should remain upright.

Returns
true if this body be prevented from rotating

Reimplemented in ComplexObstacle, and SimpleObstacle.

bool Obstacle::isRemoved ( ) const
inline

Returns true if our object has been flagged for garbage collection

A garbage collected object will be removed from the physics world at the next time step.

Returns
true if our object has been flagged for garbage collection
bool Obstacle::isSensor ( ) const
inline

Returns true if this object is a sensor.

Sometimes game logic needs to know when two entities overlap yet there should be no collision response. This is done by using sensors. A sensor is an entity that detects collision but does not produce a response.

Returns
true if this object is a sensor.
virtual bool Obstacle::isSleepingAllowed ( ) const
inlinevirtual

Returns false if this body should never fall asleep

An sleeping body is one that has come to rest and the physics engine has decided to stop simulating it to save CPU cycles. If a body is awake and collides with a sleeping body, then the sleeping body wakes up. Bodies will also wake up if a joint or contact attached to them is destroyed. You can also wake a body manually.

Returns
false if this body should never fall asleep

Reimplemented in ComplexObstacle, and SimpleObstacle.

void Obstacle::markDirty ( bool  value)
inline

Sets whether the shape information must be updated.

Attributes tied to the geometry (and not just forces/position) must wait for collisions to complete before they are reset. Shapes (and their properties) are reset in the update method.

Parameters
valuewhether the shape information must be updated.
void Obstacle::markRemoved ( bool  value)
inline

Sets whether our object has been flagged for garbage collection

A garbage collected object will be removed from the physics world at the next time step.

Parameters
valuewhether our object has been flagged for garbage collection
void Obstacle::positionDebugNode ( )
protectedvirtual

Repositions the debug node so that it agrees with the physics object.

By default, the position of a node should be the body position times the draw scale. However, for some obstacles (particularly complex obstacles), it may be desirable to turn the default functionality off. Hence we have made this virtual.

Reimplemented in ComplexObstacle, and SimpleObstacle.

void Obstacle::positionSceneNode ( )
protectedvirtual

Repositions the scene node so that it agrees with the physics object.

By default, the position of a node should be the body position times the draw scale. However, for some obstacles (particularly complex obstacles), it may be desirable to turn the default functionality off. Hence we have made this virtual.

Reimplemented in ComplexObstacle, and SimpleObstacle.

virtual void Obstacle::resetDebugNode ( )
inlineprotectedvirtual

Redraws the outline of the physics fixtures to 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).

Unfortunately, the current implementation is very inefficient. Cocos2d does not batch drawnode commands like it does Sprites or PolygonSprites. Therefore, every distinct DrawNode is a distinct OpenGL call. This can really hurt framerate when debugging mode is on. Ideally, we would refactor this so that we only draw to a single, master draw node. However, this means that we would have to handle our own vertex transformations, instead of relying on the transforms in the scene graph.

Reimplemented in CapsuleObstacle, PolygonObstacle, BoxObstacle, and WheelObstacle.

virtual void Obstacle::resetMass ( )
inlinevirtual

Resets this body to use the mass computed from the its shape and density

Reimplemented in ComplexObstacle, and SimpleObstacle.

virtual void Obstacle::resetSceneNode ( )
inlineprotectedvirtual

Performs any necessary additions to the scene graph node.

This method is necessary for custom physics objects that are composed of multiple scene graph nodes.

Reimplemented in PolygonObstacle.

virtual void Obstacle::setActive ( bool  value)
inlinevirtual

Sets whether the body is active

An inactive body not participate in collision or dynamics. This state is similar to sleeping except the body will not be woken by other bodies and the body's fixtures will not be placed in the broad-phase. This means the body will not participate in collisions, ray casts, etc.

Parameters
valuewhether the body is active

Reimplemented in ComplexObstacle, and SimpleObstacle.

virtual void Obstacle::setAngle ( float  value)
inlinevirtual

Sets the angle of rotation for this body (about the center).

Parameters
valuethe angle of rotation for this body (in radians)

Reimplemented in ComplexObstacle, and SimpleObstacle.

virtual void Obstacle::setAngularDamping ( float  value)
inlinevirtual

Sets the angular damping for this body.

Angular damping is use to reduce the angular velocity. Damping is different than friction because friction only occurs with contact. Damping is not a replacement for friction and the two effects should be used together.

Damping parameters should be between 0 and infinity, with 0 meaning no damping, and infinity meaning full damping. Normally you will use a damping value between 0 and 0.1.

Parameters
valuethe angular damping for this body.

Reimplemented in ComplexObstacle, and SimpleObstacle.

virtual void Obstacle::setAngularVelocity ( float  value)
inlinevirtual

Sets the angular velocity for this physics body

Parameters
valuethe angular velocity for this physics body (in radians)

Reimplemented in ComplexObstacle, and SimpleObstacle.

virtual void Obstacle::setAwake ( bool  value)
inlinevirtual

Sets whether the body is awake

An sleeping body is one that has come to rest and the physics engine has decided to stop simulating it to save CPU cycles. If a body is awake and collides with a sleeping body, then the sleeping body wakes up. Bodies will also wake up if a joint or contact attached to them is destroyed. You can also wake a body manually.

Parameters
valuewhether the body is awake

Reimplemented in ComplexObstacle, and SimpleObstacle.

void Obstacle::setBodyState ( const b2Body &  body)

Copies the state from the given body to the body def.

This is important if you want to save the state of the body before removing it from the world.

virtual void Obstacle::setBodyType ( b2BodyType  value)
inlinevirtual

Sets the body type for Box2D physics

If you want to lock a body in place (e.g. a platform) set this value to STATIC. KINEMATIC allows the object to move (and some limited collisions), but ignores external forces (e.g. gravity). DYNAMIC makes this is a full-blown physics object.

Parameters
valuethe body type for Box2D physics

Reimplemented in ComplexObstacle, and SimpleObstacle.

virtual void Obstacle::setBullet ( bool  value)
inlinevirtual

Sets whether this body is a bullet

By default, Box2D uses continuous collision detection (CCD) to prevent dynamic bodies from tunneling through static bodies. Normally CCD is not used between dynamic bodies. This is done to keep performance reasonable. In some game scenarios you need dynamic bodies to use CCD. For example, you may want to shoot a high speed bullet at a stack of dynamic bricks. Without CCD, the bullet might tunnel through the bricks.

Fast moving objects in Box2D can be labeled as bullets. Bullets will perform CCD with both static and dynamic bodies. You should decide what bodies should be bullets based on your game design.

Parameters
valuewhether this body is a bullet

Reimplemented in ComplexObstacle, and SimpleObstacle.

virtual void Obstacle::setCentroid ( const Vec2 &  value)
inlinevirtual

Sets the center of mass for this physics body

This method converts from a Cocos2D vector type to a Box2D vector type. This cuts down on the confusion between vector types.

Parameters
valuethe center of mass for this physics body

Reimplemented in ComplexObstacle, and SimpleObstacle.

void Obstacle::setCentroid ( float  x,
float  y 
)
virtual

Sets the center of mass for this physics body

Parameters
xthe x-coordinate of the center of mass for this physics body
ythe y-coordinate of the center of mass for this physics body

Reimplemented in ComplexObstacle, and SimpleObstacle.

void Obstacle::setDebugNode ( WireNode node)

Sets the scene graph node for debugging purposes.

The debug node is used 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).

The scene graph is completely decoupled from the physics system. The node does not have to be the same size as the physics body. We only guarantee that the node is positioned correctly according to the drawing scale.

Parameters
valuethe scene graph node for debugging purposes.

a reference to this debug scene graph node the previous debug scene graph node used by this object

Sets the scene graph node for debugging purposes.

The scene graph is completely decoupled from the physics system. The node does not have to be the same size as the physics body. We only guarantee that the node is positioned correctly according to the drawing scale.

Parameters
valuethe scene graph node for drawing purposes.

a reference to this debug scene graph node the previous debug scene graph node used by this object

virtual void Obstacle::setDensity ( float  value)
inlinevirtual

Sets the density of this body

The density is typically measured in usually in kg/m^2. The density can be zero or positive. You should generally use similar densities for all your fixtures. This will improve stacking stability.

Parameters
valuethe density of this body

Reimplemented in ComplexObstacle, SimpleObstacle, and CapsuleObstacle.

virtual void Obstacle::setDrawScale ( const Vec2 &  value)
inlinevirtual

Sets the drawing scale for this physics object

The drawing scale is the number of pixels to draw before Box2D unit. Because mass is a function of area in Box2D, we typically want the physics objects to be small. So we decouple that scale from the physics object. However, we must track the scale difference to communicate with the scene graph.

We allow for the scaling factor to be non-uniform.

Parameters
valuethe drawing scale for this physics object

Reimplemented in ComplexObstacle.

void Obstacle::setDrawScale ( float  x,
float  y 
)
virtual

Sets the drawing scale for this physics object

The drawing scale is the number of pixels to draw before Box2D unit. Because mass is a function of area in Box2D, we typically want the physics objects to be small. So we decouple that scale from the physics object. However, we must track the scale difference to communicate with the scene graph.

We allow for the scaling factor to be non-uniform.

Parameters
xthe x-axis scale for this physics object
ythe y-axis scale for this physics object

Reimplemented in ComplexObstacle.

virtual void Obstacle::setFilterData ( b2Filter  value)
inlinevirtual

Sets the filter data for this object

Collision filtering allows you to prevent collision between fixtures. For example, say you make a character that rides a bicycle. You want the bicycle to collide with the terrain and the character to collide with the terrain, but you don't want the character to collide with the bicycle (because they must overlap). Box2D supports such collision filtering using categories and groups.

A value of null removes all collision filters.

Parameters
valuethe filter data for this object

Reimplemented in ComplexObstacle, and SimpleObstacle.

virtual void Obstacle::setFixedRotation ( bool  value)
inlinevirtual

Sets whether this body be prevented from rotating

This is very useful for characters that should remain upright.

Parameters
valuewhether this body be prevented from rotating

Reimplemented in ComplexObstacle, and SimpleObstacle.

virtual void Obstacle::setFriction ( float  value)
inlinevirtual

Sets the friction coefficient of this body

The friction parameter is usually set between 0 and 1, but can be any non-negative value. A friction value of 0 turns off friction and a value of 1 makes the friction strong. When the friction force is computed between two shapes, Box2D must combine the friction parameters of the two parent fixtures. This is done with the geometric mean.

Parameters
valuethe friction coefficient of this body

Reimplemented in ComplexObstacle, and SimpleObstacle.

virtual void Obstacle::setGravityScale ( float  value)
inlinevirtual

Sets the gravity scale to apply to this body

This allows isolated objects to float. Be careful with this, since increased gravity can decrease stability.

Parameters
valuethe gravity scale to apply to this body

Reimplemented in ComplexObstacle, and SimpleObstacle.

void Obstacle::setInertia ( float  value)
virtual

Sets the rotational inertia of this body

For static bodies, the mass and rotational inertia are set to zero. When a body has fixed rotation, its rotational inertia is zero.

Parameters
valuethe rotational inertia of this body

Reimplemented in ComplexObstacle, and SimpleObstacle.

virtual void Obstacle::setLinearDamping ( float  value)
inlinevirtual

Sets the linear damping for this body.

Linear damping is use to reduce the linear velocity. Damping is different than friction because friction only occurs with contact. Damping is not a replacement for friction and the two effects should be used together.

Damping parameters should be between 0 and infinity, with 0 meaning no damping, and infinity meaning full damping. Normally you will use a damping value between 0 and 0.1. Most people avoid linear damping because it makes bodies look floaty.

Parameters
valuethe linear damping for this body.

Reimplemented in ComplexObstacle, and SimpleObstacle.

virtual void Obstacle::setLinearVelocity ( const Vec2 &  value)
inlinevirtual

Sets the linear velocity for this physics body

This method converts from a Cocos2D vector type to a Box2D vector type. This cuts down on the confusion between vector types.

Parameters
valuethe linear velocity for this physics body

Reimplemented in ComplexObstacle, and SimpleObstacle.

virtual void Obstacle::setLinearVelocity ( float  x,
float  y 
)
inlinevirtual

Sets the linear velocity for this physics body

Parameters
xthe x-coordinate of the linear velocity
ythe y-coordinate of the linear velocity

Reimplemented in ComplexObstacle, and SimpleObstacle.

void Obstacle::setMass ( float  value)
virtual

Sets the mass of this body

The value is usually in kilograms.

Parameters
valuethe mass of this body

Reimplemented in ComplexObstacle, and SimpleObstacle.

void Obstacle::setName ( string  value)
inline

Sets the physics object tag.

A tag is a string attached to an object, in order to identify it in debugging.

Parameters
valuethe physics object tag
virtual void Obstacle::setPosition ( const Vec2 &  value)
inlinevirtual

Sets the current position for this physics body

This method converts from a Cocos2D vector type to a Box2D vector type. This cuts down on the confusion between vector types.

Parameters
valuethe current position for this physics body

Reimplemented in ComplexObstacle, and SimpleObstacle.

virtual void Obstacle::setPosition ( float  x,
float  y 
)
inlinevirtual

Sets the current position for this physics body

Parameters
xthe current x-coordinate for this physics body
ythe current y-coordinate for this physics body

Reimplemented in ComplexObstacle, and SimpleObstacle.

virtual void Obstacle::setRestitution ( float  value)
inlinevirtual

Sets the restitution of this body

Restitution is used to make objects bounce. The restitution value is usually set to be between 0 and 1. Consider dropping a ball on a table. A value of zero means the ball won't bounce. This is called an inelastic collision. A value of one means the ball's velocity will be exactly reflected. This is called a perfectly elastic collision.

Parameters
valuethe restitution of this body

Reimplemented in ComplexObstacle, and SimpleObstacle.

void Obstacle::setSceneNode ( Node *  node)

Sets the scene graph node for drawing purposes.

The scene graph is completely decoupled from the physics system. The node does not have to be the same size as the physics body. We only guarantee that the node is positioned correctly according to the drawing scale.

Parameters
valuethe scene graph node for drawing purposes.

a reference to this scene graph node the previous scene graph node used by this object

Sets the scene graph node for drawing purposes.

The scene graph is completely decoupled from the physics system. The node does not have to be the same size as the physics body. We only guarantee that the node is positioned correctly according to the drawing scale.

Parameters
valuethe scene graph node for drawing purposes.

a reference to this scene graph node the previous debug graph node used by this object

virtual void Obstacle::setSensor ( bool  value)
inlinevirtual

Sets whether this object is a sensor.

Sometimes game logic needs to know when two entities overlap yet there should be no collision response. This is done by using sensors. A sensor is an entity that detects collision but does not produce a response.

Parameters
valuewhether this object is a sensor.

Reimplemented in ComplexObstacle, and SimpleObstacle.

virtual void Obstacle::setSleepingAllowed ( bool  value)
inlinevirtual

Sets whether the body should ever fall asleep

An sleeping body is one that has come to rest and the physics engine has decided to stop simulating it to save CPU cycles. If a body is awake and collides with a sleeping body, then the sleeping body wakes up. Bodies will also wake up if a joint or contact attached to them is destroyed. You can also wake a body manually.

Parameters
valuewhether the body should ever fall asleep

Reimplemented in ComplexObstacle, and SimpleObstacle.

virtual void Obstacle::setVX ( float  value)
inlinevirtual

Sets the x-velocity for this physics body

Parameters
valuethe x-velocity for this physics body

Reimplemented in ComplexObstacle, and SimpleObstacle.

virtual void Obstacle::setVY ( float  value)
inlinevirtual

Sets the y-velocity for this physics body

Parameters
valuethe y-velocity for this physics body

Reimplemented in ComplexObstacle, and SimpleObstacle.

virtual void Obstacle::setX ( float  value)
inlinevirtual

Sets the x-coordinate for this physics body

Parameters
valuethe x-coordinate for this physics body

Reimplemented in ComplexObstacle, and SimpleObstacle.

virtual void Obstacle::setY ( float  value)
inlinevirtual

Sets the y-coordinate for this physics body

Parameters
valuethe y-coordinate for this physics body

Reimplemented in ComplexObstacle, and SimpleObstacle.

string Obstacle::toString ( ) const

Returns a string representation of this physics object.

This method converts the physics object into a string for debugging. By default it shows the tag and position. Other physics objects may want to override this method for more detailed information.

Returns
a string representation of this physics object
virtual void Obstacle::update ( float  delta)
inlinevirtual

Updates the object's physics state (NOT GAME LOGIC).

This method is called AFTER the collision resolution state. Therefore, it should not be used to process actions or any other gameplay information. Its primary purpose is to adjust changes to the fixture, which have to take place after collision.

In other words, this is the method that updates the scene graph. If you forget to call it, it will not draw your changes.

Parameters
dtTiming values from parent loop

Reimplemented in ComplexObstacle, and SimpleObstacle.

Friends And Related Function Documentation

ostream& operator<< ( ostream &  os,
const Obstacle obj 
)
friend

Outputs this physics object to the given output stream.

This function uses the toString() method to convert the physics object into a string

Parameters
osthe output stream
objthe physics object to ouput
Returns
the output stream

Member Data Documentation

b2BodyDef Obstacle::_bodyinfo
protected

Stores the body information for this shape

WireNode* Obstacle::_debug
protected

The (optional) node for debug drawing.

Vec2 Obstacle::_drawScale
protected

The conversion rate between physics units and drawing units

b2FixtureDef Obstacle::_fixture
protected

Stores the fixture information for this shape

b2MassData Obstacle::_massdata
protected

The mass data of this shape (which may override the fixture)

bool Obstacle::_masseffect
protected

Whether or not to use the custom mass data

Node* Obstacle::_node
protected

The Cocos2D node in the scene graph.

string Obstacle::_tag
protected

A tag for debugging purposes


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