CUGL 2.1
Cornell University Game Library
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
cugl::physics2::SimpleObstacle Class Reference

#include <CUSimpleObstacle.h>

Inheritance diagram for cugl::physics2::SimpleObstacle:
cugl::physics2::Obstacle cugl::physics2::BoxObstacle cugl::physics2::CapsuleObstacle cugl::physics2::PolygonObstacle cugl::physics2::WheelObstacle

Public Member Functions

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

Protected Member Functions

virtual void updateDebug () override
 
- Protected Member Functions inherited from cugl::physics2::Obstacle
virtual void resetDebug ()
 

Protected Attributes

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

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

Constructor & Destructor Documentation

◆ SimpleObstacle()

cugl::physics2::SimpleObstacle::SimpleObstacle ( )
inline

Creates a new simple physics 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 (in this case, in one of the subclasses).

◆ ~SimpleObstacle()

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

Member Function Documentation

◆ activatePhysics()

virtual bool cugl::physics2::SimpleObstacle::activatePhysics ( b2World &  world)
overridevirtual

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

Implementations of this method should NOT retain ownership of the Box2D world. That is a tight coupling that we should avoid.

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

Reimplemented from cugl::physics2::Obstacle.

◆ createFixtures()

virtual void cugl::physics2::SimpleObstacle::createFixtures ( )
inlinevirtual

Create new fixtures for this body, defining the shape

This is the primary method to override for custom physics objects.

Reimplemented in cugl::physics2::CapsuleObstacle, cugl::physics2::PolygonObstacle, cugl::physics2::BoxObstacle, and cugl::physics2::WheelObstacle.

◆ deactivatePhysics()

virtual void cugl::physics2::SimpleObstacle::deactivatePhysics ( b2World &  world)
overridevirtual

Destroys the physics Body(s) of this object if applicable.

This removes the body from the Box2D world.

Parameters
worldBox2D world that stores body

Reimplemented from cugl::physics2::Obstacle.

◆ getAngle()

virtual float cugl::physics2::SimpleObstacle::getAngle ( ) const
inlineoverridevirtual

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

◆ getAngleSnap()

int cugl::physics2::SimpleObstacle::getAngleSnap ( )
inline

Returns the number of decimal places to snap rotation to the 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, CUGL 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.

Returns
the number of decimal places to snap rotation to the physics body

◆ getAngularDamping()

virtual float cugl::physics2::SimpleObstacle::getAngularDamping ( ) const
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.

Returns
the angular damping for this body.

Reimplemented from cugl::physics2::Obstacle.

◆ getAngularVelocity()

virtual float cugl::physics2::SimpleObstacle::getAngularVelocity ( ) const
inlineoverridevirtual

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

◆ getBody()

virtual b2Body* cugl::physics2::SimpleObstacle::getBody ( )
inlineoverridevirtual

Returns a (weak) reference to Box2D body for this obstacle.

You use this body to add joints and apply forces. As a weak reference, this physics obstacle does not transfer ownership of this body. In addition, the value may be a nullptr.

Returns
a (weak) reference to Box2D body for this obstacle.

Reimplemented from cugl::physics2::Obstacle.

◆ getBodyType()

virtual b2BodyType cugl::physics2::SimpleObstacle::getBodyType ( ) const
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.

Returns
the body type for Box2D physics

Reimplemented from cugl::physics2::Obstacle.

◆ getCentroid()

virtual Vec2 cugl::physics2::SimpleObstacle::getCentroid ( ) const
inlineoverridevirtual

Returns the center of mass of this body

This method converts from a Box2D vector type to a CUGL 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 from cugl::physics2::Obstacle.

◆ getGravityScale()

virtual float cugl::physics2::SimpleObstacle::getGravityScale ( ) const
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.

Returns
the gravity scale to apply to this body

Reimplemented from cugl::physics2::Obstacle.

◆ getInertia()

virtual float cugl::physics2::SimpleObstacle::getInertia ( ) const
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.

Returns
the rotational inertia of this body

Reimplemented from cugl::physics2::Obstacle.

◆ getLinearDamping()

virtual float cugl::physics2::SimpleObstacle::getLinearDamping ( ) const
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.

Returns
the linear damping for this body.

Reimplemented from cugl::physics2::Obstacle.

◆ getLinearVelocity()

virtual Vec2 cugl::physics2::SimpleObstacle::getLinearVelocity ( ) const
inlineoverridevirtual

Returns the linear velocity for this physics body

This method converts from a Box2D vector type to a CUGL 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 from cugl::physics2::Obstacle.

◆ getMass()

virtual float cugl::physics2::SimpleObstacle::getMass ( ) const
inlineoverridevirtual

Returns the mass of this body

The value is usually in kilograms.

Returns
the mass of this body

Reimplemented from cugl::physics2::Obstacle.

◆ getPosition()

virtual Vec2 cugl::physics2::SimpleObstacle::getPosition ( ) const
inlineoverridevirtual

Returns the current position for this physics body

This method converts from a Box2D vector type to a CUGL 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 from cugl::physics2::Obstacle.

◆ getPositionSnap()

int cugl::physics2::SimpleObstacle::getPositionSnap ( )
inline

Returns the number of decimal places to snap the node to the 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, CUGL will round the position of the node 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.

Returns
the number of decimal places to snap the node to the physics body

◆ getVX()

virtual float cugl::physics2::SimpleObstacle::getVX ( ) const
inlineoverridevirtual

Returns the x-velocity for this physics body

Returns
the x-velocity for this physics body

Reimplemented from cugl::physics2::Obstacle.

◆ getVY()

virtual float cugl::physics2::SimpleObstacle::getVY ( ) const
inlineoverridevirtual

Returns the y-velocity for this physics body

Returns
the y-velocity for this physics body

Reimplemented from cugl::physics2::Obstacle.

◆ getX()

virtual float cugl::physics2::SimpleObstacle::getX ( ) const
inlineoverridevirtual

Returns the x-coordinate for this physics body

Returns
the x-coordinate for this physics body

Reimplemented from cugl::physics2::Obstacle.

◆ getY()

virtual float cugl::physics2::SimpleObstacle::getY ( ) const
inlineoverridevirtual

Returns the x-coordinate for this physics body

Returns
the x-coordinate for this physics body

Reimplemented from cugl::physics2::Obstacle.

◆ isAwake()

virtual bool cugl::physics2::SimpleObstacle::isAwake ( ) const
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.

Returns
true if the body is awake

Reimplemented from cugl::physics2::Obstacle.

◆ isBullet()

virtual bool cugl::physics2::SimpleObstacle::isBullet ( ) const
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.

Returns
true if this body is a bullet

Reimplemented from cugl::physics2::Obstacle.

◆ isEnabled()

virtual bool cugl::physics2::SimpleObstacle::isEnabled ( ) const
inlineoverridevirtual

Returns true if the body is enabled

A disabled 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 activenablede

Reimplemented from cugl::physics2::Obstacle.

◆ isFixedRotation()

virtual bool cugl::physics2::SimpleObstacle::isFixedRotation ( ) const
inlineoverridevirtual

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

◆ isSleepingAllowed()

virtual bool cugl::physics2::SimpleObstacle::isSleepingAllowed ( ) const
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.

Returns
false if this body should never fall asleep

Reimplemented from cugl::physics2::Obstacle.

◆ releaseFixtures()

virtual void cugl::physics2::SimpleObstacle::releaseFixtures ( )
inlinevirtual

Release the fixtures for this body, reseting the shape

This is the primary method to override for custom physics objects.

Reimplemented in cugl::physics2::CapsuleObstacle, cugl::physics2::PolygonObstacle, cugl::physics2::BoxObstacle, and cugl::physics2::WheelObstacle.

◆ resetMass()

virtual void cugl::physics2::SimpleObstacle::resetMass ( )
inlineoverridevirtual

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

Reimplemented from cugl::physics2::Obstacle.

◆ setAngle()

