Cornell Cocos
Cornell Extensions to Cocos2d
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
CapsuleObstacle Class Reference

#include <CUCapsuleObstacle.h>

Inheritance diagram for CapsuleObstacle:
SimpleObstacle Obstacle

Public Types

enum  Orientation {
  Orientation::TOP, Orientation::VERTICAL, Orientation::BOTTOM, Orientation::LEFT,
  Orientation::HORIZONTAL, Orientation::RIGHT
}
 

Public Member Functions

const Size & getDimension () const
 
void setDimension (const Size &value)
 
void setDimension (float width, float height)
 
float getWidth () const
 
void setWidth (float value)
 
float getHeight () const
 
void setHeight (float value)
 
const OrientationgetOrientation () const
 
bool setOrientation (Orientation value)
 
void setSeamOffset (float value)
 
float getSeamOffset () const
 
virtual void setDensity (float value) override
 
virtual void createFixtures () override
 
virtual void releaseFixtures () override
 
CC_CONSTRUCTOR_ACCESS _core (nullptr)
 
CC_CONSTRUCTOR_ACCESS _cap1 (nullptr)
 
CC_CONSTRUCTOR_ACCESS _cap2 (nullptr)
 
CC_CONSTRUCTOR_ACCESS _seamEpsilon (0.0f)
 
virtual bool init () override
 
virtual bool init (const Vec2 &pos) override
 
virtual bool init (const Vec2 &pos, const Size &size)
 
virtual bool init (const Vec2 &pos, const Size &size, Orientation orient)
 
- Public Member Functions inherited from 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 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 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 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)
 
WireNodegetDebugNode () const
 
void setDebugNode (WireNode *node)
 
string getName () const
 
void setName (string value)
 
string toString () const
 
virtual ~Obstacle ()
 

Static Public Member Functions

static CapsuleObstaclecreate ()
 
static CapsuleObstaclecreate (const Vec2 &pos)
 
static CapsuleObstaclecreate (const Vec2 &pos, const Size &size)
 
static CapsuleObstaclecreate (const Vec2 &pos, const Size &size, Orientation orient)
 

Public Attributes

CC_CONSTRUCTOR_ACCESS __pad0__: CapsuleObstacle(void) : SimpleObstacle()
 
- Public Attributes inherited from SimpleObstacle
CC_CONSTRUCTOR_ACCESS __pad0__: SimpleObstacle() : Obstacle()
 
- Public Attributes inherited from Obstacle
CC_CONSTRUCTOR_ACCESS __pad0__: Obstacle(void)
 

Protected Member Functions

bool resize (const Size &size)
 
virtual void resetDebugNode () override
 
- Protected Member Functions inherited from Obstacle
virtual void resetSceneNode ()
 

Protected Attributes

b2PolygonShape _shape
 
b2CircleShape _ends
 
b2AABB _center
 
b2Fixture * _core
 
b2Fixture * _cap1
 
b2Fixture * _cap2
 
Size _dimension
 
Orientation _orient
 
float _seamEpsilon
 
- Protected Attributes inherited from SimpleObstacle
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
 

Detailed Description

Capsule-shaped model to support collisions.

A capsule is a box with semicircular ends along the major axis. They are a popular physics objects, particularly for character avatars. The rounded ends means they are less likely to snag, and they naturally fall off platforms when they go too far.

The constructors allow some control over the capsule shape. You can have half-capsules or full capsules. In the case where width == height, you can specify a vertical or horizontal capsule. However, the circles must be on a major axis. Therefore, you cannot have a vertical capsule if width > height, or a horiztonal capsule when width < height. The constructors will fail in those cases.

Member Enumeration Documentation

Enum to specify the capsule orientiation

Enumerator
TOP 

A half-capsule with a rounded end at the top

VERTICAL 

A full capsule with a rounded ends at the top and bottom

BOTTOM 

A half-capsule with a rounded end at the bottom

LEFT 

A half-capsule with a rounded end at the left

HORIZONTAL 

A full capsule with a rounded ends at the left and right

RIGHT 

A half-capsule with a rounded end at the right

Member Function Documentation

CapsuleObstacle * CapsuleObstacle::create ( )
static

Creates a new capsule object at the origin with no size.

Returns
An autoreleased physics object
CapsuleObstacle * CapsuleObstacle::create ( const Vec2 &  pos)
static

Creates a new capsule object at the given point with no size.

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 scene graph node is positioned correctly according to the drawing scale.

Parameters
posInitial position in world coordinates
Returns
An autoreleased physics object
CapsuleObstacle * CapsuleObstacle::create ( const Vec2 &  pos,
const Size &  size 
)
static

Creates a new capsule object of the given dimensions.

The orientation of the capsule will be a full capsule along the major axis. If width == height, it will default to a vertical orientation.

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 scene graph node is positioned correctly according to the drawing scale.

Parameters
posInitial position in world coordinates
sizeThe capsule size (width and height)
Returns
An autoreleased physics object
CapsuleObstacle * CapsuleObstacle::create ( const Vec2 &  pos,
const Size &  size,
CapsuleObstacle::Orientation  orient 
)
static

Creates a new capsule object of the given dimensions and orientation.

