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

A system of interlocking gears. More...

#include <Gear.h>

Inheritance diagram for CGear:
Collaboration diagram for CGear:

Public Member Functions

 CGear ()
 Constructor.
 
 ~CGear ()
 Destructor.
 
void Action ()
 Reverse gears.
 
- Public Member Functions inherited from CLevel
 CLevel (eSprite)
 
virtual ~CLevel ()
 Default constructor.
 
virtual void Move ()
 Destructor.
 
virtual void Draw ()
 Draw objects in level.
 

Private Member Functions

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

Private Attributes

std::vector< b2RevoluteJoint * > m_stdJoint
 Revolute joint pointers.
 
b2Body * m_pBase = nullptr
 Pointer to invisible background body.
 

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

The number and positions of the gears are hard-coded but since we use std::vector for storage, it is fairly easy to add more if you want them.

Constructor & Destructor Documentation

◆ ~CGear()

CGear::~CGear ( )

The only thing that needs to be cleaned up here is the physics body for the base, which is the invisible background to which we attach our revolute joints. The other physics bodies are cleaned up in the CObject destructor.

Member Function Documentation

◆ Action()

void CGear::Action ( )
virtual

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

Reimplemented from CLevel.

◆ CreateBase()

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

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

◆ CreateGear()

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

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

◆ CreateGearJoint()

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

Create a gear joint between two of the revolute joints in m_stdJoint.

Parameters
iIndex of first revolute joint and body attached to it.
jIndex of second revolute joint and body attached to it.
rGear ratio.
Here is the caller graph for this function:

◆ CreateRoundGears()

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

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

◆ CreateSquareGears()

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

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

Parameters
xX coordinate in Physics World units.
yY coordinate in Physics World units.
Here is the call graph for this function:
Here is the caller graph for this function: