Cornell Cocos
Cornell Extensions to Cocos2d
|
#include <CUSimpleObstacle.h>
Public Member Functions | |
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 | isActive () const override |
virtual void | setActive (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 () const override |
virtual bool | activatePhysics (b2World &world) override |
virtual void | deactivatePhysics (b2World &world) override |
virtual void | createFixtures () |
virtual void | releaseFixtures () |
virtual void | update (float delta) override |
int | getPositionSnap () |
void | setPositionSnap (unsigned int snap) |
int | getAngleSnap () |
void | setAngleSnap (unsigned int snap) |
virtual void | positionSceneNode () override |
virtual void | positionDebugNode () override |
CC_CONSTRUCTOR_ACCESS | _body (nullptr) |
virtual | ~SimpleObstacle () |
Public Member Functions inherited from Obstacle | |
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 Vec2 & | getDrawScale () const |
virtual void | setDrawScale (const Vec2 &value) |
virtual void | setDrawScale (float x, float y) |
Node * | getSceneNode () const |
void | setSceneNode (Node *node) |
WireNode * | getDebugNode () const |
void | setDebugNode (WireNode *node) |
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__: SimpleObstacle() : Obstacle() |
Public Attributes inherited from Obstacle | |
CC_CONSTRUCTOR_ACCESS | __pad0__: Obstacle(void) |
Protected Attributes | |
b2Body * | _body |
int | _posSnap |
unsigned long | _posFact |
int | _angSnap |
unsigned long | _angFact |
Protected Attributes inherited from Obstacle | |
b2BodyDef | _bodyinfo |
b2FixtureDef | _fixture |
b2MassData | _massdata |
Vec2 | _drawScale |
bool | _masseffect |
Node * | _node |
WireNode * | _debug |
string | _tag |
Additional Inherited Members | |
Protected Member Functions inherited from Obstacle | |
virtual void | resetSceneNode () |
virtual void | resetDebugNode () |
Base model class to support collisions.
This is an instance of a Physics object with just one body. It does not have any joints. It is the primary type of physics object. This class does not provide Shape information, and should not be instantiated directly.
Many of the method comments in this class are taken from the Box2d manual by Erin Catto (2011).
|
inlinevirtual |
Deletes this physics object and all of its resources.
We have to make the destructor public so that we can polymorphically delete physics objects.
The purpose of this destructor is to warn us if we delete an object pre-maturely.
|
overridevirtual |
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.
world | Box2D world to store body |
Reimplemented from Obstacle.
|
inlinevirtual |
Create new fixtures for this body, defining the shape
This is the primary method to override for custom physics objects.
Reimplemented in CapsuleObstacle, PolygonObstacle, BoxObstacle, and WheelObstacle.
|
overridevirtual |
Destroys the physics Body(s) of this object if applicable, removing them from the world.
world | Box2D world that stores body |
Reimplemented from Obstacle.
|
inlineoverridevirtual |
Returns the angle of rotation for this body (about the center).
The value returned is in radians
Reimplemented from Obstacle.
|
inline |
Returns the number of decimal places to snap rotation of image to physics body
Physics bodies will have very precise angles, but these fractional angles may not be ideal for drawing, and may produce artifacts. When the value of snap is nonnegative, Cocos2d will round the rotation (measured in degrees, as that is the value used by images) of the image to snap decimal places.
For example, if the snap is 0, it will always round the angle to the nearest degree. If it is 1, it will round it to the nearest 10th of a degree. If it is -1 (or any negative value) it will not snap at all.
|
inlineoverridevirtual |
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.
Reimplemented from Obstacle.
|
inlineoverridevirtual |
Returns the angular velocity for this physics body
The rate of change is measured in radians per step
Reimplemented from Obstacle.
|
inlineoverridevirtual |
Returns the Box2D body for this object.
You use this body to add joints and apply forces.
Reimplemented from Obstacle.
|
inlineoverridevirtual |
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.
Reimplemented from Obstacle.
|
inlineoverridevirtual |
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.
Reimplemented from Obstacle.
|
inlineoverridevirtual |
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.
Reimplemented from Obstacle.
|
inlineoverridevirtual |
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.
Reimplemented from Obstacle.
|
inlineoverridevirtual |
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.
Reimplemented from Obstacle.
|
inlineoverridevirtual |
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.
Reimplemented from Obstacle.
|
inlineoverridevirtual |
Returns the mass of this body
The value is usually in kilograms.
Reimplemented from Obstacle.
|
inlineoverridevirtual |
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.
Reimplemented from Obstacle.
|
inline |
Returns the number of decimal places to snap position of image to physics body
Physics bodies will have very precise positions, but these fractional positions may not be ideal for drawing, and may produce artifacts. When the value of snap is nonnegative, Cocos2d will round the position of the image to snap decimal places.
For example, if the snap is 0, it will always round position to the nearest integer. If it is 1, it will round it to the nearest 10th of a point. If it is -1 (or any negative value) it will not snap at all.
|
inlineoverridevirtual |
Returns the x-velocity for this physics body
Reimplemented from Obstacle.
|
inlineoverridevirtual |
Returns the y-velocity for this physics body
Reimplemented from Obstacle.
|
inlineoverridevirtual |
Returns the x-coordinate for this physics body
Reimplemented from Obstacle.
|
inlineoverridevirtual |
Returns the x-coordinate for this physics body
Reimplemented from Obstacle.
|
inlineoverridevirtual |
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.
Reimplemented from Obstacle.
|
inlineoverridevirtual |
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.
Reimplemented from Obstacle.
|
inlineoverridevirtual |
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.
Reimplemented from Obstacle.
|
inlineoverridevirtual |
Returns true if this body be prevented from rotating
This is very useful for characters that should remain upright.
Reimplemented from Obstacle.
|
inlineoverridevirtual |
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.
Reimplemented from Obstacle.
|
overridevirtual |
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 from Obstacle.
|
overridevirtual |
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 from Obstacle.
|
inlinevirtual |
Release the fixtures for this body, reseting the shape
This is the primary method to override for custom physics objects.
Reimplemented in CapsuleObstacle, PolygonObstacle, BoxObstacle, and WheelObstacle.
|
inlineoverridevirtual |
Resets this body to use the mass computed from the its shape and density
Reimplemented from Obstacle.
|
inlineoverridevirtual |
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.
value | whether the body is active |
Reimplemented from Obstacle.
|
inlineoverridevirtual |
Sets the angle of rotation for this body (about the center).
value | the angle of rotation for this body (in radians) |
Reimplemented from Obstacle.
|
inline |
Sets the number of decimal places to snap position of image to physics body
Physics bodies will have very precise angles, but these fractional angles may not be ideal for drawing, and may produce artifacts. When the value of snap is nonnegative, Cocos2d will round the rotation (measured in degrees, as that is the value used by images) of the image to snap decimal places.
For example, if the snap is 0, it will always round the angle to the nearest degree. If it is 1, it will round it to the nearest 10th of a degree. If it is -1 (or any negative value) it will not snap at all.
snap | the number of decimal places to snap position of image to physics body |
|
inlineoverridevirtual |
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.
value | the angular damping for this body. |
Reimplemented from Obstacle.
|
inlineoverridevirtual |
Sets the angular velocity for this physics body
value | the angular velocity for this physics body (in radians) |
Reimplemented from Obstacle.
|
inlineoverridevirtual |
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.
value | whether the body is awake |
Reimplemented from Obstacle.
|
inlineoverridevirtual |
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.
value | the body type for Box2D physics |
Reimplemented from Obstacle.
|
inlineoverridevirtual |
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.
value | whether this body is a bullet |
Reimplemented from Obstacle.
|
inlineoverridevirtual |
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.
value | the center of mass for this physics body |
Reimplemented from Obstacle.
|
inlineoverridevirtual |
Sets the center of mass for this physics body
x | the x-coordinate of the center of mass for this physics body |
y | the y-coordinate of the center of mass for this physics body |
Reimplemented from Obstacle.
|
overridevirtual |
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.
value | the density of this body |
Reimplemented from Obstacle.
Reimplemented in CapsuleObstacle.
|
overridevirtual |
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.
value | the filter data for this object |
Reimplemented from Obstacle.
|
inlineoverridevirtual |
Sets whether this body be prevented from rotating
This is very useful for characters that should remain upright.
value | whether this body be prevented from rotating |
Reimplemented from Obstacle.
|
overridevirtual |
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.
value | the friction coefficient of this body |
Reimplemented from Obstacle.
|
inlineoverridevirtual |
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.
value | the gravity scale to apply to this body |
Reimplemented from Obstacle.
|
inlineoverridevirtual |
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.
value | the rotational inertia of this body |
Reimplemented from Obstacle.
|
inlineoverridevirtual |
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.
value | the linear damping for this body. |
Reimplemented from Obstacle.
|
inlineoverridevirtual |
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.
value | the linear velocity for this physics body |
Reimplemented from Obstacle.
|
inlineoverridevirtual |
Sets the linear velocity for this physics body
x | the x-coordinate of the linear velocity |
y | the y-coordinate of the linear velocity |
Reimplemented from Obstacle.
|
inlineoverridevirtual |
Sets the mass of this body
The value is usually in kilograms.
value | the mass of this body |
Reimplemented from Obstacle.
|
inlineoverridevirtual |
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.
value | the current position for this physics body |
Reimplemented from Obstacle.
|
inlineoverridevirtual |
Sets the current position for this physics body
x | the current x-coordinate for this physics body |
y | the current y-coordinate for this physics body |
Reimplemented from Obstacle.
|
inline |
Sets the number of decimal places to snap position of image to physics body
Physics bodies will have very precise positions, but these fractional positions may not be ideal for drawing, and may produce artifacts. When the value of snap is nonnegative, Cocos2d will round the position of the image to snap decimal places.
For example, if the snap is 0, it will always round position to the nearest integer. If it is 1, it will round it to the nearest 10th of a point. If it is -1 (or any negative value) it will not snap at all.
snap | the number of decimal places to snap position of image to physics body |
|
overridevirtual |
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.
value | the restitution of this body |
Reimplemented from Obstacle.
|
overridevirtual |
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.
value | whether this object is a sensor. |
Reimplemented from Obstacle.
|
inlineoverridevirtual |
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.
value | whether the body should ever fall asleep |
Reimplemented from Obstacle.
|
inlineoverridevirtual |
Sets the x-velocity for this physics body
value | the x-velocity for this physics body |
Reimplemented from Obstacle.
|
inlineoverridevirtual |
Sets the y-velocity for this physics body
value | the y-velocity for this physics body |
Reimplemented from Obstacle.
|
inlineoverridevirtual |
Sets the x-coordinate for this physics body
value | the x-coordinate for this physics body |
Reimplemented from Obstacle.
|
inlineoverridevirtual |
Sets the y-coordinate for this physics body
value | the y-coordinate for this physics body |
Reimplemented from Obstacle.
|
overridevirtual |
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.
dt | Timing values from parent loop |
Reimplemented from Obstacle.
|
protected |
Cache of factor to snap rotation of image to physics body
|
protected |
Number of decimal places to snap rotation of image to physics body
|
protected |
The physics body for Box2D.
|
protected |
Cache of factor to snap position of image to physics body
|
protected |
Number of decimal places to snap position of image to physics body