Ball and Spring Toy
Chapter 4 of Ian Parberry's "Introduction to Game Physics with Box2D"
|
The body. More...
#include <Body.h>
Public Member Functions | |
CBody (CParticleManager *p, CSpringManager *s) | |
Constructor. | |
~CBody () | |
Destructor. | |
CParticle * | MakeChain (int count, int radius, float r, float angle) |
Make a chain body. | |
CParticle * | MakeTriangle (int radius, float r) |
Make a triangle body. | |
CParticle * | MakeSquare (int radius, float r) |
Make a square body. | |
CParticle * | MakeWheel (int sides, int radius, float r) |
Make a wheel body. | |
CParticle * | MakeRagdoll () |
Make a ragdoll body. | |
void | DeliverImpulse (float angle, float magnitude) |
Deliver impulse to body. | |
void | ApplyTorque (float angle, float magnitude) |
Apply a torque by delivering impulse to edge particle. | |
void | Teleport (float xdelta, float ydelta) |
Magically teleport body by this amount. | |
void | move () |
Move body. | |
The body.
void CBody::ApplyTorque | ( | float | angle, |
float | magnitude | ||
) |
Apply a torque by delivering impulse to edge particle.
Deliver torque to body. This is achieved by delivering an impulse to a particle on the outside of the body.
angle | Orientation of torque. |
magnitude | Magnitude of torque. |
void CBody::DeliverImpulse | ( | float | angle, |
float | magnitude | ||
) |
Deliver impulse to body.
Deliver impulse to body.
angle | Orientation of impulse. |
magnitude | Magnitude of impulse. |
CParticle * CBody::MakeChain | ( | int | count, |
int | radius, | ||
float | r, | ||
float | angle | ||
) |
Make a chain body.
Make a chain of points in a straight line connected by springs.
count | Number of points |
radius | Half the length of one of the springs. |
r | Coefficient of restitution of the springs. |
angle | Angle that the chain makes with the horizontal. |
CParticle * CBody::MakeRagdoll | ( | ) |
Make a ragdoll body.
Make a cross-braced stick figure with spring constraints.
CParticle * CBody::MakeSquare | ( | int | radius, |
float | r | ||
) |
Make a square body.
Make a cross-braced square of points connected by springs.
radius | Half the length of one of the springs. |
r | Coefficient of restitution of the springs. |
CParticle * CBody::MakeTriangle | ( | int | radius, |
float | r | ||
) |
Make a triangle body.
Make a triangle of points connected by springs.
radius | Half the length of one of the springs. |
r | Coefficient of restitution of the springs. |
CParticle * CBody::MakeWheel | ( | int | sides, |
int | radius, | ||
float | r | ||
) |
Make a wheel body.
Make a cross-braced wheel of points connected by springs.
sides | Number of sides to the wheel. |
radius | Half the length of one of the springs. |
r | Coefficient of restitution of the springs. |
void CBody::move | ( | ) |
Move body.
Move the body. Since the components of the body (particles and springs) are responsible for moving themselves, all we need to do here is to orient the particles at the ends and middle of the springs correctly.
void CBody::Teleport | ( | float | xdelta, |
float | ydelta | ||
) |
Magically teleport body by this amount.
Teleport the body without moving any of the particle relative to each other.
xdelta | Amount to move horizontally. |
ydelta | Amount to move vertically. |