![]() |
Collision Math Toy
Ian Parberry's "Introduction to Game Physics"
|
The object manager. More...
#include <ObjectManager.h>
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. | |
CGate * | m_pGate = nullptr |
Pointer to gate. | |
CAabb2D | m_cAABB |
AABB for playable part of the game world. | |
UINT | m_nLostBalls = 0 |
Number of lost balls. | |
CQuadTree * | m_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 CRenderer * | m_pRenderer = nullptr |
Pointer to the renderer. | |
static CObjectManager * | m_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. | |
A collection of all of the game objects.
CObjectManager::~CObjectManager | ( | ) |
The destructor clears the shape lists, which destructs all of the shapes in them.
CShape * CObjectManager::AddShape | ( | CShapeDesc * | sd, |
const CObjDesc & | od | ||
) |
Creates a new shape and pushes a contact descriptor for that shape into the shape list.
sd | Pointer to a shape descriptor. |
od | Object descriptor. |
|
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.
v | Array of pointers to vectors of static, kinematic, and dynamic shapes. |
|
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.
void CObjectManager::clear | ( | ) |
Delete all dynamic shapes and objects.
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.).
|
private |
Draw all AABBs in the AABB list.
|
private |
Line segments get special treatment because they are drawn using CRenderer's DrawLine function instead of its Draw function.
p | Pointer to an object. |
|
private |
Draw all sectors in the sector list.
|
private |
Draw all tangents in the tangent list.
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.
UINT CObjectManager::GetCollisionCnt | ( | ) |
Get the number of collisions since the count was last reset and reset count to zero.
UINT CObjectManager::GetCollisionTestCnt | ( | ) |
Get the number of collision tests since the count was last reset and reset count to zero.
UINT CObjectManager::GetLostBallCnt | ( | ) | const |
Reader function for the number of lost balls, which is defined to be those that have strayed outside m_cAABB.
UINT CObjectManager::GetOverlapCnt | ( | ) | const |
Reader function for the overlap count.
UINT CObjectManager::GetQTLeafCount | ( | ) | const |
Reader function for the number of leaves in the quadtree.
UINT CObjectManager::GetQTLevelCount | ( | ) | const |
Reader function for the number of levels in the quadtree.
UINT CObjectManager::GetQTMaxLeafSize | ( | ) | const |
Reader function for the maximum number of objects in a leaf.
Vector2 CObjectManager::GetQTNodeArea | ( | ) | const |
Reader function for the width and height of the area covered by each quadtree leaf.
UINT CObjectManager::GetQTNodeCount | ( | ) | const |
Reader function for the number of nodes in the quadtree including both leaves and non-leaves.
void CObjectManager::MakeLineSeg | ( | const Vector2 & | p0, |
const Vector2 & | p1, | ||
eSound | snd | ||
) |
Make a compound shape consisting of a line segment and two guard points.
p0 | One end of line segment. |
p1 | The other end of line segment. |
snd | Sound to be played on collision. |
|
private |
Create a new shape and a contact descriptor for that shape.
sd | Pointer to a shape descriptor. |
od | An object descriptor. |
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.
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.
void CObjectManager::move | ( | ) |
Move all dynamic and kinematic shapes and perform broad phase collision and response.
|
private |
Check whether a shape collides with a dynamic circle and make appropriate response.
pShape | Pointer to a shape. |
pCirc | Pointer to dynamic circle. |
void CObjectManager::ResetQuadTree | ( | UINT | n | ) |
Reset the quadtree to a given number of levels.
n | Number of levels for the new quadtree. |
void CObjectManager::RotateKinematic | ( | bool | b | ) |
Set the rotating flag in all kinematic shapes.
b | true for rotating, false for not rotating. |
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.