Box2D Joint Toy
Game Physics with a 2D Physics Engine
Loading...
Searching...
No Matches
CRackAndPinion Class Reference

Rack and pinion. More...

#include <RackAndPinion.h>

Inheritance diagram for CRackAndPinion:
Collaboration diagram for CRackAndPinion:

Public Member Functions

 CRackAndPinion ()
 Constructor.
 
 ~CRackAndPinion ()
 Destructor.
 
void Move ()
 Reverse the rack when it hits the limits.
 
void Action ()
 Reverse the motor.
 
- Public Member Functions inherited from CLevel
 CLevel (eSprite)
 
virtual ~CLevel ()
 Default constructor.
 
virtual void Draw ()
 Draw objects in level.
 

Private Member Functions

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

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

- Protected Member Functions inherited from CLevel
CLineObjectCreateLine (b2Body *, const b2Vec2 &, bool, b2Body *, const b2Vec2 &, bool)
 Create new line object.
 
- Protected Attributes inherited from CLevel
std::vector< CObject * > m_stdObject
 Object pointers.
 
std::vector< CLineObject * > m_stdLine
 Line list.
 
eSprite m_eBgSprite
 Type of background sprite.
 
- Static Protected Attributes inherited from CCommon
static b2World * m_pPhysicsWorld = nullptr
 Pointer to Box2D Physics World.
 
static CBox2DRenderer * m_pRenderer = nullptr
 Pointer to the renderer.
 
static CLevelm_pLevel = nullptr
 Pointer to current level.
 
static eLevel m_eCurLevel = eLevel::Windmill
 Current level.
 
static eDrawMode m_eDrawMode = eDrawMode::Sprites
 Draw mode.
 

Detailed Description

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 ( )

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.

Here is the call graph for this function:

Member Function Documentation

◆ Action()

void CRackAndPinion::Action ( )
virtual

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

Reimplemented from CLevel.

◆ CreateBase()

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

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.
Here is the caller graph for this function:

◆ CreatePinion()

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

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.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ CreateRack()

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

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.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Move()

void CRackAndPinion::Move ( )
virtual

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

Reimplemented from CLevel.

Here is the call graph for this function: