Ball and Spring Toy
Chapter 4 of Ian Parberry's "Introduction to Game Physics with Box2D"
 All Classes Files Functions Variables Enumerations Pages
Public Member Functions | List of all members
CBody Class Reference

The body. More...

#include <Body.h>

Public Member Functions

 CBody (CParticleManager *p, CSpringManager *s)
 Constructor.
 
 ~CBody ()
 Destructor.
 
CParticleMakeChain (int count, int radius, float r, float angle)
 Make a chain body.
 
CParticleMakeTriangle (int radius, float r)
 Make a triangle body.
 
CParticleMakeSquare (int radius, float r)
 Make a square body.
 
CParticleMakeWheel (int sides, int radius, float r)
 Make a wheel body.
 
CParticleMakeRagdoll ()
 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.
 

Detailed Description

The body.

Member Function Documentation

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.

Parameters
angleOrientation of torque.
magnitudeMagnitude of torque.
void CBody::DeliverImpulse ( float  angle,
float  magnitude 
)

Deliver impulse to body.

Deliver impulse to body.

Parameters
angleOrientation of impulse.
magnitudeMagnitude 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.

Parameters
countNumber of points
radiusHalf the length of one of the springs.
rCoefficient of restitution of the springs.
angleAngle 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.

Parameters
radiusHalf the length of one of the springs.
rCoefficient of restitution of the springs.
CParticle * CBody::MakeTriangle ( int  radius,
float  r 
)

Make a triangle body.

Make a triangle of points connected by springs.

Parameters
radiusHalf the length of one of the springs.
rCoefficient 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.

Parameters
sidesNumber of sides to the wheel.
radiusHalf the length of one of the springs.
rCoefficient 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.

Parameters
xdeltaAmount to move horizontally.
ydeltaAmount to move vertically.