World of Rigid Bodies (WoRB)
|
Encapsulates a system of rigid bodies. More...
#include <WoRB.h>
Data Structures | |
class | RigidBodies |
Represents a rigid body iterator for the WorldOfRigidBodies class. More... | |
Public Member Functions | |
WorldOfRigidBodies () | |
Constructs an instance of WoRB class. | |
void | RemoveObjects () |
Removes all objects from the system. | |
void | Add (Geometry *object) |
Adds new object to the system. | |
void | Add (Geometry &object) |
Adds new object to the system. | |
void | InitializeODE () |
Prepares ODE (recalculates derived quantities) | |
void | SolveODE (double h) |
Solves (integrates) equations of motion for the whole system. | |
Data Fields | |
Quaternion | Gravity |
Holds common gravity applied to all objects (set to 0 to disable). | |
double | Time |
Holds the system local time, in s . | |
unsigned long | TimeStepCount |
Holds the number of integrator time-steps, from the simulation start. | |
double | TotalKineticEnergy |
Holds the total kinetic energy of the system, in J . | |
double | TotalPotentialEnergy |
Holds the total potential energy of the system, in J . | |
Quaternion | TotalLinearMomentum |
Holds the total linear momentum of the system, in kg m^2 s^-1 . | |
Quaternion | TotalAngularMomentum |
Holds the total angular momentum of the system, in kg m^2 s^-1 . | |
CollisionResolver | Collisions |
Holds the collision data for all registered collisions. | |
Collision | CollisionRegistry [MaxCollisions] |
Holds the memory parcel where collisions are registered. | |
Private Attributes | |
unsigned | ObjectCount |
Holds the number of the objects in the system. | |
Geometry * | Object [MaxObjects] |
Points to an array of the objects handled by the system. | |
Friends | |
class | RigidBodies |
Encapsulates a system of rigid bodies.
WoRB::WorldOfRigidBodies< MaxObjects, MaxCollisions >::WorldOfRigidBodies | ( | ) | [inline] |
Constructs an instance of WoRB class.
Definition at line 160 of file WoRB.h.
: Collisions( CollisionRegistry, MaxCollisions ) { }
void WoRB::WorldOfRigidBodies< MaxObjects, MaxCollisions >::Add | ( | Geometry * | object | ) | [inline] |
Adds new object to the system.
Definition at line 176 of file WoRB.h.
Referenced by WoRB_MexFunction::Parse().
{ Object[ ObjectCount++ ] = object; }
void WoRB::WorldOfRigidBodies< MaxObjects, MaxCollisions >::Add | ( | Geometry & | object | ) | [inline] |
Adds new object to the system.
Definition at line 183 of file WoRB.h.
{ Object[ ObjectCount++ ] = &object; }
void WoRB::WorldOfRigidBodies< MaxObjects, MaxCollisions >::InitializeODE | ( | ) | [inline] |
Prepares ODE (recalculates derived quantities)
Definition at line 192 of file WoRB.h.
Referenced by WoRB_MexFunction::Parse().
{ Time = 0; TimeStepCount = 0; Collisions.Initialize (); for ( RigidBodies body = RigidBodies(this); body.Exists(); ++body ) { body->CalculateDerivedQuantities (); body->ClearAccumulators (); } TotalKineticEnergy = 0; TotalPotentialEnergy = 0; TotalLinearMomentum = 0; TotalAngularMomentum = 0; for ( RigidBodies body = RigidBodies(this); body.Exists(); ++body ) { TotalKineticEnergy += body->KineticEnergy; TotalPotentialEnergy += body->PotentialEnergy; TotalLinearMomentum += body->LinearMomentum; TotalAngularMomentum += body->TotalAngularMomentum; } }
void WoRB::WorldOfRigidBodies< MaxObjects, MaxCollisions >::RemoveObjects | ( | ) | [inline] |
void WoRB::WorldOfRigidBodies< MaxObjects, MaxCollisions >::SolveODE | ( | double | h | ) | [inline] |
Solves (integrates) equations of motion for the whole system.
Solves ODE for all the objects in the system, performs the contact generation and then resolves detected contacts.
h | Integrator time-step length |
Definition at line 224 of file WoRB.h.
{ ///////////////////////////////////////////////////////////////////////////// // Calculate and accumulate all external and internal forces // // Add gravity // for ( RigidBodies body = RigidBodies(this); body.Exists(); ++body ) { Quaternion f_g = body->Mass() * Gravity; double E_p = - f_g.Dot( body->Position ); body->AddExternalForce( f_g, E_p ); } ///////////////////////////////////////////////////////////////////////////// // Solve ODE for every object in the system // for ( RigidBodies body = RigidBodies(this); body.Exists(); ++body ) { body->SolveODE( h ); } // Solve system local time (avoiding `Time += h` cause of rounding-errors). // Time = h * (++TimeStepCount); ///////////////////////////////////////////////////////////////////////////// // Calculate derived quantities TotalKineticEnergy = 0; TotalPotentialEnergy = 0; TotalLinearMomentum = 0; TotalAngularMomentum = 0; for ( RigidBodies body = RigidBodies(this); body.Exists(); ++body ) { TotalKineticEnergy += body->KineticEnergy; TotalPotentialEnergy += body->PotentialEnergy; TotalLinearMomentum += body->LinearMomentum; TotalAngularMomentum += body->TotalAngularMomentum; } ///////////////////////////////////////////////////////////////////////////// // Collision Detection Collisions.Initialize (); // Detect and register collisions between all objects in the system // for ( unsigned i = 0; i < ObjectCount; ++i ) { for ( unsigned j = i + 1; j < ObjectCount; ++j ) { Object[i]->Detect( Collisions, Object[j] ); } } Collisions.UpdateDerivedQuantities( h ); ///////////////////////////////////////////////////////////////////////////// // Collision Response Collisions.ImpulseTransfers( h ); Collisions.PositionProjections (); ///////////////////////////////////////////////////////////////////////////// // Prepare force and torque accumulators for the next time-step // for ( RigidBodies body = RigidBodies(this); body.Exists(); ++body ) { body->ClearAccumulators (); } }
friend class RigidBodies [friend] |
Definition at line 102 of file WoRB.h.
Referenced by WoRB::WorldOfRigidBodies< 256, 1024 >::InitializeODE(), and WoRB::WorldOfRigidBodies< 256, 1024 >::SolveODE().
Collision WoRB::WorldOfRigidBodies< MaxObjects, MaxCollisions >::CollisionRegistry[MaxCollisions] |
CollisionResolver WoRB::WorldOfRigidBodies< MaxObjects, MaxCollisions >::Collisions |
Holds the collision data for all registered collisions.
Definition at line 150 of file WoRB.h.
Referenced by WoRB::WorldOfRigidBodies< 256, 1024 >::InitializeODE(), WoRB_MexFunction::OnProcessData(), WoRB_MexFunction::Parse(), and WoRB::WorldOfRigidBodies< 256, 1024 >::SolveODE().
Quaternion WoRB::WorldOfRigidBodies< MaxObjects, MaxCollisions >::Gravity |
Holds common gravity applied to all objects (set to 0 to disable).
Definition at line 118 of file WoRB.h.
Referenced by WoRB_MexFunction::Parse(), and WoRB::WorldOfRigidBodies< 256, 1024 >::SolveODE().
Geometry* WoRB::WorldOfRigidBodies< MaxObjects, MaxCollisions >::Object[MaxObjects] [private] |
Points to an array of the objects handled by the system.
Definition at line 110 of file WoRB.h.
Referenced by WoRB::WorldOfRigidBodies< 256, 1024 >::Add(), WoRB::WorldOfRigidBodies< MaxObjects, MaxCollisions >::RigidBodies::Exists(), WoRB::WorldOfRigidBodies< MaxObjects, MaxCollisions >::RigidBodies::Next(), WoRB::WorldOfRigidBodies< MaxObjects, MaxCollisions >::RigidBodies::operator->(), WoRB::WorldOfRigidBodies< MaxObjects, MaxCollisions >::RigidBodies::RigidBodies(), and WoRB::WorldOfRigidBodies< 256, 1024 >::SolveODE().
unsigned WoRB::WorldOfRigidBodies< MaxObjects, MaxCollisions >::ObjectCount [private] |
Holds the number of the objects in the system.
Definition at line 106 of file WoRB.h.
Referenced by WoRB::WorldOfRigidBodies< 256, 1024 >::Add(), WoRB::WorldOfRigidBodies< MaxObjects, MaxCollisions >::RigidBodies::Clear(), WoRB::WorldOfRigidBodies< MaxObjects, MaxCollisions >::RigidBodies::Count(), WoRB::WorldOfRigidBodies< MaxObjects, MaxCollisions >::RigidBodies::Exists(), WoRB::WorldOfRigidBodies< MaxObjects, MaxCollisions >::RigidBodies::Next(), WoRB::WorldOfRigidBodies< MaxObjects, MaxCollisions >::RigidBodies::operator->(), WoRB::WorldOfRigidBodies< 256, 1024 >::RemoveObjects(), WoRB::WorldOfRigidBodies< MaxObjects, MaxCollisions >::RigidBodies::RigidBodies(), and WoRB::WorldOfRigidBodies< 256, 1024 >::SolveODE().
double WoRB::WorldOfRigidBodies< MaxObjects, MaxCollisions >::Time |
Holds the system local time, in s
.
Definition at line 124 of file WoRB.h.
Referenced by WoRB::WorldOfRigidBodies< 256, 1024 >::InitializeODE(), WoRB_MexFunction::OnProcessData(), and WoRB::WorldOfRigidBodies< 256, 1024 >::SolveODE().
unsigned long WoRB::WorldOfRigidBodies< MaxObjects, MaxCollisions >::TimeStepCount |
Holds the number of integrator time-steps, from the simulation start.
Definition at line 128 of file WoRB.h.
Referenced by WoRB::WorldOfRigidBodies< 256, 1024 >::InitializeODE(), WoRB_MexFunction::OnProcessData(), and WoRB::WorldOfRigidBodies< 256, 1024 >::SolveODE().
Quaternion WoRB::WorldOfRigidBodies< MaxObjects, MaxCollisions >::TotalAngularMomentum |
Holds the total angular momentum of the system, in kg m^2 s^-1
.
Definition at line 144 of file WoRB.h.
Referenced by WoRB::WorldOfRigidBodies< 256, 1024 >::InitializeODE(), WoRB_MexFunction::OnProcessData(), and WoRB::WorldOfRigidBodies< 256, 1024 >::SolveODE().
double WoRB::WorldOfRigidBodies< MaxObjects, MaxCollisions >::TotalKineticEnergy |
Holds the total kinetic energy of the system, in J
.
Definition at line 132 of file WoRB.h.
Referenced by WoRB::WorldOfRigidBodies< 256, 1024 >::InitializeODE(), WoRB_MexFunction::OnProcessData(), and WoRB::WorldOfRigidBodies< 256, 1024 >::SolveODE().
Quaternion WoRB::WorldOfRigidBodies< MaxObjects, MaxCollisions >::TotalLinearMomentum |
Holds the total linear momentum of the system, in kg m^2 s^-1
.
Definition at line 140 of file WoRB.h.
Referenced by WoRB::WorldOfRigidBodies< 256, 1024 >::InitializeODE(), WoRB_MexFunction::OnProcessData(), and WoRB::WorldOfRigidBodies< 256, 1024 >::SolveODE().
double WoRB::WorldOfRigidBodies< MaxObjects, MaxCollisions >::TotalPotentialEnergy |
Holds the total potential energy of the system, in J
.
Definition at line 136 of file WoRB.h.
Referenced by WoRB::WorldOfRigidBodies< 256, 1024 >::InitializeODE(), WoRB_MexFunction::OnProcessData(), and WoRB::WorldOfRigidBodies< 256, 1024 >::SolveODE().