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

The body. More...

#include <Body.h>

Inheritance diagram for CBody:
CCommon CChain CRagdoll CWheel

Public Member Functions

void DeliverImpulse (float)
 Deliver impulse to body. More...
 
void Teleport (const Vector2 &)
 Magically teleport body by this amount. More...
 
void draw ()
 Draw body. More...
 

Protected Member Functions

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

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

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.

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

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

◆ DeliverImpulse()

void CBody::DeliverImpulse ( float  m)

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

Parameters
mMagnitude of impulse.

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

◆ Teleport()

void CBody::Teleport ( const Vector2 &  d)

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

Parameters
dDisplacement.