Box2D Joint Toy
Ian Parberry's "Introduction to Game Physics"
Public Member Functions | Private Member Functions | Private Attributes | List of all members
CNewtonsCradle Class Reference

Newton's cradle. More...

#include <NewtonsCradle.h>

Inheritance diagram for CNewtonsCradle:
CCommon

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.
 
CSirIsaacNewtonm_pIsaac = nullptr
 Isaac Newton caricature.
 

Additional Inherited Members

- Static Protected Attributes inherited from CCommon
static b2World * m_pPhysicsWorld = nullptr
 Pointer to Box2D Physics World.
 
static CRendererm_pRenderer = nullptr
 Pointer to the renderer.
 
static CObjectManagerm_pObjectManager = nullptr
 Pointer to the object manager.
 
static CWindmillm_pWindmill = nullptr
 Pointer to windmill.
 
static CGearm_pGear = nullptr
 Pointer to gear system.
 
static CNautilusGearm_pNautilusGear = nullptr
 Pointer to Nautilus gear system.
 
static CRackAndPinionm_pRackAndPinion = nullptr
 Pointer to rack-and-pinion.
 
static CCarm_pCar = nullptr
 Pointer to car.
 
static CRampm_pRamp = nullptr
 Pointer to ramp.
 
static CNewtonsCradlem_pNewtonsCradle = nullptr
 Pointer to Newton's Cradle.
 
static CPulleym_pPulley = nullptr
 Pointer to pulley system.
 
static eLevel m_eCurLevel = eLevel::Windmill
 Current level.
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ CNewtonsCradle()

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.

Parameters
xX coordinate of the center of the cradle in Physics World.
nNumber of balls required.

◆ ~CNewtonsCradle()

CNewtonsCradle::~CNewtonsCradle ( )

Denstructor.

Destructor.

Member Function Documentation

◆ CreateBall()

b2Body * CNewtonsCradle::CreateBall ( float  x,
float  y 
)
private

Create a ball.

Create a ball bearing object and Physics World body.

Parameters
xX coordinate in Physics World units.
yY coordinate in Physics World units.

◆ CreateCradle()

b2Body * CNewtonsCradle::CreateCradle ( float  x,
float  y 
)
private

Create the cradle.

The cradle except for the bar at the top of the cradle.

Parameters
xX coordinate in Physics World units.
yY coordinate in Physics World units.

◆ DeliverImpulse()

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.

Parameters
nNumber of balls that get the impulse.

◆ move()

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.