Ball and Spring Toy
Game Physics with Bespoke Code
Loading...
Searching...
No Matches
CPoint Class Reference

The point. More...

#include <Point.h>

Inheritance diagram for CPoint:
Collaboration diagram for CPoint:

Public Member Functions

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

Private Member Functions

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

Private Attributes

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

Additional Inherited Members

- Static Protected Attributes inherited from CCommon
static Sage::CSpriteRenderer * m_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 )

Create a Verlet-style point.

Parameters
tSprite type.
pInitial position.
rRadius.

Member Function Documentation

◆ Adjust()

void CPoint::Adjust ( const Vector2 & v)

All a point needs to do ti adjust its position during Gauss-Seidel relaxation is to move when the spring tells it to.

Parameters
vTranslation vector.
Here is the caller graph for this function:

◆ 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 motion.

Parameters
aAngle.
mMagnitude.
Here is the caller graph for this function:

◆ Draw()

void CPoint::Draw ( float a)

Draw a point. If it's a ball, draw it at orientation zero (the default orientation, meaning the sprite is drawn as given in the image file). Otherwise, orient it correctly.

Parameters
aOrientation.
Here is the caller graph for this function:

◆ EdgeCollision()

float CPoint::EdgeCollision ( )
private

Check for a collision and do the necessary calculations for reflecting a point if it hits an edge.

Returns
Collision speed, zero if no collision.
Here is the caller graph for this function:

◆ GetPos()

const Vector2 & CPoint::GetPos ( ) const

Reader function for position.

Returns
Position.
Here is the caller graph for this function:

◆ 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.

Here is the call graph for this function:

◆ SetCollisionSound()

void CPoint::SetCollisionSound ( eSound s)

Set the sound to be used when this point collides with something.

Parameters
sNew collision sound.
Here is the caller graph for this function:

◆ 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.