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

A system of interlocking gears. More...

#include <Gear.h>

Inheritance diagram for CGear:
CCommon

Public Member Functions

 CGear (float, float)
 Constructor. More...
 
void reverse ()
 Reverse gears. More...
 

Private Member Functions

b2Body * CreateBase (float, float)
 Create invisible base in Physics World. More...
 
void CreateRoundGears (float, float)
 Create round gears in Physics World. More...
 
void CreateSquareGears (float, float)
 Create square gears in Physics World. More...
 
b2Body * CreateGear (float, float, eSprite)
 Create gear wheel in Physics World. More...
 
void CreateGearJoint (UINT, UINT, float)
 Create gear joint in Physics World. More...
 

Private Attributes

std::vector< b2Body * > m_stdGear
 Gear body pointers.
 
std::vector< b2RevoluteJoint * > m_stdJoint
 Revolute joint pointers.
 

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

A system of interlocking gears.

The number and positions of the gears are hard-coded but there is enough storage for any number of them.

Constructor & Destructor Documentation

◆ CGear()

CGear::CGear ( float  x,
float  y 
)

Constructor.

Parameters
xX coordinate in Physics World units.
yY coordinate in Physics World units.

Member Function Documentation

◆ CreateBase()

b2Body * CGear::CreateBase ( float  x,
float  y 
)
private

Create invisible base in Physics World.

Create an invisible base to attach the largest gear wheel to. The base has no sprite and no shape in Physics World. The latter means it doesn't collide with anything.

Parameters
xX coordinate in Physics World units.
yY coordinate in Physics World units.
Returns
Pointer to the cog wheel body in Physics World.

◆ CreateGear()

b2Body * CGear::CreateGear ( float  x,
float  y,
eSprite  t 
)
private

Create gear wheel in Physics World.

Create a gear wheel at a given position in Physics World.

Parameters
xX coordinate in Physics World units.
yY coordinate in Physics World units.
tSprite type of the gear wheel.
Returns
Pointer to the cog wheel body in Physics World.

◆ CreateGearJoint()

void CGear::CreateGearJoint ( UINT  i,
UINT  j,
float  r 
)
private

Create gear joint in Physics World.

Create a gear joint between two of hthe revolute joints in m_pJoint.

Parameters
iIndex of first revolute joint and body attached to it.
jIndex of second revolute joint and body attached to it.
rGear ratio.

◆ CreateRoundGears()

void CGear::CreateRoundGears ( float  x,
float  y 
)
private

Create round gears in Physics World.

Create the square gears and push them onto the gear list. It is assumed that this function is called first and that the driving gear (the one with the motor on its revolute joint) is to be the first one on the gear list.

Parameters
xX coordinate in Physics World units.
yY coordinate in Physics World units.

◆ CreateSquareGears()

void CGear::CreateSquareGears ( float  x,
float  y 
)
private

Create square gears in Physics World.

Create the square gears and push them onto the gear list.

Parameters
xX coordinate in Physics World units.
yY coordinate in Physics World units.

◆ reverse()

void CGear::reverse ( )

Reverse gears.

Reverse the gears by setting the motor speed on the revolute joint for the first gear.