Ball and Spring Toy
Ian Parberry's "Introduction to Game Physics"
Public Member Functions | Private Member Functions | Private Attributes | List of all members
CPoint Class Reference

The point. More...

#include <Point.h>

Inheritance diagram for CPoint:
CCommon

Public Member Functions

 CPoint (eSprite, const Vector2 &, float)
 Constructor. More...
 
void move ()
 Change position depending on time and velocity. More...
 
void draw (float)
 Draw. More...
 
void DeliverImpulse (float, float)
 Deliver an impulse. More...
 
void Adjust (const Vector2 &)
 Adjust position from Gauss-Seidel relaxation. More...
 
void Teleport (const Vector2 &)
 Magically teleport point by this amount. More...
 
void SetCollisionSound (eSound)
 Override default collision sound. More...
 
const Vector2 & GetPos () const
 Get position. More...
 
float GetRadius () const
 Get radius. More...
 

Private Member Functions

float EdgeCollision ()
 Collision detection and response for edges of screen. More...
 

Private Attributes

eSprite m_eSpriteType = eSprite::Size
 Sprite type.
 
Vector2 m_vPos
 Current position.
 
Vector2 m_vOldPos
 Previous position, needed for Verlet.
 
float m_fRadius = 0
 Radius of bounding circle.
 
float m_fAngle = 0
 Orientation angle.
 
float m_fXScale = 1
 Scale along x-axis.
 
float m_fYScale = 1
 Scale along y-axis.
 
eSound m_eCollisionSnd = eSound::Size
 Collision sound.
 

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 eBody m_eCurrentBody = (eBody)0
 Current body type.
 

Detailed Description

The point class is the representation of an abstract point moving through space using Verlet Integration.

Constructor & Destructor Documentation

◆ CPoint()

CPoint::CPoint ( eSprite  t,
const Vector2 &  p,
float  r 
)
Parameters
tSprite type.
pInitial position.
rRadius.

Member Function Documentation

◆ Adjust()

void CPoint::Adjust ( const Vector2 &  v)

All a point needs to do for Gauss-Seidel relaxation is to move when the spring tells it to.

◆ DeliverImpulse()

void CPoint::DeliverImpulse ( float  a,
float  m 
)

Since we are using Verlet integration, an impulse is easily faked by moving the old position a distance proportional to the magnitude of the impulse in the direction of the vector's orientatio.

Parameters
aAngle.
mMagnitude.

◆ draw()

void CPoint::draw ( float  a)
Parameters
aOrientation.

◆ EdgeCollision()

float CPoint::EdgeCollision ( )
private

Checks for a collision, and does the necessary calculations for reflecting a point if it hits an edge.

Returns
Collision speed, zero if no collision.

◆ GetPos()

const Vector2 & CPoint::GetPos ( ) const

Reader function for position.

Returns
Position.

◆ GetRadius()

float CPoint::GetRadius ( ) const

Reader function for radius.

Returns
Radius.

◆ move()

void CPoint::move ( )

Move the point using Verlet integration, perform collision detection and response with edges of window. Notice that there is no concept of time here.

◆ SetCollisionSound()

void CPoint::SetCollisionSound ( eSound  s)
Parameters
sNew collision sound.

◆ Teleport()

void CPoint::Teleport ( const Vector2 &  d)

Teleport the point without changing its velocity. Well, actually points don't have a velocity under Verlet Integration, but you know what I mean. Just displace both the position and old position.

Parameters
dDisplacement.