Ball and Spring Toy
Ian Parberry's "Introduction to Game Physics"
Public Member Functions | Private Attributes | List of all members
CObjectManager Class Reference

The object manager. More...

#include <ObjectManager.h>

Inheritance diagram for CObjectManager:
CCommon

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...
 
CPointcreate (eSprite, const Vector2 &, float)
 Create a point. More...
 
CSpringcreate (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.
 
CBodym_pCurBody0 = nullptr
 The first body.
 
CBodym_pCurBody1 = nullptr
 The second body.
 

Additional Inherited Members

- Static Protected Attributes inherited from CCommon
static CRendererm_pRenderer = nullptr
 Pointer to the renderer.
 
static CObjectManagerm_pObjectManager = nullptr
 Pointer to the object manager.
 
static eBody m_eCurrentBody = (eBody)0
 Current body type.
 

Detailed Description

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.

Member Function Documentation

◆ clear()

void CObjectManager::clear ( )

Clear all points from the point list and springs from the spring list, then delete the current bodies.

◆ create() [1/2]

CPoint * CObjectManager::create ( eSprite  t,
const Vector2 &  v,
float  r 
)

Create a point and add it to the point list.

Parameters
tSprite type.
vPosition.
rRestitution.

◆ create() [2/2]

CSpring * CObjectManager::create ( eSprite  t,
CPoint v0,
CPoint v1,
float  r 
)

Create a spring and add it to the spring list.

Parameters
tSprite type.
v0Point at one end of spring.
v1Point at other end of spring.
rRestitution.

◆ CreateBody()

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.

Parameters
bBody type.

◆ DeliverImpulse()

void CObjectManager::DeliverImpulse ( float  m)

Deliver an impulse to the two current bodies.

◆ draw()

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.

◆ move()

void CObjectManager::move ( )

Move the points in the point list and perform Gauss-Seidel relaxation on the springs in the spring list.

◆ Relax()

void CObjectManager::Relax ( UINT  n)

Perform several iterations of Gauss-Seidel relaxation on the springs in the spring list.

Parameters
nNumber of iterations to perform.