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

A pair of interlocking nautilus gears. More...

#include <NautilusGear.h>

Inheritance diagram for CNautilusGear:
Collaboration diagram for CNautilusGear:

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
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 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.

Constructor & Destructor Documentation

◆ CNautilusGear()

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.

Here is the call graph for this function:

◆ ~CNautilusGear()

CNautilusGear::~CNautilusGear ( )

Null destructor.

Member Function Documentation

◆ Action()

void CNautilusGear::Action ( )
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.

◆ CreateBase()

b2Body * CNautilusGear::CreateBase ( float x,
float y )
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.

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 * CNautilusGear::CreateGear ( float x,
float y,
eSprite t,
b2BodyType bt )
private

Create the object and physics body for a gear wheel.

Parameters
xX coordinate in Physics World units.
yY coordinate in Physics World units.
tSprite type of the gear wheel.
btBox2D body type.
Returns
Pointer to the gear body in Physics World.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Move()

void CNautilusGear::Move ( )
virtual

Make the right gear rotate in synchrony with the left gear. Assumes that the left gear was created first.

Reimplemented from CLevel.