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

A model for physics simulation. More...

#include <gf/PhysicsModel.h>

Inheritance diagram for gf::PhysicsModel:
Inheritance graph
[legend]

Public Member Functions

 PhysicsModel (Vector2f gravity={ 0.0f, 0.0f })
 Constructor. More...
 
void setGravity (Vector2f gravity) noexcept
 Set the gravity of the simulation. More...
 
Vector2f getGravity () const noexcept
 Get the gravity of the simulation. More...
 
void addBody (PhysicsBody &body)
 Add a body to the simulation. More...
 
void removeBody (PhysicsBody &body)
 Remove a body from the simulation. More...
 
void clear ()
 Remove all bodies from the simulation. More...
 
virtual void update (Time time) override
 Update the model's state. More...
 
- Public Member Functions inherited from gf::Model
virtual ~Model ()
 Destructor. More...
 

Detailed Description

A model for physics simulation.

See also
gf::PhysicsBody, gf::FixedTimestepModel

Constructor & Destructor Documentation

◆ PhysicsModel()

gf::PhysicsModel::PhysicsModel ( Vector2f  gravity = { 0.0f, 0.0f })

Constructor.

Parameters
gravityThe gravity of the simulation (default: no gravity)

Member Function Documentation

◆ addBody()

void gf::PhysicsModel::addBody ( PhysicsBody body)

Add a body to the simulation.

Parameters
bodyA physics body

◆ clear()

void gf::PhysicsModel::clear ( )

Remove all bodies from the simulation.

◆ getGravity()

Vector2f gf::PhysicsModel::getGravity ( ) const
inlinenoexcept

Get the gravity of the simulation.

Returns
The current gravity

◆ removeBody()

void gf::PhysicsModel::removeBody ( PhysicsBody body)

Remove a body from the simulation.

Parameters
bodyA physics body

◆ setGravity()

void gf::PhysicsModel::setGravity ( Vector2f  gravity)
inlinenoexcept

Set the gravity of the simulation.

Parameters
gravityThe new gravity

◆ update()

virtual void gf::PhysicsModel::update ( Time  time)
overridevirtual

Update the model's state.

Models are updated each frame. The time between two frames is given as a parameter to help in the update. This time is in seconds.

Parameters
timeThe time since the last update
See also
gf::ModelContainer::update()

Reimplemented from gf::Model.