![]() |
The Pinball Game
Ian Parberry's "Introduction to Game Physics"
|
A gate. More...
#include <Parts.h>
Public Member Functions | |
CGate (CLineSeg *p) | |
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 CRenderer * | m_pRenderer = nullptr |
Pointer to the renderer. | |
static CObjectManager * | m_pObjectManager = nullptr |
Pointer to the object manager. | |
static UINT | m_nMIterations = 4 |
Number of motion iterations. | |
static UINT | m_nCIterations = 1 |
Number of collision iterations. | |
static float | m_fFrequency = 60.0f*m_nMIterations |
Frequency, number of physics iterations per second. | |
static eDrawMode | m_eDrawMode = eDrawMode::Background |
Draw mode. | |
static bool | m_bBallInPlay = false |
Is there a ball currently in play? | |
static UINT | m_nScore = 0 |
Current score. | |
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.
CGate::CGate | ( | CLineSeg * | p | ) |
Construct a closed and unlatched gate from a line segment.
p | Pointer to a line segment. |
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.
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.
p | Pointer to a dynamic circle. |