![]() |
Gamedev Framework (gf)
0.16.0
A C++14 framework for 2D games
|
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 Transform & | getTransform () 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... | |
A physics body.
A body has several properties:
| gf::PhysicsBody::PhysicsBody | ( | const PhysicsGeometry & | geometry, |
| Type | type = Dynamic |
||
| ) |
Constructor.
| geometry | The geometry of the body |
| type | The type of the body (default: dynamic) |
| void gf::PhysicsBody::applyForce | ( | Vector2f | force | ) |
Apply a force.
The force changes the acceleration (by Newton's law)
| force | The force to apply to the acceleration of the body |
| void gf::PhysicsBody::applyLinearImpulse | ( | Vector2f | impulse | ) |
Apply a linear impulse.
The impulse changes the velocity.
| impulse | The 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.
| other | The other body |
| p | Data to fill if there is a collision |
|
inline |
Get the acceleration of the body.
|
inline |
Get the angle of the body.
|
inline |
Get the dynamic friction coefficient of the body.
|
inline |
Get the inverse mass of the body.
The inverse mass is zero for static objects.
|
inline |
Get the linear damping of the body.
|
inline |
Get the linear velocity of the body.
|
inline |
Get the position of the body.
|
inline |
Get the restitution of the body of the body.
|
inline |
Get the static friction coefficient of the body.
| const Transform& gf::PhysicsBody::getTransform | ( | ) | const |
|
inline |
Get the type of the body.
| void gf::PhysicsBody::move | ( | Vector2f | offset | ) |
Move the body.
| offset | The offset to apply to the position of the body |
| 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.
| target | The render target |
| states | The render states to use for drawing |
|
inline |
Set the angle of the body.
| angle | The 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.
| density | The new density |
|
inline |
Set the dynamic friction coefficient of the body.
| friction | The new friction coefficient |
|
inline |
Set the linear damping of the body.
| damping | The new damping |
|
inline |
Set the linear velocity of the body.
| velocity | The new velocity |
| void gf::PhysicsBody::setPosition | ( | Vector2f | position | ) |
Set the position of the body.
| position | The new position of the body |
|
inline |
Set the restitution of the body of the body.
| restitution | The new restitution |
|
inline |
Set the static friction coefficient of the body.
| friction | The new friction coefficient |
| void gf::PhysicsBody::setVelocityFromAngle | ( | ) |
Set the velocity direction from the angle of the body.
| void gf::PhysicsBody::step | ( | float | dt | ) |
Update the model's state.
| dt | The time (in seconds) since the last update |
|
inline |
Change the angle of the body.
| arc | The arc to add to the current angle |
| void gf::PhysicsBody::updateTransform | ( | ) |
1.8.13