![]() |
Ball and Spring Toy
Game Physics with Bespoke Code
|
The object manager. More...
#include <ObjectManager.h>


Public Member Functions | |
| ~CObjectManager () | |
| Destructor. | |
| void | Clear () |
| Reset to initial conditions. | |
| void | Move () |
| Move all objects. | |
| void | Draw () |
| Draw all objects. | |
| void | DeliverImpulse (float) |
| Apply impulse to the current bodies. | |
| void | CreateBody () |
| Create a pair of bodies. | |
| CPoint * | create (eSprite, const Vector2 &, float) |
| Create a point. | |
| CSpring * | create (eSprite, CPoint *, CPoint *, float) |
| Create a spring. | |
| void | Relax (UINT) |
| Gauss-Seidel relaxation. | |
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 Protected Attributes inherited from CCommon | |
| static Sage::CSpriteRenderer * | 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.
| CObjectManager::~CObjectManager | ( | ) |
Call CObjectManager::clear to delete everything.

| 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 append it to the point list.
| t | Sprite type. |
| v | Position. |
| r | Restitution. |

Create a spring and append 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 | ( | ) |
Create a pair of bodies, one springy and one sticky, except for the case of the ragdoll in which we only create one body. Gets the body type from m_eCurrentBody.

| void CObjectManager::DeliverImpulse | ( | float | m | ) |
Deliver an impulse to the two current bodies.
| m | Impulse magnitude. |


| void CObjectManager::Draw | ( | ) |
Draw the current bodies using Painter's Algorithm. The background is drawn first, then bodies 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 the point and spring lists, but that would very probably 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 some iterations of Gauss-Seidel relaxation on the springs in the spring list.
| n | Number of iterations to perform. |

