![]() |
Box2D Joint Toy
Ian Parberry's "Introduction to Game Physics"
|
Newton's cradle. More...
#include <NewtonsCradle.h>
Public Member Functions | |
CNewtonsCradle (float, UINT) | |
Constructor. More... | |
~CNewtonsCradle () | |
Denstructor. More... | |
void | DeliverImpulse (UINT) |
Deliver impulse. More... | |
void | move () |
Swivel Isaac Newton's eyeballs. More... | |
void | DrawIsaac () |
Draw Isaac Newton. | |
Private Member Functions | |
b2Body * | CreateBall (float, float) |
Create a ball. More... | |
b2Body * | CreateCradle (float, float) |
Create the cradle. More... | |
Private Attributes | |
std::vector< b2Body * > | m_stdBallList |
Pointers to Physics World bodies of the balls. | |
CSirIsaacNewton * | m_pIsaac = nullptr |
Isaac Newton caricature. | |
Additional Inherited Members | |
![]() | |
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. | |
Newton's cradle.
Newton's Cradle has a bunch of balls on strings hanging from a cradle. It's a common executive toy. For those in the know, it demonstrates the conservation of momentum and energy in collisions.
CNewtonsCradle::CNewtonsCradle | ( | float | x, |
UINT | n | ||
) |
Constructor.
Create the cradle, the balls, the distance joints connecting the former to the latter, and the line objects that represent them. The balls are created in left-to-right order.
x | X coordinate of the center of the cradle in Physics World. |
n | Number of balls required. |
CNewtonsCradle::~CNewtonsCradle | ( | ) |
Denstructor.
Destructor.
|
private |
Create a ball.
Create a ball bearing object and Physics World body.
x | X coordinate in Physics World units. |
y | Y coordinate in Physics World units. |
|
private |
Create the cradle.
The cradle except for the bar at the top of the cradle.
x | X coordinate in Physics World units. |
y | Y coordinate in Physics World units. |
void CNewtonsCradle::DeliverImpulse | ( | UINT | n | ) |
Deliver impulse.
Deliver an impulse to the n leftmost balls. This function assumes that the balls were created in left-to-right order.
n | Number of balls that get the impulse. |
void CNewtonsCradle::move | ( | ) |
Swivel Isaac Newton's eyeballs.
Move Isaac Newton's eyeballs seivel in the direction of the last ball in the ball list, which is hopefully the rightmost one.