The orientation must be consistent with the major axis (or else the two axes must be the same). If the orientation specifies a minor axis, then this constructor will return null.

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 scene graph node is positioned correctly according to the drawing scale.

Parameters
posInitial position in world coordinates
sizeThe capsule size (width and height)
orientThe capsule orientation
Returns
An autoreleased physics object
void CapsuleObstacle::createFixtures ( )
overridevirtual

Create new fixtures for this body, defining the shape

This is the primary method to override for custom physics objects

Reimplemented from SimpleObstacle.

const Size& CapsuleObstacle::getDimension ( ) const
inline

Returns the dimensions of this capsule

Returns
the dimensions of this capsule
float CapsuleObstacle::getHeight ( ) const
inline

Returns the capsule height

Returns
the capsule height
const Orientation& CapsuleObstacle::getOrientation ( ) const
inline

Returns the orientation of this capsule

Returns
the orientation of this capsule
float CapsuleObstacle::getSeamOffset ( ) const
inline

Returns the seam offset of the core rectangle

If the center rectangle is exactly the same size as the circle radius, you may get catching at the seems. To prevent this, you should make the center rectangle epsilon narrower so that everything rolls off the round shape. This parameter is that epsilon value

Returns
the seam offset of the core rectangle
float CapsuleObstacle::getWidth ( ) const
inline

Returns the capsule width

Returns
the capsule width
virtual bool CapsuleObstacle::init ( )
inlineoverridevirtual

Initializes a new box object at the origin with no size.

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

Reimplemented from Obstacle.

virtual bool CapsuleObstacle::init ( const Vec2 &  pos)
inlineoverridevirtual

Initializes a new capsule object at the given point with no size.

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 scene graph node is positioned correctly according to the drawing scale.

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

Reimplemented from Obstacle.

bool CapsuleObstacle::init ( const Vec2 &  pos,
const Size &  size 
)
virtual

Initializes a new capsule object of the given dimensions.

The orientation of the capsule will be a full capsule along the major axis. If width == height, it will default to a vertical orientation.

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 scene graph node is positioned correctly according to the drawing scale.

Parameters
posInitial position in world coordinates
sizeThe box size (width and height)
Returns
true if the obstacle is initialized properly, false otherwise.
bool CapsuleObstacle::init ( const Vec2 &  pos,
const Size &  size,
CapsuleObstacle::Orientation  orient 
)
virtual

Initializes a new capsule object of the given dimensions.

The orientation must be consistent with the major axis (or else the two axes must be the same). If the orientation specifies a minor axis, then this initializer will fail.

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 scene graph node is positioned correctly according to the drawing scale.

Parameters
posInitial position in world coordinates
sizeThe box size (width and height)
Returns
true if the obstacle is initialized properly, false otherwise.
void CapsuleObstacle::releaseFixtures ( )
overridevirtual

Release the fixtures for this body, reseting the shape

This is the primary method to override for custom physics objects

Reimplemented from SimpleObstacle.

void CapsuleObstacle::resetDebugNode ( )
overrideprotectedvirtual

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).

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 from Obstacle.

bool CapsuleObstacle::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)

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

Parameters
sizeThe new dimension (width and height)
void CapsuleObstacle::setDensity ( float  value)
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.

Parameters
valuethe density of this body

Reimplemented from SimpleObstacle.

void CapsuleObstacle::setDimension ( const Size &  value)
inline

Sets the dimensions of this capsule

Parameters
valuethe dimensions of this capsule
void CapsuleObstacle::setDimension ( float  width,
float  height 
)
inline

Sets the dimensions of this capsule

Parameters
widthThe width of this capsule
heightThe height of this capsule
void CapsuleObstacle::setHeight ( float  value)
inline

Sets the capsule height

Parameters
valuethe capsule height
bool CapsuleObstacle::setOrientation ( Orientation  value)

Sets the orientation of this capsule, if valid.

If the orientation is not valid, then nothing happens and the method return false.

Parameters
valuethe orientation of this capsule
Returns
true if the orientation was successfully changed.
void CapsuleObstacle::setSeamOffset ( float  value)
inline

Sets the seam offset of the core rectangle

If the center rectangle is exactly the same size as the circle radius, you may get catching at the seems. To prevent this, you should make the center rectangle epsilon narrower so that everything rolls off the round shape. This parameter is that epsilon value

value the seam offset of the core rectangle

void CapsuleObstacle::setWidth ( float  value)
inline

Sets the capsule width

Parameters
valuethe capsule width

Member Data Documentation

b2Fixture* CapsuleObstacle::_cap1
protected

A cache value for the first end cap fixture (for resizing)

b2Fixture* CapsuleObstacle::_cap2
protected

A cache value for the second end cap fixture (for resizing)

b2AABB CapsuleObstacle::_center
protected

AABB representation of capsule core for fast computation

b2Fixture* CapsuleObstacle::_core
protected

A cache value for the center fixture (for resizing)

Size CapsuleObstacle::_dimension
protected

The width and height of the capsule

b2CircleShape CapsuleObstacle::_ends
protected

Shape information for the end caps

Orientation CapsuleObstacle::_orient
protected

The capsule orientation

float CapsuleObstacle::_seamEpsilon
protected

The seam offset of the core rectangle

b2PolygonShape CapsuleObstacle::_shape
protected

Shape information for this capsule core


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