![]() |
Box2D Joint Toy
Ian Parberry's "Introduction to Game Physics"
|
The pulley class. More...
#include <Pulley.h>
Public Member Functions | |
| CPulley (float, float, float) | |
| Constructor. More... | |
| void | move () |
| Rotate the pulley wheels. More... | |
| void | CreateElephant () |
| Create an elephant. More... | |
| bool | DeleteElephant () |
| Delete an elephant. More... | |
Private Member Functions | |
| b2Body * | CreateWheel (float, float) |
| Create a pulley wheel. More... | |
| b2Body * | CreateCrate (float, float) |
| Create the elephant's crate. More... | |
| b2Body * | CreateObject (const b2Vec2 &, float, eSprite) |
| Create an object. More... | |
Private Attributes | |
| b2PulleyJoint * | m_pJoint = nullptr |
| Pointer to the pulley joint. | |
| float | m_fJointLenA = 0 |
| Length of left side of pulley. | |
| b2Body * | m_pWheel0 = nullptr |
| Pointer to the left pulley wheel. | |
| b2Body * | m_pWheel1 = nullptr |
| Pointer to the right pulley wheel. | |
| float | m_fWheelRad = 1 |
| Pulley wheel radius. | |
| b2Vec2 | m_vElephantSpawnPt |
| Elephant spawn point. | |
Additional Inherited Members | |
Static Protected Attributes inherited from CCommon | |
| static b2World * | m_pPhysicsWorld = nullptr |
| Pointer to Box2D Physics World. | |
| static CRenderer * | m_pRenderer = nullptr |
| Pointer to the renderer. | |
| static CObjectManager * | m_pObjectManager = nullptr |
| Pointer to the object manager. | |
| static CWindmill * | m_pWindmill = nullptr |
| Pointer to windmill. | |
| static CGear * | m_pGear = nullptr |
| Pointer to gear system. | |
| static CNautilusGear * | m_pNautilusGear = nullptr |
| Pointer to Nautilus gear system. | |
| static CRackAndPinion * | m_pRackAndPinion = nullptr |
| Pointer to rack-and-pinion. | |
| static CCar * | m_pCar = nullptr |
| Pointer to car. | |
| static CRamp * | m_pRamp = nullptr |
| Pointer to ramp. | |
| static CNewtonsCradle * | m_pNewtonsCradle = nullptr |
| Pointer to Newton's Cradle. | |
| static CPulley * | m_pPulley = nullptr |
| Pointer to pulley system. | |
| static eLevel | m_eCurLevel = eLevel::Windmill |
| Current level. | |
The pulley class.
A pair of objects connected by a pulley joint, with a pair of pulley wheels that are animated in code.
| CPulley::CPulley | ( | float | x, |
| float | y, | ||
| float | w | ||
| ) |
Constructor.
| x | X coordinate in Physics World units. |
| y | Y coordinate in Physics World units. |
| w | Pulley wheel horizontal separation in Physics World units. |
|
private |
Create the elephant's crate.
The bucket is the thing on the left that the elephant falls into. It consists of a left side, a right side, and a bottom, all of which are rectangles.
| x | X coordinate in Physics World units. |
| y | Y coordinate in Physics World units. |
| void CPulley::CreateElephant | ( | ) |
Create an elephant.
Create an elephant at its spawn point offset by a small pseudorandom amount to make the crate swing a bot.
|
private |
Create an object.
Create an object, used for the safe and the elephant.
| v | Position in Physics World. |
| d | Object density. |
| t | Type of object to be created. |
|
private |
Create a pulley wheel.
The pulley wheels are going to be static objects that we rotate ourselves depending on the positions of the objects that the pulley is attached to.
| x | X coordinate in Physics World units. |
| y | Y coordinate in Physics World units. |
| bool CPulley::DeleteElephant | ( | ) |
Delete an elephant.
Delete the first elephant, if there is one.
| void CPulley::move | ( | ) |
Rotate the pulley wheels.
Animate the pulley wheels by setting their orientations to reflect the amount of rope that has gone over them.