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


Public Member Functions | |
| CNautilusGear () | |
| Constructor. | |
| ~CNautilusGear () | |
| Destructor. | |
| void | Move () |
| Move gears in synchrony. | |
| void | Action () |
| Reverse gears. | |
Public Member Functions inherited from CLevel | |
| CLevel (eSprite) | |
| virtual | ~CLevel () |
| Default constructor. | |
| virtual void | Draw () |
| Draw objects in level. | |
Private Member Functions | |
| b2Body * | CreateBase (float, float) |
| Create invisible base. | |
| b2Body * | CreateGear (float, float, eSprite, b2BodyType) |
| Create gear. | |
Private Attributes | |
| b2RevoluteJoint * | m_pJoint = nullptr |
| Ptr to left gear revolute joint. | |
| const float | a = 98.0f |
| Maximum radius in Render World units, from image. | |
| const float | b = 34.0f |
| Minimum radius in Render World units, from image. | |
| const float | d = 0.5f*logf(a/b)/b2_pi |
| Denominator for computing orientation. | |
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. | |
A nautilus gear is a gear in the shape of a nautilus shell. This level will animate a pair of nautilus gears. The left gear has a revolute joint with a motor. The right gear has variable speed, so it cannot be animated by Box2D. We have to animate it ourselves which means doing a little math.
| CNautilusGear::CNautilusGear | ( | ) |
Create gear wheel objects and physics bodies, with a revolute joint between the left gear and the background. Store a pointer to the revolute joint in m_pJoint so that the motor speed and direction can be changed.

| CNautilusGear::~CNautilusGear | ( | ) |
Null destructor.
|
virtual |
Reverse the gears by setting the motor speed on the revolute joint for the left gear. Assumes that m_pJoint contains a pointer to the revolute joint.
Reimplemented from CLevel.
|
private |
Create an invisible base object and phsyics body 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 the object and physics body for a gear wheel.
| x | X coordinate in Physics World units. |
| y | Y coordinate in Physics World units. |
| t | Sprite type of the gear wheel. |
| bt | Box2D body type. |


|
virtual |
Make the right gear rotate in synchrony with the left gear. Assumes that the left gear was created first.
Reimplemented from CLevel.