Collision Math Toy
Ian Parberry's "Introduction to Game Physics"
Public Member Functions | Private 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. More...
 
CShape * AddShape (CShapeDesc *, const CObjDesc &)
 Add shape. More...
 
void clear ()
 Clear all dynamic shapes. More...
 
void move ()
 Move all objects. More...
 
void Draw ()
 Draw all objects. More...
 
void ResetQuadTree (UINT)
 Reset the quadtree. More...
 
void UpdateQuadtree ()
 Update the quadtree. More...
 
void MakeWorldEdges ()
 Create shapes for world edges. More...
 
void MakeShapes ()
 Create shapes. More...
 
void MakeLineSeg (const Vector2 &, const Vector2 &, eSound)
 Make static line segment with guard points. More...
 
void RotateKinematic (bool)
 Start or stop kinematic shapes rotating. More...
 
UINT GetCollisionCnt ()
 Get number of collisions since last called. More...
 
UINT GetCollisionTestCnt ()
 Get number of collision tests since last called. More...
 
UINT GetAABBTestCnt ()
 Get number of AABB tests since last called. More...
 
UINT GetLostBallCnt () const
 Get number of lost balls. More...
 
UINT GetOverlapCnt () const
 Get number of overlapped balls. More...
 
UINT GetQTLevelCount () const
 Get quadtree level count. More...
 
UINT GetQTNodeCount () const
 Get quadtree node count. More...
 
UINT GetQTLeafCount () const
 Get quadtree leaf count. More...
 
Vector2 GetQTNodeArea () const
 Get quadtree leaf area. More...
 
UINT GetQTMaxLeafSize () const
 Get maximum number of objects in a leaf. More...
 

Private Member Functions

CShape * MakeShape (CShapeDesc *, const CObjDesc &)
 Make a shape. More...
 
void BroadPhase (std::vector< CShape * >[])
 Broad phase collision detection and response, brute force. More...
 
void BroadPhaseWithQuadtree ()
 Broad phase collision detection and response with quadtree. More...
 
bool NarrowPhase (CShape *, CDynamicCircle *)
 Narrow phase collision detection and response. More...
 
void DrawObject (CObject *)
 Draw an object. More...
 
void DrawAABBs ()
 Draw AABBs. More...
 
void DrawSectors ()
 Draw arc sectors. More...
 
void DrawTangents ()
 Draw tangents on line segments and arcs. More...
 

Private Attributes

std::vector< CShape * > m_stdShapes [(UINT) eMotion::Size]
 Array of lists of shapes.
 
std::vector< CObject * > m_stdObjects
 Object list.
 
CGatem_pGate = nullptr
 Pointer to gate.
 
CAabb2D m_cAABB
 AABB for playable part of the game world.
 
UINT m_nLostBalls = 0
 Number of lost balls.
 
CQuadTreem_pQuadTree = nullptr
 Quadtree for collision detection and response.
 
UINT m_nCollisionCnt = 0
 Number of collisions.
 
UINT m_nCloseCollisionCnt = 0
 Number of close collisions.
 
UINT m_nCollisionTestCnt = 0
 Number of collision tests.
 
UINT m_nAABBTestCnt = 0
 AABB test count.
 
UINT m_nOverlapCnt = 0
 Number of overlaps.
 

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 LParticleEngine2D * m_pFrontParticleEngine = nullptr
 Pointer to front particle engine.

 
static LParticleEngine2D * m_pBackParticleEngine = nullptr
 Pointer to front particle engine.
 
static bool m_bShowTrack = false
 Show trail of breadcrumbs.
 
static bool m_bShowReticles = false
 Show reticle at hit point.
 
static bool m_bShowImpacts = false
 Draw dots at collision points.
 
static bool m_bShowArrows = false
 Draw arrows for velocity vectors.
 
static bool m_bShowTangents = false
 Draw arrows for tangents.
 
static bool m_bShowSectors = false
 Draw arc sentinels and normals.
 
