Ball and Spring Toy
Game Physics with Bespoke Code
Loading...
Searching...
No Matches
CObjectManager Class Reference

The object manager. More...

#include <ObjectManager.h>

Inheritance diagram for CObjectManager:
Collaboration diagram for CObjectManager:

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

Constructor & Destructor Documentation

◆ ~CObjectManager()

CObjectManager::~CObjectManager ( )

Call CObjectManager::clear to delete everything.

Here is the call graph for this function:

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.

Here is the caller graph for this function:

◆ create() [1/2]

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

Create a point and append it to the point list.

Parameters
tSprite type.
vPosition.
rRestitution.
Returns
Pointer to the created point.
Here is the caller graph for this function:

◆ create() [2/2]

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

Create a spring and append it to the spring list.

Parameters
tSprite type.
v0Point at one end of spring.
v1Point at other end of spring.
rRestitution.
Returns
Pointer to the created spring.

◆ CreateBody()

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.

Here is the caller graph for this function:

◆ DeliverImpulse()

void CObjectManager::DeliverImpulse ( float m)

Deliver an impulse to the two current bodies.

Parameters
mImpulse magnitude.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Draw()

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.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Move()

void CObjectManager::Move ( )

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Relax()

void CObjectManager::Relax ( UINT n)

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

Parameters
nNumber of iterations to perform.
Here is the call graph for this function:
Here is the caller graph for this function: