![]() |
Ball and Spring Toy
Ian Parberry's "Introduction to Game Physics"
|
The object manager. More...
#include <ObjectManager.h>
Public Member Functions | |
~CObjectManager () | |
Destructor. | |
void | clear () |
Reset to initial conditions. More... | |
void | move () |
Move all objects. More... | |
void | draw () |
Draw all objects. More... | |
void | DeliverImpulse (float) |
Apply impulse to the current bodies. More... | |
void | CreateBody (eBody) |
Create a pair of bodies. More... | |
CPoint * | create (eSprite, const Vector2 &, float) |
Create a point. More... | |
CSpring * | create (eSprite, CPoint *, CPoint *, float) |
Create a spring. More... | |
void | Relax (UINT) |
Gauss-Seidel relaxation. More... | |
Private Attributes | |
std::vector< CPoint * > | m_stdPt |
Point list. | |
std::vector< CSpring * > | m_stdSpr |
Spring list. | |
CBody * | m_pCurBody0 = nullptr |
The first body. | |
CBody * | m_pCurBody1 = nullptr |
The second body. | |
Additional Inherited Members | |
![]() | |
static CRenderer * | m_pRenderer = nullptr |
Pointer to the renderer. | |
static CObjectManager * | m_pObjectManager = nullptr |
Pointer to the object manager. | |
static eBody | m_eCurrentBody = (eBody)0 |
Current body type. | |
A collection of all of the game objects. Note that while bodies maintain a local list of pointers to their points and springs so that draw order can be maintained, the object manager keeps lists of pointers to all of the points and springs from all of the bodies so it can easily move the points and perform Gauss-Seidel relaxation on the springs. Those operations do not depend upon whether those points and springs are in bodies.
void CObjectManager::clear | ( | ) |
Clear all points from the point list and springs from the spring list, then delete the current bodies.
Create a point and add it to the point list.
t | Sprite type. |
v | Position. |
r | Restitution. |
Create a spring and add it to the spring list.
t | Sprite type. |
v0 | Point at one end of spring. |
v1 | Point at other end of spring. |
r | Restitution. |
void CObjectManager::CreateBody | ( | eBody | b | ) |
Create a pair of bodies, one springy and one sticky, except for the case of the ragdoll in which we only create one body.
b | Body type. |
void CObjectManager::DeliverImpulse | ( | float | m | ) |
Deliver an impulse to the two current bodies.
void CObjectManager::draw | ( | ) |
Draw the current bodies using Painter's Algorithm. The background is drawn first, then bodies objects are asked to draw themselves in the order in which they were created. That is, they are drawn from back to front. We could draw the balls and springs from CObjectManager's point and spring lists, but that would mess up the draw order. We have to make sure that each body's points and springs are drawn more or less together.
void CObjectManager::move | ( | ) |
Move the points in the point list and perform Gauss-Seidel relaxation on the springs in the spring list.
void CObjectManager::Relax | ( | UINT | n | ) |
Perform several iterations of Gauss-Seidel relaxation on the springs in the spring list.
n | Number of iterations to perform. |