CUGL 2.3
Cornell University Game Library
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
cugl::physics2::CapsuleObstacle Class Reference

#include <CUCapsuleObstacle.h>

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

Public Member Functions

 CapsuleObstacle (void)
 
virtual ~CapsuleObstacle ()
 
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, poly2::Capsule shape)
 
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)
 
poly2::Capsule getShape () const
 
void setShape (poly2::Capsule value)
 
void setSeamOffset (float value)
 
float getSeamOffset () const
 
virtual void setDensity (float value) override
 
virtual void createFixtures () override
 
virtual void releaseFixtures () override
 
- Public Member Functions inherited from cugl::physics2::SimpleObstacle
 SimpleObstacle ()
 
virtual ~SimpleObstacle ()
 
virtual b2BodyType getBodyType () const override
 
virtual void setBodyType (b2BodyType value) override
 
virtual Vec2 getPosition () const override
 
virtual void setPosition (const Vec2 value) override
 
virtual void setPosition (float x, float y) override
 
virtual float getX () const override
 
virtual void setX (float value) override
 
virtual float getY () const override
 
virtual void setY (float value) override
 
virtual float getAngle () const override
 
virtual void setAngle (float value) override
 
virtual Vec2 getLinearVelocity () const override
 
virtual void setLinearVelocity (const Vec2 value) override
 
virtual void setLinearVelocity (float x, float y) override
 
virtual float getVX () const override
 
virtual void setVX (float value) override
 
virtual float getVY () const override
 
virtual void setVY (float value) override
 
virtual float getAngularVelocity () const override
 
virtual void setAngularVelocity (float value) override
 
virtual bool isEnabled () const override
 
virtual void setEnabled (bool value) override
 
virtual bool isAwake () const override
 
virtual void setAwake (bool value) override
 
virtual bool isSleepingAllowed () const override
 
virtual void setSleepingAllowed (bool value) override
 
virtual bool isBullet () const override
 
virtual void setBullet (bool value) override
 
virtual bool isFixedRotation () const override
 
virtual void setFixedRotation (bool value) override
 
virtual float getGravityScale () const override
 
virtual void setGravityScale (float value) override
 
virtual float getLinearDamping () const override
 
virtual void setLinearDamping (float value) override
 
virtual float getAngularDamping () const override
 
virtual void setAngularDamping (float value) override
 
virtual void setDensity (float value) override
 
virtual void setFriction (float value) override
 
virtual void setRestitution (float value) override
 
virtual void setSensor (bool value) override
 
virtual void setFilterData (b2Filter value) override
 
virtual Vec2 getCentroid () const override
 
virtual void setCentroid (const Vec2 value) override
 
virtual void setCentroid (float x, float y) override
 
virtual float getInertia () const override
 
virtual void setInertia (float value) override
 
virtual float getMass () const override
 
virtual void setMass (float value) override
 
virtual void resetMass () override
 
virtual b2Body * getBody () override
 
virtual bool activatePhysics (b2World &world) override
 
virtual void deactivatePhysics (b2World &world) override
 
virtual void createFixtures ()
 
virtual void releaseFixtures ()
 
virtual void update (float delta) override
 
int getPositionSnap ()
 
void setPositionSnap (unsigned int snap)
 
int getAngleSnap ()
 
void setAngleSnap (unsigned int snap)
 
- Public Member Functions inherited from cugl::physics2::Obstacle
 Obstacle (void)
 
virtual ~Obstacle ()
 
virtual bool init ()
 
virtual bool init (const Vec2 vec)
 
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)
 
virtual b2Body * getBody ()
 
virtual bool activatePhysics (b2World &world)
 
virtual void deactivatePhysics (b2World &world)
 
virtual void update (float delta)
 
const std::function< void(Obstacle *obstacle)> & getListener () const
 
void setListener (const std::function< void(Obstacle *obstacle)> &listener)
 
std::string getName () const
 
void setName (std::string value)
 
std::string toString () const
 
Color4 getDebugColor () const
 
virtual void setDebugColor (Color4 color)
 
scene2::SceneNodegetDebugScene () const
 
scene2::WireNodegetDebugNode () const
 
virtual void setDebugScene (const std::shared_ptr< scene2::SceneNode > &node)
 
bool hasDebug ()
 

Static Public Member Functions

static std::shared_ptr< CapsuleObstaclealloc ()
 
static std::shared_ptr< CapsuleObstaclealloc (const Vec2 pos)
 
static std::shared_ptr< CapsuleObstaclealloc (const Vec2 pos, const Size size)
 
static std::shared_ptr< CapsuleObstaclealloc (const Vec2 pos, const Size size, poly2::Capsule shape)
 

Protected Member Functions

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

Protected Attributes

b2PolygonShape _shape
 
b2CircleShape _ends
 
b2AABB _center
 
b2Fixture * _core
 
b2Fixture * _cap1
 
b2Fixture * _cap2
 
Size _dimension
 
poly2::Capsule _orient
 
float _seamEpsilon
 
- Protected Attributes inherited from cugl::physics2::SimpleObstacle
b2Body * _body
 
int _posSnap
 
unsigned long _posFact
 
int _angSnap
 
unsigned long _angFact
 
- Protected Attributes inherited from cugl::physics2::Obstacle
b2BodyDef _bodyinfo
 
b2FixtureDef _fixture
 
b2MassData _massdata
 
bool _masseffect
 
std::shared_ptr< scene2::SceneNode_scene
 
std::shared_ptr< scene2::WireNode_debug
 
Color4 _dcolor
 
std::string _tag
 
std::function< void(Obstacle *obstacle)> _listener
 

Detailed Description

Capsule-shaped model to support collisions.

A capsule is a box with semicircular ends along the major axis. They are a popular physics object, 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.

If width < height, the capsule will be oriented vertically with the rounded portions at the top and bottom. Otherwise it will be oriented horizontally. The constructors allow some control over the capsule shape. You can have half-capsules or full capsules. In the case where width == height, the capsule will be a circle or semicircle, depending on the capsula shape.

Constructor & Destructor Documentation

◆ CapsuleObstacle()

cugl::physics2::CapsuleObstacle::CapsuleObstacle ( void  )
inline

Creates a new capsule object 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.

◆ ~CapsuleObstacle()

virtual cugl::physics2::CapsuleObstacle::~CapsuleObstacle ( )
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.

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

Member Function Documentation

◆ alloc() [1/4]

static std::shared_ptr< CapsuleObstacle > cugl::physics2::CapsuleObstacle::alloc ( )
inlinestatic

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

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

◆ alloc() [2/4]

static std::shared_ptr< CapsuleObstacle > cugl::physics2::CapsuleObstacle::alloc ( const Vec2  pos)
inlinestatic

Returns 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
a new capsule object at the given point with no size.

◆ alloc() [3/4]

static std::shared_ptr< CapsuleObstacle > cugl::physics2::CapsuleObstacle::alloc ( const Vec2  pos,
const Size  size 
)
inlinestatic

Returns 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 be a simple circle.

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
a new capsule object of the given dimensions.

◆ alloc() [4/4]

static std::shared_ptr< CapsuleObstacle > cugl::physics2::CapsuleObstacle::alloc ( const Vec2  pos,
const Size  size,
poly2::Capsule  shape 
)
inlinestatic

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

The orientation of the capsule is determined by the major axis. A HALF capsule is rounded on the left for horizontal orientation and on the bottom for vertical orientation. A HALF_REVERSE capsule is the reverse.

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)
shapeThe capsule shape/orientation
Returns
a new capsule object of the given dimensions and orientation.

◆ createFixtures()

virtual void cugl::physics2::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 cugl::physics2::SimpleObstacle.

◆ getDimension()

const Size cugl::physics2::CapsuleObstacle::getDimension ( ) const
inline

Returns the dimensions of this capsule

Returns
the dimensions of this capsule

◆ getHeight()

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

Returns the capsule height

Returns
the capsule height

◆ getSeamOffset()

float cugl::physics2::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

◆ getShape()

poly2::Capsule cugl::physics2::CapsuleObstacle::getShape ( ) const
inline

Returns the shape/orientation of this capsule

Returns
the shape/orientation of this capsule

◆ getWidth()

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

Returns the capsule width

Returns
the capsule width

◆ init() [1/4]

virtual bool cugl::physics2::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 cugl::physics2::Obstacle.

◆ init() [2/4]

virtual bool cugl::physics2::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 cugl::physics2::Obstacle.

◆ init() [3/4]

virtual bool cugl::physics2::CapsuleObstacle::init ( const Vec2  pos,
const Size  size 
)
inlinevirtual

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 be a simple circle.

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
true if the obstacle is initialized properly, false otherwise.

◆ init() [4/4]

virtual bool cugl::physics2::CapsuleObstacle::init ( const Vec2  pos,
const Size  size,
poly2::Capsule  shape 
)
virtual

Initializes a new capsule object of the given dimensions.

The orientation of the capsule is determined by the major axis. A HALF capsule is rounded on the left for horizontal orientation and on the bottom for vertical orientation. A HALF_REVERSE capsule is the reverse.

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)
shapeThe capsule shape/orientation
Returns
true if the obstacle is initialized properly, false otherwise.

◆ releaseFixtures()

virtual void cugl::physics2::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 cugl::physics2::SimpleObstacle.

◆ resetDebug()

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

Creates the outline of the physics fixtures in the debug node

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

Reimplemented from cugl::physics2::Obstacle.

◆ resize()

void cugl::physics2::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)

◆ setDensity()

virtual void cugl::physics2::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 cugl::physics2::SimpleObstacle.

◆ setDimension() [1/2]

void cugl::physics2::CapsuleObstacle::setDimension ( const Size  value)
inline

Sets the dimensions of this capsule

Parameters
valuethe dimensions of this capsule

◆ setDimension() [2/2]

void cugl::physics2::CapsuleObstacle::setDimension ( float  width,
float  height 
)
inline

Sets the dimensions of this capsule

Parameters
widthThe width of this capsule
heightThe height of this capsule

◆ setHeight()

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

Sets the capsule height

Parameters
valuethe capsule height

◆ setSeamOffset()

void cugl::physics2::CapsuleObstacle::setSeamOffset ( float  value)

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

Parameters
valuethe seam offset of the core rectangle

◆ setShape()

void cugl::physics2::CapsuleObstacle::setShape ( poly2::Capsule  value)

Sets the shape/orientation of this capsule.

Parameters
valuethe shape/orientation of this capsule

◆ setWidth()

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

Sets the capsule width

Parameters
valuethe capsule width

Member Data Documentation

◆ _cap1

b2Fixture* cugl::physics2::CapsuleObstacle::_cap1
protected

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

◆ _cap2

b2Fixture* cugl::physics2::CapsuleObstacle::_cap2
protected

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

◆ _center

b2AABB cugl::physics2::CapsuleObstacle::_center
protected

AABB representation of capsule core for fast computation

◆ _core

b2Fixture* cugl::physics2::CapsuleObstacle::_core
protected

A cache value for the center fixture (for resizing)

◆ _dimension

Size cugl::physics2::CapsuleObstacle::_dimension
protected

The width and height of the capsule

◆ _ends

b2CircleShape cugl::physics2::CapsuleObstacle::_ends
protected

Shape information for the end caps

◆ _orient

poly2::Capsule cugl::physics2::CapsuleObstacle::_orient
protected

The capsule shape

◆ _seamEpsilon

float cugl::physics2::CapsuleObstacle::_seamEpsilon
protected

The seam offset of the core rectangle

◆ _shape

b2PolygonShape cugl::physics2::CapsuleObstacle::_shape
protected

Shape information for this capsule core


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