![]() |
Ball and Spring Toy
Ian Parberry's "Introduction to Game Physics"
|
The body. More...
#include <Body.h>
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 | |
CPoint * | CreatePoint (eSprite, const Vector2 &) |
Create point. More... | |
CSpring * | CreateSpring (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 CRenderer * | m_pRenderer = nullptr |
Pointer to the renderer. | |
static CObjectManager * | m_pObjectManager = nullptr |
Pointer to the object manager. | |
static eBody | m_eCurrentBody = (eBody)0 |
Current body type. | |
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.
Create a point and append it to the point list.
t | Sprite type. |
v | Location of the point. |
Create a spring between two points and append it to the spring list.
t | Sprite type. |
p0 | Index of first point. |
p1 | Index of second point. |
r | Restitution value for the spring. |
void CBody::DeliverImpulse | ( | float | m | ) |
Deliver an impulse at a random angle in the range \([0, \pi]\).
m | Magnitude of impulse. |
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.
void CBody::Teleport | ( | const Vector2 & | d | ) |
Teleport the body without moving any of the point relative to each other.
d | Displacement. |