CUGL 2.5
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) |
void | setShared (bool shared) |
bool | isShared () const |
void | clearSharingDirtyBits () |
bool | hasDirtyType () const |
bool | hasDirtyPosition () const |
bool | hasDirtyVelocity () const |
bool | hasDirtyAngle () const |
bool | hasDirtyAngularVelocity () const |
bool | hasDirtyBool () const |
bool | hasDirtyFloat () const |
virtual b2Body * | getBody () |
virtual bool | activatePhysics (b2World &world) |
virtual void | deactivatePhysics (b2World &world) |
virtual void | createFixtures () |
virtual void | releaseFixtures () |
virtual void | update (float delta) |
const std::function< void(Obstacle *obstacle)> & | getListener () const |
void | setListener (const std::function< void(Obstacle *obstacle)> &listener) |
int | getPositionSnap () |
void | setPositionSnap (unsigned int snap) |
int | getAngleSnap () |
void | setAngleSnap (unsigned int snap) |
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 |
b2Body * | _body |
int | _posSnap |
unsigned long | _posFact |
int | _angSnap |
unsigned long | _angFact |
bool | _shared |
Friends | |
std::ostream & | operator<< (std::ostream &os, const Obstacle &obj) |
Base model class to support collisions.
Instances of this class represent a body. There should be NO game controlling logic code in a physics objects. That should reside in the Controllers.
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.
In addition to combining body and fixture information, this class provides some basic primitives for synchronizing bodies between multiple physics worlds. See setShared
.
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. Note that we do not allow an obstacle to be deleted while physics is still active. Doing so will result in an error.
A non-default destructor is necessary since we must release all claims on scene graph nodes.
|
virtual |
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 |
|
inline |
Clears all of the bits tracking the shared state.
This is done after a physics object has been synchronized across the appropriate worlds.
|
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::BoxObstacle, cugl::physics2::CapsuleObstacle, cugl::physics2::PolygonObstacle, and cugl::physics2::WheelObstacle.
|
virtual |
Destroys the physics Body(s) of this object if applicable.
This removes the body from the Box2D world.
world | Box2D world that stores body |
|
inlinevirtual |
Returns the angle of rotation for this body (about the center).
The value returned is in radians
|
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.
|
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.
|
inlinevirtual |
Returns the angular velocity for this physics body
The rate of change is measured in radians per step
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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
|
inlinevirtual |
Returns the y-velocity for this physics body
|
inlinevirtual |
Returns the x-coordinate for this physics body
|
inlinevirtual |
Returns the y-coordinate for this physics body
|
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.
|
inline |
Returns true if the angle of this obstacle is dirty
This happens if the angle is modified outside of the physics simulation.
|
inline |
Returns true if the angular velocity of this obstacle is dirty
This happens if the angular velocity is modified outside of the physics simulation.
|
inline |
Returns true if any boolean attribute of this obstacle is dirty
This happens if the attribute is modified outside of the physics simulation.
|
inline |
Returns true if any float attribute of this obstacle is dirty
This happens if the attribute is modified outside of the physics simulation.
|
inline |
Returns true if the positional data of this obstacle is dirty
This happens if the position is modified outside of the physics simulation.
|
inline |
Returns true if the body type of this obstacle is dirty
This happens if the body type is modified outside of the physics simulation.
|
inline |
Returns true if the velocity data of this obstacle is dirty
This happens if the velocity is modified outside of the physics simulation.
|
inlinevirtual |
Initializes a new physics object at the origin.
Reimplemented in cugl::physics2::PolygonObstacle, cugl::physics2::BoxObstacle, cugl::physics2::CapsuleObstacle, and cugl::physics2::WheelObstacle.
|
virtual |
Initializes a new physics object at the given point
vec | Initial position in world coordinates |
Reimplemented in cugl::physics2::BoxObstacle, cugl::physics2::CapsuleObstacle, cugl::physics2::WheelObstacle, and cugl::physics2::PolygonObstacle.
|
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.
|
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.
|
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.
|
inlinevirtual |
Returns true if this body be prevented from rotating
This is very useful for characters that should remain upright.
|
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.
|
inline |
Returns whether this object is shared across multiple physics worlds.
If true, this object will keep additional information about it's state changes. In particular, we track any change to a physics object that is not a result of the physics simulation itself.
|
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.
|
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 |
|
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::BoxObstacle, cugl::physics2::CapsuleObstacle, cugl::physics2::PolygonObstacle, and cugl::physics2::WheelObstacle.
|
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::BoxObstacle, cugl::physics2::CapsuleObstacle, cugl::physics2::PolygonObstacle, and cugl::physics2::WheelObstacle.
|
inlinevirtual |
Resets this body to use the mass computed from the its shape and density
|
inlinevirtual |
Sets the angle of rotation for this body (about the center).
value | the angle of rotation for this body (in radians) |
|
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.
snap | the number of decimal places to snap rotation to the physics body |
|
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. |
|
inlinevirtual |
Sets the angular velocity for this physics body
value | the angular velocity for this physics body (in radians) |
|
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 |
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 |
|
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 |
|
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 |
|
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 |
|
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. |
|
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 |
|
virtual |
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::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 |
|
virtual |
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 |
|
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 |
|
virtual |
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 |
|
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 |
|
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 |
|
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. |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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.
snap | the number of decimal places to snap the node to the physics body |
|
virtual |
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 |
|
virtual |
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. |
|
inline |
Sets whether this object is shared across multiple physics worlds.
If true, this object will keep additional information about it's state changes. In particular, we track any change to a physics object that is not a result of the physics simulation itself.
shared | Whether this object is shared across multiple worlds. |
|
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 |
|
inlinevirtual |
Sets the x-velocity for this physics body
value | the x-velocity for this physics body |
|
inlinevirtual |
Sets the y-velocity for this physics body
value | the y-velocity for this physics body |
|
inlinevirtual |
Sets the x-coordinate for this physics body
value | the x-coordinate for this physics body |
|
inlinevirtual |
Sets the y-coordinate for this physics body
value | the y-coordinate for this physics body |
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 |
|
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).
|
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 |
Cache of factor to snap rotation of image to physics body
|
protected |
Number of decimal places to snap rotation of image to physics body
|
protected |
The physics body for Box2D.
|
protected |
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 |
Cache of factor to snap position of image to physics body
|
protected |
Number of decimal places to snap position of image to physics body
|
protected |
The wireframe parent for debugging.
|
protected |
Whether or not this obstacle is shared across multiple obstacle worlds
|
protected |
A tag for debugging purposes