Collision Math Toy
Ian Parberry's "Introduction to Game Physics"
Public Member Functions | Private Attributes | List of all members
CGate Class Reference

A gate. More...

#include <Parts.h>

Inheritance diagram for CGate:
CCommon

Public Member Functions

 CGate (CLineSeg *)
 Constructor. More...
 
 ~CGate ()
 Destructor.
 
void CloseGate ()
 Check latch to see if gate should be closed. More...
 
bool NarrowPhase (CDynamicCircle *)
 Narrow phase collision detection and response. More...
 

Private Attributes

CLineSeg * m_pLineSeg = nullptr
 Pointer to line segment representing gate.
 
bool m_bOpen = false
 true if gate is open.
 
bool m_bOccupied = false
 true if ball is holding gate open.
 

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 gate allows balls to cross in one direction only. It's essentially a line segment with a couple of Boolean variables and some code that handles the crossing-in-one-direction requirement. Care must be taken to do the right thing when a ball gets nudged back while in the process of crossing.

A gate can be open or closed, latched or unlatched. When it is open, there can be no collisions. When it is closed, balls collide with it if they are travelling from one side but not the other. More specifically, if the vector from the ball's center to the POI is in the opposite direction to the line segment's normal vector CLineSeg::m_vNormal, then they can cross. Recall that the direction of CLineSeg::m_vNormal depends on the order in which CLineSeg's end points were specified, so make sure you get it right.

Constructor & Destructor Documentation

◆ CGate()

CGate::CGate ( CLineSeg *  p)

Construct a closed and unlatched gate from a line segment.

Parameters
pPointer to a line segment.

Member Function Documentation

◆ CloseGate()

void CGate::CloseGate ( )

Close gate if open and there is no ball currently holding it open. Unset the occupied flag ready for use the the next frame. We assume that this is called at the end of the frame.

◆ NarrowPhase()

bool CGate::NarrowPhase ( CDynamicCircle *  p)

If a dynamic circle collides with a gate and it is moving in the correct direction, then the gate opens and the dynamic circle is allowed through. Otherwise the dynamic circle bounces off the gate as usual.

Parameters
pPointer to a dynamic circle.
Returns
true if the dynamic circle bounces off the gate.