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

A class representing a Box2D dynamic body with special fixtures and data used to track collisions and respond to them in a way that is appropriate to the game rather than what is correct for the physical simulation. More...

#include <CharacterBody.hpp>

Collaboration diagram for pk::CharacterBody:
Collaboration graph

Public Member Functions

 CharacterBody (b2World *world, GLRect rect, int id)
 
virtual ~CharacterBody ()
 
b2World * getWorld ()
 Get a pointer to the Box2D world. 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 CharacterBody. More...
 
float getRotation ()
 Get the rotation for the CharacterBody. More...
 
void setTransform (b2Vec2 position, float angle)
 Set the transform data (position and angle) for the CharacterBody. 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...
 
int getCharacterBodyID ()
 Get the CharacterBody ID. More...
 
SensorDatafootSensor ()
 Get the foot sensor data. More...
 
SensorDataleftSensor ()
 Get the left sensor data. More...
 
SensorDatarightSensor ()
 Get the right sensor data. More...
 
SensorDatatopSensor ()
 Get the top sensor data. More...
 
void destroyBody ()
 Destroy the CharacterBody. Safe destruction using the internals of Box2D. More...
 
bool canJump ()
 Check if the CharacterBody can jump. Based on SensorData from foot sensor. More...
 
bool touchingWall ()
 Check if the CharacterBody is touching a wall. Based on SensorData from left, right, and top. More...
 

Private Member Functions

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

Private Attributes

b2World * m_world
 A pointer to a Box2D world. More...
 
b2BodyDef m_bodyDef
 A Box2D body definition structure. More...
 
b2Body * m_body
 A Box2D body. More...
 
b2PolygonShape m_shape
 A Box2D polygon shape. More...
 
b2FixtureDef m_fixtureDef
 A Box2D fixture definition structure. More...
 
GLRect m_rect
 A GLRect structure. More...
 
int m_characterID
 The unique id of the character body. More...
 
SensorDatam_footSensorData
 Foot sensor data. More...
 
SensorDatam_leftSensorData
 Left sensor data. More...
 
SensorDatam_rightSensorData
 Right sensor data. More...
 
SensorDatam_topSensorData
 Top sensor data. More...
 

Detailed Description

A class representing a Box2D dynamic body with special fixtures and data used to track collisions and respond to them in a way that is appropriate to the game rather than what is correct for the physical simulation.

Constructor & Destructor Documentation

◆ CharacterBody() [1/2]

pk::CharacterBody::CharacterBody ( )
inlineprivate

Default constructor - Inaccessible.

◆ CharacterBody() [2/2]

pk::CharacterBody::CharacterBody ( b2World *  world,
GLRect  rect,
int  id 
)

◆ ~CharacterBody()

virtual pk::CharacterBody::~CharacterBody ( )
virtual

Member Function Documentation

◆ allowSleep()

void pk::CharacterBody::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.

◆ canJump()

bool pk::CharacterBody::canJump ( )

Check if the CharacterBody can jump. Based on SensorData from foot sensor.

◆ destroyBody()

void pk::CharacterBody::destroyBody ( )

Destroy the CharacterBody. Safe destruction using the internals of Box2D.

◆ footSensor()

SensorData * pk::CharacterBody::footSensor ( )
inline

Get the foot sensor data.

Returns
SensorData* - a pointer to the foot sensor data.

◆ getCharacterBodyID()

int pk::CharacterBody::getCharacterBodyID ( )
inline

Get the CharacterBody ID.

Returns
int - a plain old int as ID.

◆ getDensity()

float pk::CharacterBody::getDensity ( )
inline

Get the density of the body.

Returns
float - a plain old float.

◆ getFriction()

float pk::CharacterBody::getFriction ( )
inline

Get the friction of the body.

Returns
float - a plain old float.

◆ getLinearVelocity()

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

Get the linear velocity of the body.

Returns
glm::vec2 - a vector of floats.

◆ getPosition()

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

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

Returns
b2Vec2 - a Box2D vector of floats.

◆ getPositionInPixels()

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

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

Returns
glm::vec2 - a vector of floats.

◆ getRestitution()

float pk::CharacterBody::getRestitution ( )
inline

Get the restitution of the body.

Returns
float - a plain old float.

◆ getRotation()

float pk::CharacterBody::getRotation ( )
inline

Get the rotation for the CharacterBody.

Returns
float - a plain old float as degrees.

◆ getWorld()

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

Get a pointer to the Box2D world.

Returns
b2World* - a pointer to a Box2D b2World.

◆ leftSensor()

SensorData * pk::CharacterBody::leftSensor ( )
inline

Get the left sensor data.

Returns
SensorData* - a pointer to the left sensor data.

◆ rightSensor()

SensorData * pk::CharacterBody::rightSensor ( )
inline

Get the right sensor data.

Returns
SensorData* - a pointer to the right sensor data.

◆ setDensity()

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

Set the density of the body.

Parameters
floatdensity - a plain old float.

◆ setFixedRotation()

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

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

Parameters
boolr - a plain old bool.

◆ setFriction()

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

Set the friction for the body.

Parameters
floatfriction - a plain old float.

◆ setLinearVelocity()

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

Set the linear velocity of the body.

Parameters
glm::vec2v - a vector of floats.

◆ setPosition()

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

Set the position of the CharacterBody.

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

◆ setRestitution()

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

Set the restitution (bounciness) for the body.

Parameters
floatrestitution - a plain old float.

◆ setTransform()

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

Set the transform data (position and angle) for the CharacterBody.

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

◆ topSensor()

SensorData * pk::CharacterBody::topSensor ( )
inline

Get the top sensor data.

Returns
SensorData* - a pointer to the top sensor data.

◆ touchingWall()

bool pk::CharacterBody::touchingWall ( )

Check if the CharacterBody is touching a wall. Based on SensorData from left, right, and top.

Member Data Documentation

◆ m_body

b2Body* pk::CharacterBody::m_body
private

A Box2D body.

◆ m_bodyDef

b2BodyDef pk::CharacterBody::m_bodyDef
private

A Box2D body definition structure.

◆ m_characterID

int pk::CharacterBody::m_characterID
private

The unique id of the character body.

◆ m_fixtureDef

b2FixtureDef pk::CharacterBody::m_fixtureDef
private

A Box2D fixture definition structure.

◆ m_footSensorData

SensorData* pk::CharacterBody::m_footSensorData
private

Foot sensor data.

◆ m_leftSensorData

SensorData* pk::CharacterBody::m_leftSensorData
private

Left sensor data.

◆ m_rect

GLRect pk::CharacterBody::m_rect
private

A GLRect structure.

◆ m_rightSensorData

SensorData* pk::CharacterBody::m_rightSensorData
private

Right sensor data.

◆ m_shape

b2PolygonShape pk::CharacterBody::m_shape
private

A Box2D polygon shape.

◆ m_topSensorData

SensorData* pk::CharacterBody::m_topSensorData
private

Top sensor data.

◆ m_world

b2World* pk::CharacterBody::m_world
private

A pointer to a Box2D world.


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