PROTO::KLUDGE  0.1
Quick prototyping library for games using SDL and OpenGL.
pk::KinematicBody Class Reference

A class wrapper to ease the instantiation and use of Box2D kinematic bodies. It also performs conversions between meters in physics space and pixels in screen space automatically. More...

#include <KinematicBody.hpp>

Collaboration diagram for pk::KinematicBody:
Collaboration graph

Public Member Functions

 KinematicBody (b2World *world, GLRect rect)
 Preferred constructor. More...
 
virtual ~KinematicBody ()
 
b2World * getWorld ()
 Get a pointer to the Box2D world the static platform is tied to. More...
 
void setDensity (float density)
 Set the density of the body. More...
 
float getDensity ()
 Get the density of the body. More...
 
void setFriction (float friction)
 Set the friction for the body. More...
 
float getFriction ()
 Get the friction of the body. More...
 
void setRestitution (float restitution)
 Set the restitution (bounciness) for the body. More...
 
float getRestitution ()
 Get the restitution of the body. More...
 
void setFixedRotation (bool r)
 Set the body's rotation as fixed (no rotation). More...
 
void allowSleep (bool s)
 Set the body to allow sleeping. This increases efficiency and performance of Box2D while also preventing bodies from randomly jittering when they should appear still. More...
 
b2Vec2 getPosition ()
 Get the position of the body in Box2D units (meters). More...
 
void setPosition (glm::vec2 position)
 Set the position of the KinematicBody. More...
 
float getRotation ()
 Get the rotation of the KinematicBody. More...
 
void setTransform (b2Vec2 position, float angle)
 Set the transform (position and angle) of the KinematicBody. More...
 
glm::vec2 getPositionInPixels ()
 Get the position of the body in screen units (pixels). More...
 
void setLinearVelocity (glm::vec2 v)
 Set the linear velocity of the body. More...
 
glm::vec2 getLinearVelocity ()
 Get the linear velocity of the body. More...
 
void destroyBody ()
 Destroy the KinematicBody. Safely removes the body using Box2D internals. More...
 

Private Member Functions

 KinematicBody ()
 Default constructor - Inaccessible. More...
 

Private Attributes

b2World * m_world
 A pointer to the Box2D world. More...
 
b2BodyDef m_bodyDef
 A Box2D body definition structure. More...
 
b2PolygonShape m_shape
 A Box2D polygon shape. More...
 
b2FixtureDef m_fixtureDef
 A Box2D fixture definition structure. More...
 
b2Body * m_body
 A Box2D body. More...
 
GLRect m_rect
 A GLRect structure. More...
 

Detailed Description

A class wrapper to ease the instantiation and use of Box2D kinematic bodies. It also performs conversions between meters in physics space and pixels in screen space automatically.

Constructor & Destructor Documentation

◆ KinematicBody() [1/2]

pk::KinematicBody::KinematicBody ( )
inlineprivate

Default constructor - Inaccessible.

◆ KinematicBody() [2/2]

pk::KinematicBody::KinematicBody ( b2World *  world,
GLRect  rect 
)

Preferred constructor.

◆ ~KinematicBody()

virtual pk::KinematicBody::~KinematicBody ( )
virtual

Member Function Documentation

◆ allowSleep()

void pk::KinematicBody::allowSleep ( bool  s)
inline

Set the body to allow sleeping. This increases efficiency and performance of Box2D while also preventing bodies from randomly jittering when they should appear still.

Parameters
bools - a plain old bool.

◆ destroyBody()

void pk::KinematicBody::destroyBody ( )
inline

Destroy the KinematicBody. Safely removes the body using Box2D internals.

◆ getDensity()

float pk::KinematicBody::getDensity ( )
inline

Get the density of the body.

Returns
float - a plain old float.

◆ getFriction()

float pk::KinematicBody::getFriction ( )
inline

Get the friction of the body.

Returns
float - a plain old float.

◆ getLinearVelocity()

glm::vec2 pk::KinematicBody::getLinearVelocity ( )
inline

Get the linear velocity of the body.

Returns
glm::vec2 - a vector of floats.

◆ getPosition()

glm::vec2 pk::KinematicBody::getPosition ( )
inline

Get the position of the body in Box2D units (meters).

Returns
b2Vec2 - a Box2D vector of floats.

◆ getPositionInPixels()

glm::vec2 pk::KinematicBody::getPositionInPixels ( )
inline

Get the position of the body in screen units (pixels).

Returns
glm::vec2 - a vector of floats.

◆ getRestitution()

float pk::KinematicBody::getRestitution ( )
inline

Get the restitution of the body.

Returns
float - a plain old float.

◆ getRotation()

float pk::KinematicBody::getRotation ( )
inline

Get the rotation of the KinematicBody.

Returns
float - the rotation given as a float in degrees.

◆ getWorld()

b2World * pk::KinematicBody::getWorld ( )
inline

Get a pointer to the Box2D world the static platform is tied to.

◆ setDensity()

void pk::KinematicBody::setDensity ( float  density)
inline

Set the density of the body.

Parameters
floatdensity - a plain old float.

◆ setFixedRotation()

void pk::KinematicBody::setFixedRotation ( bool  r)
inline

Set the body's rotation as fixed (no rotation).

Parameters
boolr - a plain old bool.

◆ setFriction()

void pk::KinematicBody::setFriction ( float  friction)
inline

Set the friction for the body.

Parameters
floatfriction - a plain old float.

◆ setLinearVelocity()

void pk::KinematicBody::setLinearVelocity ( glm::vec2  v)
inline

Set the linear velocity of the body.

Parameters
glm::vec2v - a vector of floats.

◆ setPosition()

void pk::KinematicBody::setPosition ( glm::vec2  position)
inline

Set the position of the KinematicBody.

Parameters
glm::vec2position - the position given as a glm::vec2 of floats.

◆ setRestitution()

void pk::KinematicBody::setRestitution ( float  restitution)
inline

Set the restitution (bounciness) for the body.

Parameters
floatrestitution - a plain old float.

◆ setTransform()

void pk::KinematicBody::setTransform ( b2Vec2  position,
float  angle 
)
inline

Set the transform (position and angle) of the KinematicBody.

Parameters
b2Vec2position - the position given as a b2Vec2 of floats.
floatangle - the angle given as a float in degrees.

Member Data Documentation

◆ m_body

b2Body* pk::KinematicBody::m_body
private

A Box2D body.

◆ m_bodyDef

b2BodyDef pk::KinematicBody::m_bodyDef
private

A Box2D body definition structure.

◆ m_fixtureDef

b2FixtureDef pk::KinematicBody::m_fixtureDef
private

A Box2D fixture definition structure.

◆ m_rect

GLRect pk::KinematicBody::m_rect
private

A GLRect structure.

◆ m_shape

b2PolygonShape pk::KinematicBody::m_shape
private

A Box2D polygon shape.

◆ m_world

b2World* pk::KinematicBody::m_world
private

A pointer to the Box2D world.


The documentation for this class was generated from the following file: