![]() |
Box2D Joint Toy
Ian Parberry's "Introduction to Game Physics"
|
Rack and pinion. More...
#include <RackAndPinion.h>
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 b2World * | m_pPhysicsWorld = nullptr |
Pointer to Box2D Physics World. | |
static CRenderer * | m_pRenderer = nullptr |
Pointer to the renderer. | |
static CObjectManager * | m_pObjectManager = nullptr |
Pointer to the object manager. | |
static CWindmill * | m_pWindmill = nullptr |
Pointer to windmill. | |
static CGear * | m_pGear = nullptr |
Pointer to gear system. | |
static CNautilusGear * | m_pNautilusGear = nullptr |
Pointer to Nautilus gear system. | |
static CRackAndPinion * | m_pRackAndPinion = nullptr |
Pointer to rack-and-pinion. | |
static CCar * | m_pCar = nullptr |
Pointer to car. | |
static CRamp * | m_pRamp = nullptr |
Pointer to ramp. | |
static CNewtonsCradle * | m_pNewtonsCradle = nullptr |
Pointer to Newton's Cradle. | |
static CPulley * | m_pPulley = nullptr |
Pointer to pulley system. | |
static eLevel | m_eCurLevel = eLevel::Windmill |
Current level. | |
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.
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.
x | X coordinate in Physics World units. |
y | Y coordinate in Physics World units. |
|
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.
x | X coordinate in Physics World units. |
y | Y coordinate in Physics World units. |
|
private |
Create a pinion.
Create a pinion at a given position in Physics World.
x | X coordinate in Physics World units. |
y | Y coordinate in Physics World units. |
|
private |
Create a rack.
Create a rack object at a given position in Physics World.
x | X coordinate in Physics World units. |
y | Y coordinate in Physics World units. |
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.
void CRackAndPinion::reverse | ( | ) |
Reverse the motor.
Reverse the pinion by setting the motor speed on the revolute joint.