Box2D Joint Toy
Ian Parberry's "Introduction to Game Physics"
Public Member Functions | Private Member Functions | Private Attributes | List of all members
CPulley Class Reference

The pulley class. More...

#include <Pulley.h>

Inheritance diagram for CPulley:
CCommon

Public Member Functions

 CPulley (float, float, float)
 Constructor. More...
 
void move ()
 Rotate the pulley wheels. More...
 
void CreateElephant ()
 Create an elephant. More...
 
bool DeleteElephant ()
 Delete an elephant. More...
 

Private Member Functions

b2Body * CreateWheel (float, float)
 Create a pulley wheel. More...
 
b2Body * CreateCrate (float, float)
 Create the elephant's crate. More...
 
b2Body * CreateObject (const b2Vec2 &, float, eSprite)
 Create an object. More...
 

Private Attributes

b2PulleyJoint * m_pJoint = nullptr
 Pointer to the pulley joint.
 
float m_fJointLenA = 0
 Length of left side of pulley.
 
b2Body * m_pWheel0 = nullptr
 Pointer to the left pulley wheel.
 
b2Body * m_pWheel1 = nullptr
 Pointer to the right pulley wheel.
 
float m_fWheelRad = 1
 Pulley wheel radius.
 
b2Vec2 m_vElephantSpawnPt
 Elephant spawn point.
 

Additional Inherited Members

- Static Protected Attributes inherited from CCommon
static b2World * m_pPhysicsWorld = nullptr
 Pointer to Box2D Physics World.
 
static CRendererm_pRenderer = nullptr
 Pointer to the renderer.
 
static CObjectManagerm_pObjectManager = nullptr
 Pointer to the object manager.
 
static CWindmillm_pWindmill = nullptr
 Pointer to windmill.
 
static CGearm_pGear = nullptr
 Pointer to gear system.
 
static CNautilusGearm_pNautilusGear = nullptr
 Pointer to Nautilus gear system.
 
static CRackAndPinionm_pRackAndPinion = nullptr
 Pointer to rack-and-pinion.
 
static CCarm_pCar = nullptr
 Pointer to car.
 
static CRampm_pRamp = nullptr
 Pointer to ramp.
 
static CNewtonsCradlem_pNewtonsCradle = nullptr
 Pointer to Newton's Cradle.
 
static CPulleym_pPulley = nullptr
 Pointer to pulley system.
 
static eLevel m_eCurLevel = eLevel::Windmill
 Current level.
 

Detailed Description

The pulley class.

A pair of objects connected by a pulley joint, with a pair of pulley wheels that are animated in code.

Constructor & Destructor Documentation

◆ CPulley()

CPulley::CPulley ( float  x,
float  y,
float  w 
)

Constructor.

Parameters
xX coordinate in Physics World units.
yY coordinate in Physics World units.
wPulley wheel horizontal separation in Physics World units.

Member Function Documentation

◆ CreateCrate()

b2Body * CPulley::CreateCrate ( float  x,
float  y 
)
private

Create the elephant's crate.

The bucket is the thing on the left that the elephant falls into. It consists of a left side, a right side, and a bottom, all of which are rectangles.

Parameters
xX coordinate in Physics World units.
yY coordinate in Physics World units.
Returns
Pointer to physics body.

◆ CreateElephant()

void CPulley::CreateElephant ( )

Create an elephant.

Create an elephant at its spawn point offset by a small pseudorandom amount to make the crate swing a bot.

◆ CreateObject()

b2Body * CPulley::CreateObject ( const b2Vec2 &  v,
float  d,
eSprite  t 
)
private

Create an object.

Create an object, used for the safe and the elephant.

Parameters
vPosition in Physics World.
dObject density.
tType of object to be created.
Returns
Pointer to physics body.

◆ CreateWheel()

b2Body * CPulley::CreateWheel ( float  x,
float  y 
)
private

Create a pulley wheel.

The pulley wheels are going to be static objects that we rotate ourselves depending on the positions of the objects that the pulley is attached to.

Parameters
xX coordinate in Physics World units.
yY coordinate in Physics World units.
Returns
Pointer to physics body.

◆ DeleteElephant()

bool CPulley::DeleteElephant ( )

Delete an elephant.

Delete the first elephant, if there is one.

Returns
true if there was an elephant.

◆ move()

void CPulley::move ( )

Rotate the pulley wheels.

Animate the pulley wheels by setting their orientations to reflect the amount of rope that has gone over them.