static bool m_bShowAABBs = false
 Draw shape AABBs.
 
static bool m_bShowLights = false
 Light up shapes on collision.
 
static bool m_bRotate = false
 Rotate kinematic shapes.
 
static bool m_bLaunch = false
 Launch a ball.
 
static bool m_bMute = false
 Mute the sound.
 
static float m_fNextBallScale = 0.5f
 Scale factor for ball size.
 
static int m_nMIterationsInit = 4
 Initial number of motion iterations.
 
static int m_nCIterationsInit = 6
 Initial number of collision iterations.
 
static int m_nMIterations = CCommon::m_nMIterationsInit
 Current number of motion iterations.
 
static int m_nCIterations = CCommon::m_nCIterationsInit
 Current number of collision iterations.
 
static bool m_bUseQuadTree = false
 Whether to use a quadtree.
 
static HWND m_hDlg = nullptr
 Control dialog box handle.
 
static float m_fLoad = 0.0f
 Processor load.
 
static float m_fLaunchSpeed = 1000.0f
 Speed at which the next ball will be launched.
 
static int m_nDesiredLaunchCnt = 1
 Number of balls to launch at next multilaunch.
 
static int m_nLaunched = 0
 Number of balls launched in current multilaunch.
 
static bool m_bMultiLaunch = false
 Whether launching multiple balls.
 
static int m_nBallsLaunched = 0
 Number of balls in play.
 
static float m_fFrequency = 60.0f*m_nMIterations
 Frequency, number of physics iterations per second.
 

Detailed Description

A collection of all of the game objects.

Constructor & Destructor Documentation

◆ ~CObjectManager()

CObjectManager::~CObjectManager ( )

The destructor clears the shape lists, which destructs all of the shapes in them.

Member Function Documentation

◆ AddShape()

CShape * CObjectManager::AddShape ( CShapeDesc *  sd,
const CObjDesc od 
)

Creates a new shape and pushes a contact descriptor for that shape into the shape list.

Parameters
sdPointer to a shape descriptor.
odObject descriptor.
Returns
Pointer to created shape.

◆ BroadPhase()

void CObjectManager::BroadPhase ( std::vector< CShape * >  v[])
private

Do collision detection for all dynamic shapes against all static and kinematic shapes, and against all dynamic shapes that appear after it in the dynamic shape list.

Parameters
vArray of pointers to vectors of static, kinematic, and dynamic shapes.

◆ BroadPhaseWithQuadtree()

void CObjectManager::BroadPhaseWithQuadtree ( )
private

Broad phase collision detection and response using a quadtree. Assembles a vector of pointers to quadtree leaves that have at least a dynamic shape and one other shape in them, then does broad phase on the shapes in those leaves.

◆ clear()

void CObjectManager::clear ( )

Delete all dynamic shapes and objects.

◆ Draw()

void CObjectManager::Draw ( )

Draw the game objects using Painter's Algorithm. The background is drawn first, then the game objects are asked to draw themselves in the order that they are in the object list. That is, they are drawn from back to front. Draw everything, the tangents, the sectors, the AABBs, the shapes, the tracks, the reticles, the impact points (etc.).

◆ DrawAABBs()

void CObjectManager::DrawAABBs ( )
private

Draw all AABBs in the AABB list.

◆ DrawObject()

void CObjectManager::DrawObject ( CObject p)
private

Line segments get special treatment because they are drawn using CRenderer's DrawLine function instead of its Draw function.

Parameters
pPointer to an object.

◆ DrawSectors()

void CObjectManager::DrawSectors ( )
private

Draw all sectors in the sector list.

◆ DrawTangents()

void CObjectManager::DrawTangents ( )
private

Draw all tangents in the tangent list.

◆ GetAABBTestCnt()

UINT CObjectManager::GetAABBTestCnt ( )

Get the number of AABB intersection tests since the count was last reset and reset count to zero. This includes both ball-to-ball collisions plus the extra overhead of AABB intersection tests from managing the quadtree.

Returns
Number of tests.

◆ GetCollisionCnt()

UINT CObjectManager::GetCollisionCnt ( )

Get the number of collisions since the count was last reset and reset count to zero.

Returns
Number of collisions.

◆ GetCollisionTestCnt()

UINT CObjectManager::GetCollisionTestCnt ( )

Get the number of collision tests since the count was last reset and reset count to zero.

Returns
Number of tests.

◆ GetLostBallCnt()

UINT CObjectManager::GetLostBallCnt ( ) const

Reader function for the number of lost balls, which is defined to be those that have strayed outside m_cAABB.

Returns
Number of lost balls.

◆ GetOverlapCnt()

UINT CObjectManager::GetOverlapCnt ( ) const

Reader function for the overlap count.

Returns
Number of overlapped balls.

◆ GetQTLeafCount()

UINT CObjectManager::GetQTLeafCount ( ) const

Reader function for the number of leaves in the quadtree.

Returns
Number of quadtree leaves.

◆ GetQTLevelCount()

UINT CObjectManager::GetQTLevelCount ( ) const

Reader function for the number of levels in the quadtree.

Returns
Numer of quadtree levels.

◆ GetQTMaxLeafSize()

UINT CObjectManager::GetQTMaxLeafSize ( ) const

Reader function for the maximum number of objects in a leaf.

Returns
Maximum over all leaves of the number of objects in it.

◆ GetQTNodeArea()

Vector2 CObjectManager::GetQTNodeArea ( ) const

Reader function for the width and height of the area covered by each quadtree leaf.

Returns
Quadtree leaf area.

◆ GetQTNodeCount()

UINT CObjectManager::GetQTNodeCount ( ) const

Reader function for the number of nodes in the quadtree including both leaves and non-leaves.

Returns
Number of quadtree nodes.

◆ MakeLineSeg()

void CObjectManager::MakeLineSeg ( const Vector2 &  p0,
const Vector2 &  p1,
eSound  snd 
)

Make a compound shape consisting of a line segment and two guard points.

Parameters
p0One end of line segment.
p1The other end of line segment.
sndSound to be played on collision.

◆ MakeShape()

CShape * CObjectManager::MakeShape ( CShapeDesc *  sd,
const CObjDesc od 
)
private

Create a new shape and a contact descriptor for that shape.

Parameters
sdPointer to a shape descriptor.
odAn object descriptor.
Returns
Pointer to a new contact descriptor.

◆ MakeShapes()

void CObjectManager::MakeShapes ( )

Make the static shapes for the things in the world. As with most physics code, this function is long and tedious, but it's important to get the details right.

◆ MakeWorldEdges()

void CObjectManager::MakeWorldEdges ( )

Make the static shapes for the world boundaries. As with most physics code, this function is long and tedious, but it's important to get the details right.

◆ move()

void CObjectManager::move ( )

Move all dynamic and kinematic shapes and perform broad phase collision and response.

◆ NarrowPhase()

bool CObjectManager::NarrowPhase ( CShape *  pShape,
CDynamicCircle *  pCirc 
)
private

Check whether a shape collides with a dynamic circle and make appropriate response.

Parameters
pShapePointer to a shape.
pCircPointer to dynamic circle.

◆ ResetQuadTree()

void CObjectManager::ResetQuadTree ( UINT  n)

Reset the quadtree to a given number of levels.

Parameters
nNumber of levels for the new quadtree.

◆ RotateKinematic()

void CObjectManager::RotateKinematic ( bool  b)

Set the rotating flag in all kinematic shapes.

Parameters
btrue for rotating, false for not rotating.

◆ UpdateQuadtree()

void CObjectManager::UpdateQuadtree ( )

Update the quadtree to account for kinematic and dynamic shapes dynamic. It clears the kinematic and dynamic shapes out of the quadtree (since their positions and/or orientations have changed) and re-inserts them.