The 8-ball Pool End Game
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 ()
 Constructor.
 
 ~CObjectManager ()
 Destructor.
 
void create (eSprite, const Vector2 &)
 Create new object. More...
 
void clear ()
 Reset to initial conditions. More...
 
void move ()
 Move all objects. More...
 
void Draw ()
 Draw all objects. More...
 
void ResetImpulseVector ()
 Reset the Impulse Vector. More...
 
void AdjustImpulseVector (float)
 Adjust the Impulse Vector. More...
 
void AdjustCueBall (float)
 Move cue-ball up or down. More...
 
void Shoot ()
 Shoot the cue ball. More...
 
bool BallDown ()
 Is a ball down in a pocket? More...
 
bool CueBallDown ()
 Is the cue ball down in a pocket? More...
 
bool AllStopped ()
 Have all balls stopped moving? More...
 

Private Member Functions

void BroadPhase ()
 Ball, rail, and pocket collision response for all balls. More...
 
void NarrowPhase (CObject *, CObject *)
 Ball collision response for two balls. More...
 
bool BallCollide (CObject *, CObject *, float &)
 Ball collision response for two balls. More...
 
void RailCollide (CObject *)
 Collision response for ball with rail. More...
 
void PocketCollide (CObject *)
 Collision response for ball with pocket. More...
 

Private Attributes

LParticleDesc2D m_cPDesc0
 Particle descriptor for balls in step mode.
 
LParticleDesc2D m_cPDesc1
 Particle descriptor for collisions in step mode.
 
LParticleDesc2D m_cPDesc2
 Particle descriptor for collisions in real-time mode.
 
CObjectm_pCueBall = nullptr
 Cue ball object pointer.
 
CObjectm_p8Ball = nullptr
 8 ball object pointer.
 
float m_fCueAngle = 0
 Cue ball impulse angle.
 
bool m_bDrawImpulseVector = true
 Whether to draw the impulse vector.
 

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_pParticleEngine = nullptr
 Pointer to particle engine.
 
static bool m_bShowCollisions = false
 Show ball positions at TOI.
 
static bool m_bStepMode = false
 Is in step mode.
 
static bool m_bStep = false
 Step flag.
 
static float m_fXMargin = 78.0f
 Horizontal margin.
 
static float m_fYMargin = 64.0f
 Vertical margin.
 
static Vector2 m_vMargin = Vector2(m_fXMargin, m_fYMargin)
 Margins.
 
static Vector2 m_vTopLPocket = Vector2(71, 478)
 Position of top left pocket.
 
static Vector2 m_vTopRPocket = Vector2(955, 478)
 Position of top right pocket.
 
static Vector2 m_vTopCPocket = Vector2(514, 478)
 Position of top center pocket.
 
static Vector2 m_vBotLPocket = Vector2(71, 53)
 Position of bottom left pocket.
 
static Vector2 m_vBotRPocket = Vector2(955, 53)
 Position of bottom right pocket.
 
static Vector2 m_vBotCPocket = Vector2(514, 48)
 Position of bottom center pocket.
 

Detailed Description

A collection of all of the game objects.

Member Function Documentation

◆ AdjustCueBall()

void CObjectManager::AdjustCueBall ( float  d)

Adjust the cue ball up or down on the base line, being careful stop it at the horizontal rails. This should only be used in eGameState::Initial, but no check is made here.

Parameters
dDistance to move by.

◆ AdjustImpulseVector()

void CObjectManager::AdjustImpulseVector ( float  a)

Adjust the angle of the impulse vector. This should only be used in eGameState::Initial or eGameState::SetupShot, but no check is made here.

Parameters
aAmount to add to the angle of the impulse vector.

◆ AllStopped()

bool CObjectManager::AllStopped ( )

Check whether both the cue-ball and the 8-ball have stopped moving. Notice that we can set the velocity vector to the zero vector and expect it to succeed because CObject::move zeros out the velocity of slow-moving objects.

Returns
true If both balls have stopped moving.

◆ BallCollide()

bool CObjectManager::BallCollide ( CObject p0,
CObject p1,
float &  s 
)
private

Begin by computing velocities relative to b1. Calculate the relative displacement c and the distance cdotvhat along the normal to common tangent vhat. Calculate d1 and d2, the distances moved back by b1 and b2 (respectively) to their positions at TOI. Calculate time elapsed since TOI, tdelta = d2/s2. Move balls back to their positions at TOI and compute their new velocities. Move both balls after impact using their new velocities and tdelta.

Parameters
p0Pointer to first object.
p1Pointer to first object.
s[OUT] Collision speed.
Returns
true if the two objects collide.

◆ BallDown()

bool CObjectManager::BallDown ( )

Check whether the cue-ball or the 8-ball is in a pocket.

Returns
true If one of the balls is in a pocket.

◆ BroadPhase()

void CObjectManager::BroadPhase ( )
private

Collision response for all balls against each other and the rails and the pockets. We do pocket collision for all balls first to remove them from the subsequent calculations.

◆ clear()

void CObjectManager::clear ( )

Delete all of the objects in the game.

◆ create()

void CObjectManager::create ( eSprite  t,
const Vector2 &  v 
)

Create an object and put a pointer to it on the object list.

Parameters
tSprite type.
vInitial position.

◆ CueBallDown()

bool CObjectManager::CueBallDown ( )

Check whether the cue-ball is down a pocket.

Returns
true If the cue-ball is in a pocket.

◆ Draw()

void CObjectManager::Draw ( )

Draw all of the objects in the game, two balls, the directional arrow, and the step mode indicator if necessary.

◆ move()

void CObjectManager::move ( )

Move all of the objects in the object list and perform broad phase collision detection and response. If in Step Mode, drop a particle.

◆ NarrowPhase()

void CObjectManager::NarrowPhase ( CObject p0,
CObject p1 
)
private

Perform collision detection and response for a pair of objects. Play impact sound if they collide.

Parameters
p0Pointer to the first object.
p1Pointer to the second object.

◆ PocketCollide()

void CObjectManager::PocketCollide ( CObject b)
private

Collision and response for ball-in-pocket. Check for a collision and does the necessary housework for disabling a ball that is in a pocket. If there is a collision, a sound is played at a volume proportional to the speed of collision and panned to the left or right according to where the pocket is on the table.

Parameters
bPointer to a ball object to collide with pockets.

◆ RailCollide()

void CObjectManager::RailCollide ( CObject b)
private

Collision detection and response for ball hitting any rail. Check for a collision and do the necessary housework for reflecting the ball if it hits a rail. If there is a collision, a sound is played at a volume proportional to the speed of collision and panned to the left or right according to where the collision occurred.

Parameters
bPointer to a ball object to collide with rails.

◆ ResetImpulseVector()

void CObjectManager::ResetImpulseVector ( )

Make the impulse vector point from the center of the cue-ball to the center of the 8-ball and set it as visible so it gets drawn (assuming that the only reason to reset the impulse vector is because it needs to be drawn).

◆ Shoot()

void CObjectManager::Shoot ( )

Shoot the cue-ball by giving it a fixed impulse. Disable the drawing of the impulse vector and play a sound that is panned left or right depending on where the cue-ball is on the table.