Gamedev Framework (gf)  0.4.0
A C++11 framework for 2D games
Public Types | Public Member Functions | List of all members
gf::PhysicsBody Class Reference

A physics body. More...

#include <gf/PhysicsBody.h>

Public Types

enum  Type {
  Static,
  Dynamic
}
 Type of body. More...
 

Public Member Functions

 PhysicsBody (const PhysicsGeometry &geometry, Type type=Dynamic)
 Constructor. More...
 
Type getType () const
 Get the type of the body. More...
 
void update (float dt)
 Update the model's state. More...
 
void render (RenderTarget &target) const
 Render the body. More...
 
bool collidesWith (const PhysicsBody &other, Penetration &p) const
 Check if the body collides with another body. More...
 
Position, angle, velocity and acceleration
Vector2f getPosition () const
 Get the position of the body. More...
 
void setPosition (Vector2f position)
 Set the position of the body. More...
 
void move (Vector2f offset)
 Move the body. More...
 
Vector2f getLinearVelocity () const
 Get the linear velocity of the body. More...
 
void setLinearVelocity (Vector2f velocity)
 Set the linear velocity of the body. More...
 
void applyLinearImpulse (Vector2f impulse)
 Apply a linear impulse. More...
 
Vector2f getAcceleration () const
 Get the acceleration of the body. More...
 
void applyForce (Vector2f force)
 Apply a force. More...
 
float getAngle () const
 Get the angle of the body. More...
 
void setAngle (float angle)
 Set the angle of the body. More...
 
void turn (float arc)
 Change the angle of the body. More...
 
void setVelocityFromAngle ()
 Set the velocity direction from the angle of the body. More...
 
void updateTransform ()
 Update the internal transform. More...
 
const TransformgetTransform () const
 Get the current transform. More...
 
Body properties
void setRestitution (float restitution)
 Set the restitution of the body of the body. More...
 
float getRestitution () const
 Get the restitution of the body of the body. More...
 
void setStaticFriction (float friction)
 Set the static friction coefficient of the body. More...
 
float getStaticFriction () const
 Get the static friction coefficient of the body. More...
 
void setDynamicFriction (float friction)
 Set the dynamic friction coefficient of the body. More...
 
float getDynamicFriction () const
 Get the dynamic friction coefficient of the body. More...
 
void setLinearDamping (float damping)
 Set the linear damping of the body. More...
 
float getLinearDamping () const
 Get the linear damping of the body. More...
 
void setDensity (float density)
 Set the density of the body. More...
 
float getInverseMass () const
 Get the inverse mass of the body. More...
 

Detailed Description

A physics body.

A body has several properties:

See also
gf::PhysicsGeometry, gf::PhysicsModel

Constructor & Destructor Documentation

gf::PhysicsBody::PhysicsBody ( const PhysicsGeometry geometry,
Type  type = Dynamic 
)

Constructor.

Parameters
geometryThe geometry of the body
typeThe type of the body (default: dynamic)

Member Function Documentation

void gf::PhysicsBody::applyForce ( Vector2f  force)

Apply a force.

The force changes the acceleration (by Newton's law)

Parameters
forceThe force to apply to the acceleration of the body
void gf::PhysicsBody::applyLinearImpulse ( Vector2f  impulse)

Apply a linear impulse.

The impulse changes the velocity.

Parameters
impulseThe impulse to apply to the velocity of the body
bool gf::PhysicsBody::collidesWith ( const PhysicsBody other,
Penetration p 
) const

Check if the body collides with another body.

Parameters
otherThe other body
pData to fill if there is a collision
Vector2f gf::PhysicsBody::getAcceleration ( ) const
inline

Get the acceleration of the body.

Returns
The current acceleration
float gf::PhysicsBody::getAngle ( ) const
inline

Get the angle of the body.

Returns
The angle of the body
float gf::PhysicsBody::getDynamicFriction ( ) const
inline

Get the dynamic friction coefficient of the body.

Returns
The current friction coefficient
float gf::PhysicsBody::getInverseMass ( ) const
inline

Get the inverse mass of the body.

The inverse mass is zero for static objects.

Returns
The current inverse mass
float gf::PhysicsBody::getLinearDamping ( ) const
inline

Get the linear damping of the body.

Returns
The current damping
Vector2f gf::PhysicsBody::getLinearVelocity ( ) const
inline

Get the linear velocity of the body.

Returns
The current linear velocity
Vector2f gf::PhysicsBody::getPosition ( ) const
inline

Get the position of the body.

Returns
The current position of the body
float gf::PhysicsBody::getRestitution ( ) const
inline

Get the restitution of the body of the body.

Returns
The current restitution
float gf::PhysicsBody::getStaticFriction ( ) const
inline

Get the static friction coefficient of the body.

Returns
The current friction coefficient
const Transform& gf::PhysicsBody::getTransform ( ) const

Get the current transform.

Returns
The current transform
See also
updateTransform()
Type gf::PhysicsBody::getType ( ) const
inline

Get the type of the body.

Returns
The type of the body
void gf::PhysicsBody::move ( Vector2f  offset)

Move the body.

Parameters
offsetThe offset to apply to the position of the body
void gf::PhysicsBody::render ( RenderTarget target) const

Render the body.

This function is for debugging purpose. The body is outlined in red.

Parameters
targetThe render target
void gf::PhysicsBody::setAngle ( float  angle)
inline

Set the angle of the body.

Parameters
angleThe new angle
void gf::PhysicsBody::setDensity ( float  density)

Set the density of the body.

This changes the mass of the body, according to its geometry.

Parameters
densityThe new density
void gf::PhysicsBody::setDynamicFriction ( float  friction)
inline

Set the dynamic friction coefficient of the body.

Parameters
frictionThe new friction coefficient
void gf::PhysicsBody::setLinearDamping ( float  damping)
inline

Set the linear damping of the body.

Parameters
dampingThe new damping
void gf::PhysicsBody::setLinearVelocity ( Vector2f  velocity)
inline

Set the linear velocity of the body.

Parameters
velocityThe new velocity
void gf::PhysicsBody::setPosition ( Vector2f  position)

Set the position of the body.

Parameters
positionThe new position of the body
void gf::PhysicsBody::setRestitution ( float  restitution)
inline

Set the restitution of the body of the body.

Parameters
restitutionThe new restitution
void gf::PhysicsBody::setStaticFriction ( float  friction)
inline

Set the static friction coefficient of the body.

Parameters
frictionThe new friction coefficient
void gf::PhysicsBody::setVelocityFromAngle ( )

Set the velocity direction from the angle of the body.

void gf::PhysicsBody::turn ( float  arc)
inline

Change the angle of the body.

Parameters
arcThe arc to add to the current angle
void gf::PhysicsBody::update ( float  dt)

Update the model's state.

Parameters
dtThe time (in seconds) since the last update
void gf::PhysicsBody::updateTransform ( )

Update the internal transform.

Normally, you should not call this function.

See also
getTransform()