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

The body. More...

#include <Body.h>

Inheritance diagram for CBody:
Collaboration diagram for CBody:

Public Member Functions

virtual ~CBody ()
 Destructor.
 
void DeliverImpulse (float)
 Deliver impulse to body.
 
void Teleport (const Vector2 &)
 Magically teleport body by this amount.
 
void Draw ()
 Draw body.
 

Protected Member Functions

CPointCreatePoint (eSprite, const Vector2 &)
 Create point.
 
CSpringCreateSpring (eSprite, CPoint *, CPoint *, float=1.0f)
 Create spring.
 

Protected Attributes

std::vector< CPoint * > m_stdPt
 Vector of pointers to points in this body.
 
std::vector< CSpring * > m_stdSpr
 Vector of pointers to springs.
 

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

A body consists of a collection of points and springs. It maintains vectors of pointers to individual points and springs so that they can be drawn in the right order using Painter's Algorithm. It is assumed that the care and feeding of the individual points and springs is taken care of elsewhere.

Constructor & Destructor Documentation

◆ ~CBody()

CBody::~CBody ( )
virtual

Virtual destructor required because we will derive classes from CBody and access them using CBody* pointers.

Member Function Documentation

◆ CreatePoint()

CPoint * CBody::CreatePoint ( eSprite t,
const Vector2 & v )
protected

Create a point and append it to the point list.

Parameters
tSprite type.
vLocation of the point.
Returns
Pointer to the created point.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ CreateSpring()

CSpring * CBody::CreateSpring ( eSprite t,
CPoint * p0,
CPoint * p1,
float r = 1.0f )
protected

Create a spring between two points and append it to the spring list.

Parameters
tSprite type.
p0Index of first point.
p1Index of second point.
rRestitution value for the spring.
Returns
Pointer to the created spring.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ DeliverImpulse()

void CBody::DeliverImpulse ( float m)

Deliver an impulse at a random angle in the range \([0, \pi]\).

Parameters
mMagnitude of impulse.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Draw()

void CBody::Draw ( )

Draw all of the springs in the body list. These will also draw the points at their ends, so no need for a separate loop to draw the points. Doing so would violate the draw order anyway.

Here is the caller graph for this function:

◆ Teleport()

void CBody::Teleport ( const Vector2 & d)

Teleport the body without moving any of the point relative to each other.

Parameters
dDisplacement.