![]() |
Box2D Joint Toy
Game Physics with a 2D Physics Engine
|
Newton's cradle. More...
#include <NewtonsCradle.h>


Public Member Functions | |
| CNewtonsCradle () | |
| Constructor. | |
| ~CNewtonsCradle () | |
| Destructor. | |
| void | Move () |
| Swivel Isaac Newton's eyeballs. | |
| void | Draw () |
| Draw level. | |
| void | Action () |
| Reverse motor. | |
Public Member Functions inherited from CLevel | |
| CLevel (eSprite) | |
| virtual | ~CLevel () |
| Default constructor. | |
Private Member Functions | |
| void | CreateBall (float, float) |
| Create a ball. | |
| void | Create () |
| Create all balls. | |
| void | ResetBalls () |
| Reset all balls to initial conditions. | |
| b2Body * | CreateCradle (float, float) |
| Create the cradle. | |
Private Attributes | |
| CSirIsaacNewton * | m_pIsaac = nullptr |
| Isaac Newton caricature. | |
| const UINT | m_nNumBalls = 6LLU |
| Number of balls. | |
| UINT | m_nBallsToMove = 1LLU |
| Number of balls in to move at a time. | |
| bool | m_bBallsStillMoving = false |
| Flag for moving balls. | |
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. | |
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 | ( | ) |
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.

|
virtual |
If there are balls still moving, then reset them to the initial conditions. Otherwise, deliver an impulse to the leftmost balls, incrementing the number affected each time this function is called when the balls are not moving. The balls are considered moving if and impulse was applied the last time this function is called. This function assumes that the balls were created in left-to-right order, that is, they appear in the object list from left to right, with m_stdObject[0] being the leftmost ball.
Reimplemented from CLevel.

|
private |
Create the cradle, the balls, their joints, and their lines.


|
private |
Create a ball bearing object and Physics World body.
| x | X coordinate in Physics World units. |
| y | Y coordinate in Physics World units. |


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

|
virtual |
Draw the background, the objects in this level, and the Isaac Newton head.
Reimplemented from CLevel.

|
virtual |
Move Isaac Newton's eyeballs swivel in the direction of the last ball in the ball list, which is hopefully the rightmost one.
Reimplemented from CLevel.

|
private |
Reset the balls, their lines, and their joints to the initial conditions.

