![]() |
Box2D Joint Toy
Game Physics with a 2D Physics Engine
|
A system of interlocking gears. More...
#include <Gear.h>


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 | |
| CLineObject * | CreateLine (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 CLevel * | m_pLevel = nullptr |
| Pointer to current level. | |
| static eLevel | m_eCurLevel = eLevel::Windmill |
| Current level. | |
| static eDrawMode | m_eDrawMode = eDrawMode::Sprites |
| Draw mode. | |
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.
| 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.
|
virtual |
Reverse the gears by setting the motor speed on the revolute joint for the first gear.
Reimplemented from CLevel.
|
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.
| x | X coordinate in Physics World units. |
| y | Y coordinate in Physics World units. |

|
private |
Create a gear wheel at a given position in Physics World.
| x | X coordinate in Physics World units. |
| y | Y coordinate in Physics World units. |
| t | Sprite type of the gear wheel. |


|
private |
Create a gear joint between two of the revolute joints in m_stdJoint.
| i | Index of first revolute joint and body attached to it. |
| j | Index of second revolute joint and body attached to it. |
| r | Gear ratio. |

|
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.
| x | X coordinate in Physics World units. |
| y | Y coordinate in Physics World units. |


|
private |
Create the square gears and push them onto the gear list.
| x | X coordinate in Physics World units. |
| y | Y coordinate in Physics World units. |