virtual void cugl::physics2::SimpleObstacle::setAngle ( float  value)
inlineoverridevirtual

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

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

Reimplemented from cugl::physics2::Obstacle.

◆ setAngleSnap()

void cugl::physics2::SimpleObstacle::setAngleSnap ( unsigned int  snap)
inline

Sets the number of decimal places to snap rotation to the 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, CUGL 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.

Parameters
snapthe number of decimal places to snap rotation to the physics body

◆ setAngularDamping()

virtual void cugl::physics2::SimpleObstacle::setAngularDamping ( float  value)
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.

Parameters
valuethe angular damping for this body.

Reimplemented from cugl::physics2::Obstacle.

◆ setAngularVelocity()

virtual void cugl::physics2::SimpleObstacle::setAngularVelocity ( float  value)
inlineoverridevirtual

Sets the angular velocity for this physics body

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

Reimplemented from cugl::physics2::Obstacle.

◆ setAwake()

virtual void cugl::physics2::SimpleObstacle::setAwake ( bool  value)
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.

Parameters
valuewhether the body is awake

Reimplemented from cugl::physics2::Obstacle.

◆ setBodyType()

virtual void cugl::physics2::SimpleObstacle::setBodyType ( b2BodyType  value)
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.

Parameters
valuethe body type for Box2D physics

Reimplemented from cugl::physics2::Obstacle.

◆ setBullet()

virtual void cugl::physics2::SimpleObstacle::setBullet ( bool  value)
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.

Parameters
valuewhether this body is a bullet

Reimplemented from cugl::physics2::Obstacle.

◆ setCentroid() [1/2]

virtual void cugl::physics2::SimpleObstacle::setCentroid ( const Vec2  value)
inlineoverridevirtual

Sets the center of mass for this physics body

This method converts from a CUGL 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 from cugl::physics2::Obstacle.

◆ setCentroid() [2/2]

virtual void cugl::physics2::SimpleObstacle::setCentroid ( float  x,
float  y 
)
inlineoverridevirtual

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

◆ setDensity()

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

Reimplemented in cugl::physics2::CapsuleObstacle.

◆ setEnabled()

virtual void cugl::physics2::SimpleObstacle::setEnabled ( bool  value)
inlineoverridevirtual

Sets whether the body is enabled

An disabled 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 enabled

Reimplemented from cugl::physics2::Obstacle.

◆ setFilterData()

virtual void cugl::physics2::SimpleObstacle::setFilterData ( b2Filter  value)
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.

Parameters
valuethe filter data for this object

Reimplemented from cugl::physics2::Obstacle.

◆ setFixedRotation()

virtual void cugl::physics2::SimpleObstacle::setFixedRotation ( bool  value)
inlineoverridevirtual

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

◆ setFriction()

virtual void cugl::physics2::SimpleObstacle::setFriction ( float  value)
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.

Parameters
valuethe friction coefficient of this body

Reimplemented from cugl::physics2::Obstacle.

◆ setGravityScale()

virtual void cugl::physics2::SimpleObstacle::setGravityScale ( float  value)
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.

Parameters
valuethe gravity scale to apply to this body

Reimplemented from cugl::physics2::Obstacle.

◆ setInertia()

virtual void cugl::physics2::SimpleObstacle::setInertia ( float  value)
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.

Parameters
valuethe rotational inertia of this body

Reimplemented from cugl::physics2::Obstacle.

◆ setLinearDamping()

virtual void cugl::physics2::SimpleObstacle::setLinearDamping ( float  value)
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.

Parameters
valuethe linear damping for this body.

Reimplemented from cugl::physics2::Obstacle.

◆ setLinearVelocity() [1/2]

virtual void cugl::physics2::SimpleObstacle::setLinearVelocity ( const Vec2  value)
inlineoverridevirtual

Sets the linear velocity for this physics body

This method converts from a CUGL 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 from cugl::physics2::Obstacle.

◆ setLinearVelocity() [2/2]

virtual void cugl::physics2::SimpleObstacle::setLinearVelocity ( float  x,
float  y 
)
inlineoverridevirtual

Sets the linear velocity for this physics body

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

Reimplemented from cugl::physics2::Obstacle.

◆ setMass()

virtual void cugl::physics2::SimpleObstacle::setMass ( float  value)
inlineoverridevirtual

Sets the mass of this body

The value is usually in kilograms.

Parameters
valuethe mass of this body

Reimplemented from cugl::physics2::Obstacle.

◆ setPosition() [1/2]

virtual void cugl::physics2::SimpleObstacle::setPosition ( const Vec2  value)
inlineoverridevirtual

Sets the current position for this physics body

This method converts from a CUGL 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 from cugl::physics2::Obstacle.

◆ setPosition() [2/2]

virtual void cugl::physics2::SimpleObstacle::setPosition ( float  x,
float  y 
)
inlineoverridevirtual

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

◆ setPositionSnap()

void cugl::physics2::SimpleObstacle::setPositionSnap ( unsigned int  snap)
inline

Sets the number of decimal places to snap the node to the 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, CUGL will round the position of the node 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.

Parameters
snapthe number of decimal places to snap the node to the physics body

◆ setRestitution()

virtual void cugl::physics2::SimpleObstacle::setRestitution ( float  value)
overridevirtual

Sets the restitution 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 restitution of this body

Reimplemented from cugl::physics2::Obstacle.

◆ setSensor()

virtual void cugl::physics2::SimpleObstacle::setSensor ( bool  value)
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.

Parameters
valuewhether this object is a sensor.

Reimplemented from cugl::physics2::Obstacle.

◆ setSleepingAllowed()

virtual void cugl::physics2::SimpleObstacle::setSleepingAllowed ( bool  value)
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.

Parameters
valuewhether the body should ever fall asleep

Reimplemented from cugl::physics2::Obstacle.

◆ setVX()

virtual void cugl::physics2::SimpleObstacle::setVX ( float  value)
inlineoverridevirtual

Sets the x-velocity for this physics body

Parameters
valuethe x-velocity for this physics body

Reimplemented from cugl::physics2::Obstacle.

◆ setVY()

virtual void cugl::physics2::SimpleObstacle::setVY ( float  value)
inlineoverridevirtual

Sets the y-velocity for this physics body

Parameters
valuethe y-velocity for this physics body

Reimplemented from cugl::physics2::Obstacle.

◆ setX()

virtual void cugl::physics2::SimpleObstacle::setX ( float  value)
inlineoverridevirtual

Sets the x-coordinate for this physics body

Parameters
valuethe x-coordinate for this physics body

Reimplemented from cugl::physics2::Obstacle.

◆ setY()

virtual void cugl::physics2::SimpleObstacle::setY ( float  value)
inlineoverridevirtual

Sets the y-coordinate for this physics body

Parameters
valuethe y-coordinate for this physics body

Reimplemented from cugl::physics2::Obstacle.

◆ update()

virtual void cugl::physics2::SimpleObstacle::update ( float  delta)
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.

Parameters
deltaTiming values from parent loop

Reimplemented from cugl::physics2::Obstacle.

◆ updateDebug()

virtual void cugl::physics2::SimpleObstacle::updateDebug ( )
overrideprotectedvirtual

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

The debug wireframe 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.

Member Data Documentation

◆ _angFact

unsigned long cugl::physics2::SimpleObstacle::_angFact
protected

Cache of factor to snap rotation of image to physics body

◆ _angSnap

int cugl::physics2::SimpleObstacle::_angSnap
protected

Number of decimal places to snap rotation of image to physics body

◆ _body

b2Body* cugl::physics2::SimpleObstacle::_body
protected

The physics body for Box2D.

◆ _posFact

unsigned long cugl::physics2::SimpleObstacle::_posFact
protected

Cache of factor to snap position of image to physics body

◆ _posSnap

int cugl::physics2::SimpleObstacle::_posSnap
protected

Number of decimal places to snap position of image to physics body


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