Gamedev Framework (gf)  0.6.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 step (float dt)
 Update the model's state. More...
 
void render (RenderTarget &target, const RenderStates &states) 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

Member Enumeration Documentation

◆ Type

Type of body.

Enumerator
Static 

Static body with infinite mass.

Dynamic 

Dynamic bodies with finite mass.

Constructor & Destructor Documentation

◆ PhysicsBody()

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

◆ applyForce()

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

◆ applyLinearImpulse()

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

◆ collidesWith()

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

◆ getAcceleration()

Vector2f gf::PhysicsBody::getAcceleration ( ) const
inline

Get the acceleration of the body.

Returns
The current acceleration

◆ getAngle()

float gf::PhysicsBody::getAngle ( ) const
inline

Get the angle of the body.

Returns
The angle of the body

◆ getDynamicFriction()

float gf::PhysicsBody::getDynamicFriction ( ) const
inline

Get the dynamic friction coefficient of the body.

Returns
The current friction coefficient

◆ getInverseMass()

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

◆ getLinearDamping()

float gf::PhysicsBody::getLinearDamping ( ) const
inline

Get the linear damping of the body.

Returns
The current damping

◆ getLinearVelocity()

Vector2f gf::PhysicsBody::getLinearVelocity ( ) const
inline

Get the linear velocity of the body.

Returns
The current linear velocity

◆ getPosition()

Vector2f gf::PhysicsBody::getPosition ( ) const
inline

Get the position of the body.

Returns
The current position of the body

◆ getRestitution()

float gf::PhysicsBody::getRestitution ( ) const
inline

Get the restitution of the body of the body.

Returns
The current restitution

◆ getStaticFriction()

float gf::PhysicsBody::getStaticFriction ( ) const
inline

Get the static friction coefficient of the body.

Returns
The current friction coefficient

◆ getTransform()

const Transform& gf::PhysicsBody::getTransform ( ) const

Get the current transform.

Returns
The current transform
See also
updateTransform()

◆ getType()

Type gf::PhysicsBody::getType ( ) const
inline

Get the type of the body.

Returns
The type of the body

◆ move()

void gf::PhysicsBody::move ( Vector2f  offset)

Move the body.

Parameters
offsetThe offset to apply to the position of the body

◆ render()

void gf::PhysicsBody::render ( RenderTarget target,
const RenderStates states 
) const

Render the body.

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

Parameters
targetThe render target
statesThe render states to use for drawing

◆ setAngle()

void gf::PhysicsBody::setAngle ( float  angle)
inline

Set the angle of the body.

Parameters
angleThe new angle

◆ setDensity()

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

◆ setDynamicFriction()

void gf::PhysicsBody::setDynamicFriction ( float  friction)
inline

Set the dynamic friction coefficient of the body.

Parameters
frictionThe new friction coefficient

◆ setLinearDamping()

void gf::PhysicsBody::setLinearDamping ( float  damping)
inline

Set the linear damping of the body.

Parameters
dampingThe new damping

◆ setLinearVelocity()

void gf::PhysicsBody::setLinearVelocity ( Vector2f  velocity)
inline

Set the linear velocity of the body.

Parameters
velocityThe new velocity

◆ setPosition()

void gf::PhysicsBody::setPosition ( Vector2f  position)

Set the position of the body.

Parameters
positionThe new position of the body

◆ setRestitution()

void gf::PhysicsBody::setRestitution ( float  restitution)
inline

Set the restitution of the body of the body.

Parameters
restitutionThe new restitution

◆ setStaticFriction()

void gf::PhysicsBody::setStaticFriction ( float  friction)
inline

Set the static friction coefficient of the body.

Parameters
frictionThe new friction coefficient

◆ setVelocityFromAngle()

void gf::PhysicsBody::setVelocityFromAngle ( )

Set the velocity direction from the angle of the body.

◆ step()

void gf::PhysicsBody::step ( float  dt)

Update the model's state.

Parameters
dtThe time (in seconds) since the last update

◆ turn()

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

Change the angle of the body.

Parameters
arcThe arc to add to the current angle

◆ updateTransform()

void gf::PhysicsBody::updateTransform ( )

Update the internal transform.

Normally, you should not call this function.

See also
getTransform()