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

Rack and pinion. More...

#include <RackAndPinion.h>

Inheritance diagram for CRackAndPinion:
CCommon

Public Member Functions

 CRackAndPinion (float, float)
 Constructor. More...
 
void move ()
 Reverse the rack when it hits the limits. More...
 
void reverse ()
 Reverse the motor. More...
 

Private Member Functions

b2Body * CreateRack (float, float)
 Create a rack. More...
 
b2Body * CreatePinion (float, float)
 Create a pinion. More...
 
b2Body * CreateBase (float, float)
 Create an invisible gentry. More...
 

Private Attributes

b2RevoluteJoint * m_pRevoluteJoint = nullptr
 Pointer to revolute joint for pinion.
 
b2PrismaticJoint * m_pPrismaticJoint = nullptr
 Pointer to prismatic joint for rack.
 
float m_fLimit = 0
 Translation limit for prismatic joint.
 

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

Rack and pinion.

A rack and pinion connected by a prismatic joint in Physics World. A rack and pinion is a type of linear actuator that comprises a pair of gears which convert rotational motion into linear motion. A circular gear called the pinion engages teeth on a linear gear bar called the rack. Rotational motion applied to the pinion causes the rack to move relative to the pinion, thereby translating the rotational motion of the pinion into linear motion.

Constructor & Destructor Documentation

◆ CRackAndPinion()

CRackAndPinion::CRackAndPinion ( float  x,
float  y 
)

Constructor.

Create a rack and a pinion at a given position in Physics World, with a revolute joint for the pinion and a prismatic joint for the rack. The revolute joint has a motor.

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

Member Function Documentation

◆ CreateBase()

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

Create an invisible gentry.

Create an invisible base to attach the pinion 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 base body in Physics World.

◆ CreatePinion()

b2Body * CRackAndPinion::CreatePinion ( float  x,
float  y 
)
private

Create a pinion.

Create a pinion at a given position in Physics World.

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

◆ CreateRack()

b2Body * CRackAndPinion::CreateRack ( float  x,
float  y 
)
private

Create a rack.

Create a rack object at a given position in Physics World.

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

◆ move()

void CRackAndPinion::move ( )

Reverse the rack when it hits the limits.

Monitor the pinion offset, and if it is p against the stops, then reverse the direction of the motor on the revolute joint.

◆ reverse()

void CRackAndPinion::reverse ( )

Reverse the motor.

Reverse the pinion by setting the motor speed on the revolute joint.