CUGL 2.1
Cornell University Game Library
|
#include <CUObstacle.h>
Public Member Functions | |
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::SceneNode * | getDebugScene () const |
scene2::WireNode * | getDebugNode () const |
virtual void | setDebugScene (const std::shared_ptr< scene2::SceneNode > &node) |
bool | hasDebug () |
Protected Member Functions | |
virtual void | resetDebug () |
virtual void | updateDebug () |
Protected Attributes | |
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 |
Friends | |
std::ostream & | operator<< (std::ostream &os, const Obstacle &obj) |
Base model class to support collisions.
Instances represents a body and/or a group of bodies. There should be NO game controlling logic code in a physics objects. That should reside in the Controllers.
This abstract class has no Body or Shape information and should never be instantiated directly. Instead, you should instantiate either SimpleObstacle or ComplexObstacle. This class only exists to unify common functionality. In particular, it wraps the body and and fixture information into a single interface.
Many of the method comments in this class are taken from the Box2d manual by Erin Catto (2011).
cugl::physics2::Obstacle::Obstacle | ( | void | ) |
Creates a new 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).
|
virtual |
Deletes this physics object and all of its resources.
We have to make the destructor public so that we can polymorphically delete physics objects.
A non-default destructor is necessary since we must release all claims on scene graph nodes.
|
inlinevirtual |
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.
world | Box2D world to store body |
Reimplemented in cugl::physics2::ComplexObstacle, and cugl::physics2::SimpleObstacle.
|
inlinevirtual |
Destroys the physics Body(s) of this object if applicable.
This removes the body from the Box2D world.
world | Box2D world that stores body |
Reimplemented in cugl::physics2::ComplexObstacle, and cugl::physics2::SimpleObstacle.
|
inlinevirtual |
Returns the angle of rotation for this body (about the center).
The value returned is in radians
Reimplemented in cugl::physics2::ComplexObstacle, and cugl::physics2::SimpleObstacle.
|
inlinevirtual |
Returns the angular damping for this body.
Angular damping is use to reduce the angular velocity. Damping is different than friction because friction only occurs with contact. Damping is not a replacement for friction and the two effects should be used together.
Damping parameters should be between 0 and infinity, with 0 meaning no damping, and infinity meaning full damping. Normally you will use a damping value between 0 and 0.1.
Reimplemented in cugl::physics2::ComplexObstacle, and cugl::physics2::SimpleObstacle.
|
inlinevirtual |
Returns the angular velocity for this physics body
The rate of change is measured in radians per step
Reimplemented in cugl::physics2::ComplexObstacle, and cugl::physics2::SimpleObstacle.
|
inlinevirtual |
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.
Reimplemented in cugl::physics2::ComplexObstacle, and cugl::physics2::SimpleObstacle.
|
inlinevirtual |
Returns the body type for Box2D physics
If you want to lock a body in place (e.g. a platform) set this value to STATIC. KINEMATIC allows the object to move (and some limited collisions), but ignores external forces (e.g. gravity). DYNAMIC makes this is a full-blown physics object.
Reimplemented in cugl::physics2::ComplexObstacle, and cugl::physics2::SimpleObstacle.
|
inlinevirtual |
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.
Reimplemented in cugl::physics2::ComplexObstacle, and cugl::physics2::SimpleObstacle.
|
inline |
Returns the color of the debug wireframe.
The default color is white, which means that the objects will be shown with a white wireframe.
|
inline |
Returns the scene graph node for the debug wireframe
The returned node draws a wireframe of the physics body. The wireframe consists of the physics fixtures adjusted by the drawing scale. The debug node is positioned in the coordinate space of the parent scene.
The wireframe will be drawn using physics coordinates, which is possibly much smaller than your drawing coordinates (e.g. 1 Box2D unit = 1 pixel). If you want the wireframes to be larger, you should scale the parent parent coordinate space to match the rest of the application.
This scene graph node is intended for debugging purposes only. If you want a physics body to update a proper texture image, you should either use the method update(float) for subclasses or setListener for decoupled classes.
|
inline |
Returns the parent scene graph node for the debug wireframe
The returned node is the parent coordinate space for drawing physics. All debug nodes for physics objects are drawn within this coordinate space. Setting the visibility of this node to false will disable any debugging.
The wireframe will be drawn using physics coordinates, which is possibly much smaller than your drawing coordinates (e.g. 1 Box2D unit = 1 pixel). If you want the wireframes to be larger, you should scale the parent parent coordinate space to match the rest of the application.
This scene graph node is intended for debugging purposes only. If you want a physics body to update a proper texture image, you should either use the method update(float) for subclasses or setListener for decoupled classes.
|
inline |
Returns the density of this body
The density is typically measured in usually in kg/m^2. The density can be zero or positive. You should generally use similar densities for all your fixtures. This will improve stacking stability.
|
inline |
Returns the filter data for this object (or null if there is none)
Collision filtering allows you to prevent collision between fixtures. For example, say you make a character that rides a bicycle. You want the bicycle to collide with the terrain and the character to collide with the terrain, but you don't want the character to collide with the bicycle (because they must overlap). Box2D supports such collision filtering using categories and groups.
|
inline |
Returns the friction coefficient of this body
The friction parameter is usually set between 0 and 1, but can be any non-negative value. A friction value of 0 turns off friction and a value of 1 makes the friction strong. When the friction force is computed between two shapes, Box2D must combine the friction parameters of the two parent fixtures. This is done with the geometric mean.
|
inlinevirtual |
Returns the gravity scale to apply to this body
This allows isolated objects to float. Be careful with this, since increased gravity can decrease stability.
Reimplemented in cugl::physics2::ComplexObstacle, and cugl::physics2::SimpleObstacle.
|
inlinevirtual |
Returns the rotational inertia of this body
For static bodies, the mass and rotational inertia are set to zero. When a body has fixed rotation, its rotational inertia is zero.
Reimplemented in cugl::physics2::ComplexObstacle, and cugl::physics2::SimpleObstacle.
|
inlinevirtual |
Returns the linear damping for this body.
Linear damping is use to reduce the linear velocity. Damping is different than friction because friction only occurs with contact. Damping is not a replacement for friction and the two effects should be used together.
Damping parameters should be between 0 and infinity, with 0 meaning no damping, and infinity meaning full damping. Normally you will use a damping value between 0 and 0.1. Most people avoid linear damping because it makes bodies look floaty.
Reimplemented in cugl::physics2::ComplexObstacle, and cugl::physics2::SimpleObstacle.
|
inlinevirtual |
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.
Reimplemented in cugl::physics2::ComplexObstacle, and cugl::physics2::SimpleObstacle.
|
inline |
Returns the active listener to this object.
Listeners are called after every physics update, to notify them of any changes in this object state. For performance reasons, a physics obstacle can have only one listener. If you need multiple objects listening to a single physics obstacle, the listener should handle the dispatch to other objects.
|
inlinevirtual |
Returns the mass of this body
The value is usually in kilograms.
Reimplemented in cugl::physics2::ComplexObstacle, and cugl::physics2::SimpleObstacle.
|
inline |
Returns the physics object tag.
A tag is a string attached to an object, in order to identify it in debugging.
|
inlinevirtual |
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 obstacle.
Reimplemented in cugl::physics2::ComplexObstacle, and cugl::physics2::SimpleObstacle.
|
inline |
Returns the restitution of this body
Restitution is used to make objects bounce. The restitution value is usually set to be between 0 and 1. Consider dropping a ball on a table. A value of zero means the ball won't bounce. This is called an inelastic collision. A value of one means the ball's velocity will be exactly reflected. This is called a perfectly elastic collision.
|
inlinevirtual |
Returns the x-velocity for this physics body
Reimplemented in cugl::physics2::ComplexObstacle, and cugl::physics2::SimpleObstacle.
|
inlinevirtual |
Returns the y-velocity for this physics body
Reimplemented in cugl::physics2::ComplexObstacle, and cugl::physics2::SimpleObstacle.
|
inlinevirtual |
Returns the x-coordinate for this physics body
Reimplemented in cugl::physics2::ComplexObstacle, and cugl::physics2::SimpleObstacle.
|
inlinevirtual |
Returns the y-coordinate for this physics body
Reimplemented in cugl::physics2::ComplexObstacle, and cugl::physics2::SimpleObstacle.
|
inline |
Returns true if the obstacle has a wireframe for debugging.
This method will return false if there is no active parent scene for the wireframe.
|
inlinevirtual |
Initializes a new physics object at the origin.
Reimplemented in cugl::physics2::CapsuleObstacle, cugl::physics2::BoxObstacle, and cugl::physics2::WheelObstacle.
|
virtual |
Initializes a new physics object at the given point
vec | Initial position in world coordinates |
Reimplemented in cugl::physics2::CapsuleObstacle, cugl::physics2::BoxObstacle, and cugl::physics2::WheelObstacle.
|
inlinevirtual |
Returns true if the body is awake
An sleeping body is one that has come to rest and the physics engine has decided to stop simulating it to save CPU cycles. If a body is awake and collides with a sleeping body, then the sleeping body wakes up. Bodies will also wake up if a joint or contact attached to them is destroyed.
You can also wake a body manually.
Reimplemented in cugl::physics2::ComplexObstacle, and cugl::physics2::SimpleObstacle.
|
inlinevirtual |
Returns true if this body is a bullet
By default, Box2D uses continuous collision detection (CCD) to prevent dynamic bodies from tunneling through static bodies. Normally CCD is not used between dynamic bodies. This is done to keep performance reasonable. In some game scenarios you need dynamic bodies to use CCD. For example, you may want to shoot a high speed bullet at a stack of dynamic bricks. Without CCD, the bullet might tunnel through the bricks.
Fast moving objects in Box2D can be labeled as bullets. Bullets will perform CCD with both static and dynamic bodies. You should decide what bodies should be bullets based on your game design.
Reimplemented in cugl::physics2::ComplexObstacle, and cugl::physics2::SimpleObstacle.
|
inline |
Returns true if the shape information must be updated.
Attributes tied to the geometry (and not just forces/position) must wait for collisions to complete before they are reset. Shapes (and their properties) are reset in the update method.
|
inlinevirtual |
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.
Reimplemented in cugl::physics2::ComplexObstacle, and cugl::physics2::SimpleObstacle.
|
inlinevirtual |
Returns true if this body be prevented from rotating
This is very useful for characters that should remain upright.
Reimplemented in cugl::physics2::ComplexObstacle, and cugl::physics2::SimpleObstacle.
|
inline |
Returns true if our object has been flagged for garbage collection
A garbage collected object will be removed from the physics world at the next time step.
|
inline |
Returns true if this object is a sensor.
Sometimes game logic needs to know when two entities overlap yet there should be no collision response. This is done by using sensors. A sensor is an entity that detects collision but does not produce a response.
|
inlinevirtual |
Returns false if this body should never fall asleep
An sleeping body is one that has come to rest and the physics engine has decided to stop simulating it to save CPU cycles. If a body is awake and collides with a sleeping body, then the sleeping body wakes up. Bodies will also wake up if a joint or contact attached to them is destroyed. You can also wake a body manually.
Reimplemented in cugl::physics2::ComplexObstacle, and cugl::physics2::SimpleObstacle.
|
inline |
Sets whether the shape information must be updated.
Attributes tied to the geometry (and not just forces/position) must wait for collisions to complete before they are reset. Shapes (and their properties) are reset in the update method.
value | whether the shape information must be updated. |
|
inline |
Sets whether our object has been flagged for garbage collection
A garbage collected object will be removed from the physics world at the next time step.
value | whether our object has been flagged for garbage collection |
|
inlineprotectedvirtual |
Creates the outline of the physics fixtures in the debug wireframe
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 in cugl::physics2::CapsuleObstacle, cugl::physics2::ComplexObstacle, cugl::physics2::PolygonObstacle, cugl::physics2::BoxObstacle, and cugl::physics2::WheelObstacle.
|
inlinevirtual |
Resets this body to use the mass computed from the its shape and density
Reimplemented in cugl::physics2::ComplexObstacle, and cugl::physics2::SimpleObstacle.
|
inlinevirtual |
Sets the angle of rotation for this body (about the center).
value | the angle of rotation for this body (in radians) |
Reimplemented in cugl::physics2::ComplexObstacle, and cugl::physics2::SimpleObstacle.
|
inlinevirtual |
Sets the angular damping for this body.
Angular damping is use to reduce the angular velocity. Damping is different than friction because friction only occurs with contact. Damping is not a replacement for friction and the two effects should be used together.
Damping parameters should be between 0 and infinity, with 0 meaning no damping, and infinity meaning full damping. Normally you will use a damping value between 0 and 0.1.
value | the angular damping for this body. |
Reimplemented in cugl::physics2::ComplexObstacle, and cugl::physics2::SimpleObstacle.
|
inlinevirtual |
Sets the angular velocity for this physics body
value | the angular velocity for this physics body (in radians) |
Reimplemented in cugl::physics2::ComplexObstacle, and cugl::physics2::SimpleObstacle.
|
inlinevirtual |
Sets whether the body is awake
An sleeping body is one that has come to rest and the physics engine has decided to stop simulating it to save CPU cycles. If a body is awake and collides with a sleeping body, then the sleeping body wakes up. Bodies will also wake up if a joint or contact attached to them is destroyed. You can also wake a body manually.
value | whether the body is awake |
Reimplemented in cugl::physics2::ComplexObstacle, and cugl::physics2::SimpleObstacle.
void cugl::physics2::Obstacle::setBodyState | ( | const b2Body & | body | ) |
Copies the state from the given body to the body def.
This is important if you want to save the state of the body before removing it from the world.
|
inlinevirtual |
Sets the body type for Box2D physics
If you want to lock a body in place (e.g. a platform) set this value to STATIC. KINEMATIC allows the object to move (and some limited collisions), but ignores external forces (e.g. gravity). DYNAMIC makes this is a full-blown physics object.
value | the body type for Box2D physics |
Reimplemented in cugl::physics2::ComplexObstacle, and cugl::physics2::SimpleObstacle.
|
inlinevirtual |
Sets whether this body is a bullet
By default, Box2D uses continuous collision detection (CCD) to prevent dynamic bodies from tunneling through static bodies. Normally CCD is not used between dynamic bodies. This is done to keep performance reasonable. In some game scenarios you need dynamic bodies to use CCD. For example, you may want to shoot a high speed bullet at a stack of dynamic bricks. Without CCD, the bullet might tunnel through the bricks.
Fast moving objects in Box2D can be labeled as bullets. Bullets will perform CCD with both static and dynamic bodies. You should decide what bodies should be bullets based on your game design.
value | whether this body is a bullet |
Reimplemented in cugl::physics2::ComplexObstacle, and cugl::physics2::SimpleObstacle.
|
inlinevirtual |
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.
value | the center of mass for this physics body |
Reimplemented in cugl::physics2::ComplexObstacle, and cugl::physics2::SimpleObstacle.
|
virtual |
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 in cugl::physics2::ComplexObstacle, and cugl::physics2::SimpleObstacle.
|
virtual |
Sets the color of the debug wireframe.
The default color is white, which means that the objects will be shown with a white wireframe.
color | the color of the debug wireframe. |
Reimplemented in cugl::physics2::ComplexObstacle.
|
virtual |
Sets the parent scene graph node for the debug wireframe
The given node is the parent coordinate space for drawing physics. All debug nodes for physics objects are drawn within this coordinate space. Setting the visibility of this node to false will disable any debugging. Similarly, setting this value to nullptr will disable any debugging.
The wireframe will be drawn using physics coordinates, which is possibly much smaller than your drawing coordinates (e.g. 1 Box2D unit = 1 pixel). If you want the wireframes to be larger, you should scale the parent parent coordinate space to match the rest of the application.
This scene graph node is intended for debugging purposes only. If you want a physics body to update a proper texture image, you should either use the method update(float) for subclasses or setListener for decoupled classes.
node | he parent scene graph node for the debug wireframe |
Reimplemented in cugl::physics2::ComplexObstacle.
|
inlinevirtual |
Sets the density of this body
The density is typically measured in usually in kg/m^2. The density can be zero or positive. You should generally use similar densities for all your fixtures. This will improve stacking stability.
value | the density of this body |
Reimplemented in cugl::physics2::ComplexObstacle, cugl::physics2::SimpleObstacle, and cugl::physics2::CapsuleObstacle.
|
inlinevirtual |
Sets whether 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.
value | whether the body is enabled |
Reimplemented in cugl::physics2::ComplexObstacle, and cugl::physics2::SimpleObstacle.
|
inlinevirtual |
Sets the filter data for this object
Collision filtering allows you to prevent collision between fixtures. For example, say you make a character that rides a bicycle. You want the bicycle to collide with the terrain and the character to collide with the terrain, but you don't want the character to collide with the bicycle (because they must overlap). Box2D supports such collision filtering using categories and groups.
A value of null removes all collision filters.
value | the filter data for this object |
Reimplemented in cugl::physics2::ComplexObstacle, and cugl::physics2::SimpleObstacle.
|
inlinevirtual |
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 in cugl::physics2::ComplexObstacle, and cugl::physics2::SimpleObstacle.
|
inlinevirtual |
Sets the friction coefficient of this body
The friction parameter is usually set between 0 and 1, but can be any non-negative value. A friction value of 0 turns off friction and a value of 1 makes the friction strong. When the friction force is computed between two shapes, Box2D must combine the friction parameters of the two parent fixtures. This is done with the geometric mean.
value | the friction coefficient of this body |
Reimplemented in cugl::physics2::ComplexObstacle, and cugl::physics2::SimpleObstacle.
|
inlinevirtual |
Sets the gravity scale to apply to this body
This allows isolated objects to float. Be careful with this, since increased gravity can decrease stability.
value | the gravity scale to apply to this body |
Reimplemented in cugl::physics2::ComplexObstacle, and cugl::physics2::SimpleObstacle.
|
virtual |
Sets the rotational inertia of this body
For static bodies, the mass and rotational inertia are set to zero. When a body has fixed rotation, its rotational inertia is zero.
value | the rotational inertia of this body |
Reimplemented in cugl::physics2::ComplexObstacle, and cugl::physics2::SimpleObstacle.
|
inlinevirtual |
Sets the linear damping for this body.
Linear damping is use to reduce the linear velocity. Damping is different than friction because friction only occurs with contact. Damping is not a replacement for friction and the two effects should be used together.
Damping parameters should be between 0 and infinity, with 0 meaning no damping, and infinity meaning full damping. Normally you will use a damping value between 0 and 0.1. Most people avoid linear damping because it makes bodies look floaty.
value | the linear damping for this body. |
Reimplemented in cugl::physics2::ComplexObstacle, and cugl::physics2::SimpleObstacle.
|
inlinevirtual |
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.
value | the linear velocity for this physics body |
Reimplemented in cugl::physics2::ComplexObstacle, and cugl::physics2::SimpleObstacle.
|
inlinevirtual |
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 in cugl::physics2::ComplexObstacle, and cugl::physics2::SimpleObstacle.
|
inline |
Sets the active listener to this object.
Listeners are called after every physics update, to notify them of any changes in this object state. For performance reasons, a physics obstacle can have only one listener. If you need multiple objects listening to a single physics obstacle, the listener should handle the dispatch to other objects.
listener | the active listener to this object. |
|
virtual |
Sets the mass of this body
The value is usually in kilograms.
value | the mass of this body |
Reimplemented in cugl::physics2::ComplexObstacle, and cugl::physics2::SimpleObstacle.
|
inline |
Sets the physics object tag.
A tag is a string attached to an object, in order to identify it in debugging.
value | the physics object tag |
|
inlinevirtual |
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.
value | the current position for this physics body |
Reimplemented in cugl::physics2::ComplexObstacle, and cugl::physics2::SimpleObstacle.
|
inlinevirtual |
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 in cugl::physics2::ComplexObstacle, and cugl::physics2::SimpleObstacle.
|
inlinevirtual |
Sets the restitution of this body
Restitution is used to make objects bounce. The restitution value is usually set to be between 0 and 1. Consider dropping a ball on a table. A value of zero means the ball won't bounce. This is called an inelastic collision. A value of one means the ball's velocity will be exactly reflected. This is called a perfectly elastic collision.
value | the restitution of this body |
Reimplemented in cugl::physics2::ComplexObstacle, and cugl::physics2::SimpleObstacle.
|
inlinevirtual |
Sets whether this object is a sensor.
Sometimes game logic needs to know when two entities overlap yet there should be no collision response. This is done by using sensors. A sensor is an entity that detects collision but does not produce a response.
value | whether this object is a sensor. |
Reimplemented in cugl::physics2::ComplexObstacle, and cugl::physics2::SimpleObstacle.
|
inlinevirtual |
Sets whether the body should ever fall asleep
An sleeping body is one that has come to rest and the physics engine has decided to stop simulating it to save CPU cycles. If a body is awake and collides with a sleeping body, then the sleeping body wakes up. Bodies will also wake up if a joint or contact attached to them is destroyed. You can also wake a body manually.
value | whether the body should ever fall asleep |
Reimplemented in cugl::physics2::ComplexObstacle, and cugl::physics2::SimpleObstacle.
|
inlinevirtual |
Sets the x-velocity for this physics body
value | the x-velocity for this physics body |
Reimplemented in cugl::physics2::ComplexObstacle, and cugl::physics2::SimpleObstacle.
|
inlinevirtual |
Sets the y-velocity for this physics body
value | the y-velocity for this physics body |
Reimplemented in cugl::physics2::ComplexObstacle, and cugl::physics2::SimpleObstacle.
|
inlinevirtual |
Sets the x-coordinate for this physics body
value | the x-coordinate for this physics body |
Reimplemented in cugl::physics2::ComplexObstacle, and cugl::physics2::SimpleObstacle.
|
inlinevirtual |
Sets the y-coordinate for this physics body
value | the y-coordinate for this physics body |
Reimplemented in cugl::physics2::ComplexObstacle, and cugl::physics2::SimpleObstacle.
std::string cugl::physics2::Obstacle::toString | ( | ) | const |
Returns a string representation of this physics object.
This method converts the physics object into a string for debugging. By default it shows the tag and position. Other physics objects may want to override this method for more detailed information.
|
inlinevirtual |
Updates the object's physics state (NOT GAME LOGIC).
This method is called AFTER the collision resolution state. Therefore, it should not be used to process actions or any other gameplay information.
Its primary purpose is to adjust changes to the fixture, which have to take place after collision.
In other words, this is the method that updates the scene graph. If you forget to call it, it will not draw your changes.
delta | Timing values from parent loop |
Reimplemented in cugl::physics2::ComplexObstacle, and cugl::physics2::SimpleObstacle.
|
protectedvirtual |
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 in cugl::physics2::SimpleObstacle, and cugl::physics2::ComplexObstacle.
|
friend |
Outputs this physics object to the given output stream.
This function uses the toString() method to convert the physics object into a string
os | the output stream |
obj | the physics object to ouput |
|
protected |
Stores the body information for this shape
|
protected |
The wireframe color for debugging
|
protected |
The wireframe node for debugging.
|
protected |
Stores the fixture information for this shape
|
protected |
(Singular) callback function for state updates
|
protected |
The mass data of this shape (which may override the fixture)
|
protected |
Whether or not to use the custom mass data
|
protected |
The wireframe parent for debugging.
|
protected |
A tag for debugging purposes