Om  1.0.0
A universal framework for multimedia simulation
Classes | Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | List of all members
om::physics::context::PhysicsContext Class Reference

The main object that handles simulation of a physics scene. More...

#include <omPhysicsContext.h>

Classes

class  ConstraintInfo
 An object that stores information about a constraint in a physics context. More...
 
class  ConstraintIsland
 A class that stores information for a constraint island in a physics context. More...
 
class  SceneInfo
 An object that stores information about a scene in a physics context. More...
 

Public Types

typedef ObjectPool< TransformState, 8, PhysicsObjectID, AlignedAllocator< 16 > > TransformPool
 
typedef ObjectPool< VelocityState, 8, PhysicsObjectID, AlignedAllocator< 16 > > VelocityPool
 
typedef ObjectPool< MassState, 8, PhysicsObjectID, AlignedAllocator< 16 > > MassPool
 
typedef ObjectPool< ObjectState, 8, PhysicsObjectID, AlignedAllocator< 16 > > ObjectStatePool
 
typedef ObjectPool< Collider, 8, ColliderID, AlignedAllocator< 16 > > ColliderPool
 
typedef ObjectPool< ConstraintInfo, 8, ConstraintIDConstraintPool
 
typedef ObjectPool< Force *, 8, ForceIDForcePool
 
typedef ObjectPool< ForceField *, 8, ForceFieldIDFieldPool
 
typedef ObjectPool< SceneInfo, 4, PhysicsSceneIDScenePool
 

Public Member Functions

 PhysicsContext ()
 Create a new empty physics context with no objects. More...
 
 ~PhysicsContext ()
 Destory this context and release all internally allocated resources. More...
 
void update (const PhysicsRequest &request, Float dt)
 Update the state of all scenes in this physics context for the specified time step. More...
 
void updateScene (PhysicsSceneID scene, const PhysicsRequest &request, Float dt)
 Update the state of the given scene in this physics context for the specified time step. More...
 
Size getObjectCount () const
 Return the current number of objects that are part of this context. More...
 
ObjectStategetObject (PhysicsObjectID objectID)
 Return a pointer to the state of the object with the specified ID in this context. More...
 
PhysicsObjectID newObject (const Transform3f &transform=Transform3f(), const Vector3f &velocity=Vector3f(), const Vector3f &angularVelocity=Vector3f())
 Create a new object with the specified initial transform, velocity, and angular velocity. More...
 
Bool deleteObject (PhysicsObjectID object)
 Delete the object in the context with the specified ID. More...
 
void clearObjects ()
 Remove all currently simulated objects from this context. More...
 
Size getColliderCount () const
 Return the current number of colliders that are part of this context. More...
 
CollidergetCollider (ColliderID colliderID)
 Return a pointer to the collider with the specified ID in this context. More...
 
ColliderID newCollider (PhysicsShape *shape)
 Create a new collider with the given shape without a parent object. More...
 
ColliderID newCollider (PhysicsShape *shape, ObjectState *object)
 Create a new collider with a shape that is attached to the specified object. More...
 
ColliderID newCollider (PhysicsShape *shape, PhysicsObjectID object)
 Create a new collider with a shape that is attached to the object with the given ID. More...
 
Bool deleteCollider (ColliderID collider)
 Delete the collider in the context with the specified ID. More...
 
void clearColliders ()
 Remove all colliders from this context. More...
 
const CollisionResultSetgetCollisions () const
 Return an object containing the collision results for the last frame. More...
 
Size getConstraintCount () const
 Return the current number of constraints that are part of this context. More...
 
ConstraintgetConstraint (ConstraintID constraintID)
 Return a pointer to the constraint with the specified ID in this context. More...
 
ConstraintID newConstraint (Constraint *constraint, UInt32 userID)
 Create a new constraint in the context associated with no objects. More...
 
ConstraintID newConstraint (ObjectState *object, Constraint *constraint, UInt32 userID)
 Create a new constraint in the context for a single object. More...
 
ConstraintID newConstraint (PhysicsObjectID object, Constraint *constraint, UInt32 userID)
 Create a new constraint in the context for a single object. More...
 
ConstraintID newConstraint (ObjectState *obj1, ObjectState *obj2, Constraint *constraint, UInt32 userID)
 Create a new constraint in the context between the specified object states. More...
 
ConstraintID newConstraint (PhysicsObjectID obj1, PhysicsObjectID obj2, Constraint *constraint, UInt32 userID)
 Create a new constraint in the context between the objects with the given IDs. More...
 
Bool deleteConstraint (ConstraintID constraint)
 Delete the constraint in the context with the specified ID. More...
 
void clearConstraints ()
 Remove all constraints from this context. More...
 
ForceID newForce (Force *force)
 Create a new force in the context. More...
 
Bool deleteForce (ForceID force)
 Delete the force in the context with the specified ID. More...
 
void clearForces ()
 Remove all forces from this context. More...
 
ForceFieldID newField (ForceField *forceField)
 Create a new force field in the context. More...
 
Bool deleteField (ForceFieldID forceFieldID)
 Delete the force field in the context with the specified ID. More...
 
void clearFields ()
 Remove all force fields from this context. More...
 
PhysicsSceneID newScene ()
 Create a new empty scene in the context. More...
 
Bool deleteScene (PhysicsSceneID scene)
 Delete the scene in the context with the specified ID. More...
 
void clearScenes ()
 Remove all scenes from this context. More...
 
Bool addSceneObject (PhysicsSceneID scene, PhysicsObjectID object)
 Add an existing object to the scene with the given ID. More...
 
Bool removeSceneObject (PhysicsSceneID scene, PhysicsObjectID object)
 Remove an existing object from the scene with the given ID. More...
 
Bool addSceneCollider (PhysicsSceneID scene, ColliderID collider)
 Add an existing collider to the scene with the given ID. More...
 
Bool removeSceneCollider (PhysicsSceneID scene, ColliderID collider)
 Remove an existing collider from the scene with the given ID. More...
 
Bool addSceneConstraint (PhysicsSceneID scene, ConstraintID constraint)
 Add an existing constraint to the scene with the given ID. More...
 
Bool removeSceneConstraint (PhysicsSceneID scene, ConstraintID constraint)
 Remove an existing constraint from the scene with the given ID. More...
 
Bool addSceneForce (PhysicsSceneID scene, ForceID force)
 Add an existing force to the scene with the given ID. More...
 
Bool removeSceneForce (PhysicsSceneID scene, ForceID force)
 Remove an existing force from the scene with the given ID. More...
 
Bool addSceneField (PhysicsSceneID scene, ForceFieldID forceField)
 Add an existing force field to the scene with the given ID. More...
 
Bool removeSceneField (PhysicsSceneID scene, ForceFieldID forceField)
 Remove an existing force field from the scene with the given ID. More...
 
CollisionBroadphasegetSceneBroadphase (PhysicsSceneID scene) const
 Return the collision broadphase that this context is using to find potentially colliding pairs for the given scene. More...
 
Bool setSceneBroadphase (PhysicsSceneID scene, CollisionBroadphase *newBroadphase)
 Set the collision broadphase that this context is using to find potentially colliding pairs for the given scene. More...
 
CollisionNarrowphasegetNarrowphase () const
 Return the collision narrowphase that this ccontext is using to do collision detection between collider pairs. More...
 
Bool setNarrowphase (CollisionNarrowphase *newNarrowphase)
 Set the collision narrowphase that this context is using to do collision detection between collider pairs. More...
 
void updateCollisions (const SceneInfo &scene, const CollisionRequest &request, CollisionResultSet &results)
 Update all of the collisions that there are in this context. More...
 
void solveConstraints (SceneInfo &scene, const constraints::ConstraintRequest &request, Float dt)
 Solve all of the constraints in this context for the specified parameters. More...
 
void rebuildConstraintIslands (SceneInfo &scene)
 Rebuild the current set of constraint islands that this context is solving. More...
 
void addConstraintToIslands (SceneInfo &scene, const ConstraintInfo &constraint)
 Add the specified constraint to the current constraint islands for this context. More...
 

Static Public Member Functions

static void applyForce (SceneInfo &scene, Float dt)
 Apply forces to all objects in the specified scene. More...
 
static void integrateForce (SceneInfo &scene, Float dt)
 Integrate the force vectors to velocity for all objects in the specified scene. More...
 
static void integrateVelocity (SceneInfo &scene, Float dt)
 Integrate the velocity vectors to position for all objects in the specified scene. More...
 
static void updateObjectTransforms (SceneInfo &scene)
 Update the data dependent on the local-to-world transformations for all of the objects in this context. More...
 
static void updateColliderTransforms (SceneInfo &scene)
 Update the data dependent on the local-to-world transformations for all of the colliders in this context. More...
 
static void solveConstraintIsland (const ConstraintIsland &island, const constraints::ConstraintRequest &request, Float dt)
 Solve a constraint island with the specified parameters. More...
 
static UInt32 newIsland (SceneInfo &scene)
 Create a new constraint island and return its index. More...
 

Public Attributes

TransformPool transforms
 A pool of transform states for the objects in this context. More...
 
VelocityPool velocities
 A pool of velocity states for the objects in this context. More...
 
MassPool masses
 A pool of mass states for the objects in this context. More...
 
ObjectStatePool objects
 A pool of the objects that are currently in this context. More...
 
ColliderPool colliders
 A pool of the colliders that are currently in this context. More...
 
ConstraintPool constraints
 A pool information about the constraints that are currently in this context. More...
 
ForcePool forces
 A pool of the colliders that are currently in this context. More...
 
FieldPool fields
 A pool of the force fields that are currently in this context. More...
 
ScenePool scenes
 A pool of the scenes that are currently in this context. More...
 
CollisionNarrowphasenarrowphase
 An object that this context is using to do collision detection between collider pairs. More...
 
CollisionResultSet collisionResults
 An object that stores temporary collision results for the context. More...
 

Static Public Attributes

static const UInt32 INVALID_ID = UInt32(-1)
 The ID indicating an invalid object. More...
 
static const UInt32 ROOT_OBJECT_ID = 0
 The ID of the root-level object for all collision shapes with no object. More...
 

Detailed Description

The main object that handles simulation of a physics scene.

The physics context is a semi-internal interface for low-level simulation. High-level types that inherit from PhysicsContextObject are the main user interface for the simulation.

Member Typedef Documentation

Constructor & Destructor Documentation

om::physics::context::PhysicsContext::PhysicsContext ( )

Create a new empty physics context with no objects.

om::physics::context::PhysicsContext::~PhysicsContext ( )

Destory this context and release all internally allocated resources.

Member Function Documentation

void om::physics::context::PhysicsContext::update ( const PhysicsRequest request,
Float  dt 
)

Update the state of all scenes in this physics context for the specified time step.

void om::physics::context::PhysicsContext::updateScene ( PhysicsSceneID  scene,
const PhysicsRequest request,
Float  dt 
)

Update the state of the given scene in this physics context for the specified time step.

Size om::physics::context::PhysicsContext::getObjectCount ( ) const

Return the current number of objects that are part of this context.

ObjectState* om::physics::context::PhysicsContext::getObject ( PhysicsObjectID  objectID)

Return a pointer to the state of the object with the specified ID in this context.

PhysicsObjectID om::physics::context::PhysicsContext::newObject ( const Transform3f &  transform = Transform3f(),
const Vector3f &  velocity = Vector3f(),
const Vector3f &  angularVelocity = Vector3f() 
)

Create a new object with the specified initial transform, velocity, and angular velocity.

Bool om::physics::context::PhysicsContext::deleteObject ( PhysicsObjectID  object)

Delete the object in the context with the specified ID.

The method returns whether or not the object was able to be deleted.

void om::physics::context::PhysicsContext::clearObjects ( )

Remove all currently simulated objects from this context.

All objects that are part of the context should not be referenced elsewhere when this method is called, or undefined behavior can result.

Size om::physics::context::PhysicsContext::getColliderCount ( ) const

Return the current number of colliders that are part of this context.

Collider* om::physics::context::PhysicsContext::getCollider ( ColliderID  colliderID)

Return a pointer to the collider with the specified ID in this context.

ColliderID om::physics::context::PhysicsContext::newCollider ( PhysicsShape shape)

Create a new collider with the given shape without a parent object.

ColliderID om::physics::context::PhysicsContext::newCollider ( PhysicsShape shape,
ObjectState object 
)

Create a new collider with a shape that is attached to the specified object.

ColliderID om::physics::context::PhysicsContext::newCollider ( PhysicsShape shape,
PhysicsObjectID  object 
)

Create a new collider with a shape that is attached to the object with the given ID.

Bool om::physics::context::PhysicsContext::deleteCollider ( ColliderID  collider)

Delete the collider in the context with the specified ID.

The method returns whether or not the collider was able to be deleted.

void om::physics::context::PhysicsContext::clearColliders ( )

Remove all colliders from this context.

All colliders that are part of the context should not be referenced elsewhere when this method is called, or undefined behavior can result.

const CollisionResultSet& om::physics::context::PhysicsContext::getCollisions ( ) const
inline

Return an object containing the collision results for the last frame.

Size om::physics::context::PhysicsContext::getConstraintCount ( ) const

Return the current number of constraints that are part of this context.

Constraint* om::physics::context::PhysicsContext::getConstraint ( ConstraintID  constraintID)

Return a pointer to the constraint with the specified ID in this context.

ConstraintID om::physics::context::PhysicsContext::newConstraint ( Constraint constraint,
UInt32  userID 
)

Create a new constraint in the context associated with no objects.

A pointer to a Constraint object that does the constraint processing is required, as well as a user ID that can be used to identify the constraint.

ConstraintID om::physics::context::PhysicsContext::newConstraint ( ObjectState object,
Constraint constraint,
UInt32  userID 
)

Create a new constraint in the context for a single object.

A pointer to a Constraint object that does the constraint processing is required, as well as a user ID that can be used to identify the constraint.

ConstraintID om::physics::context::PhysicsContext::newConstraint ( PhysicsObjectID  object,
Constraint constraint,
UInt32  userID 
)

Create a new constraint in the context for a single object.

A pointer to a Constraint object that does the constraint processing is required, as well as a user ID that can be used to identify the constraint.

ConstraintID om::physics::context::PhysicsContext::newConstraint ( ObjectState obj1,
ObjectState obj2,
Constraint constraint,
UInt32  userID 
)

Create a new constraint in the context between the specified object states.

A pointer to a Constraint object that does the constraint processing is required, as well as a user ID that can be used to identify the constraint.

ConstraintID om::physics::context::PhysicsContext::newConstraint ( PhysicsObjectID  obj1,
PhysicsObjectID  obj2,
Constraint constraint,
UInt32  userID 
)

Create a new constraint in the context between the objects with the given IDs.

A pointer to a Constraint object that does the constraint processing is required, as well as a user ID that can be used to identify the constraint.

Bool om::physics::context::PhysicsContext::deleteConstraint ( ConstraintID  constraint)

Delete the constraint in the context with the specified ID.

The method returns whether or not the constraint was able to be deleted.

void om::physics::context::PhysicsContext::clearConstraints ( )

Remove all constraints from this context.

ForceID om::physics::context::PhysicsContext::newForce ( Force force)

Create a new force in the context.

This method registers the specified Force object with the context so that its forces will be applied during simulation.

Bool om::physics::context::PhysicsContext::deleteForce ( ForceID  force)

Delete the force in the context with the specified ID.

The method returns whether or not the force was able to be deleted.

void om::physics::context::PhysicsContext::clearForces ( )

Remove all forces from this context.

ForceFieldID om::physics::context::PhysicsContext::newField ( ForceField forceField)

Create a new force field in the context.

This method registers the specified ForceField object with the context so that its forces will be applied during simulation.

Bool om::physics::context::PhysicsContext::deleteField ( ForceFieldID  forceFieldID)

Delete the force field in the context with the specified ID.

The method returns whether or not the force was able to be deleted.

void om::physics::context::PhysicsContext::clearFields ( )

Remove all force fields from this context.

PhysicsSceneID om::physics::context::PhysicsContext::newScene ( )

Create a new empty scene in the context.

The method returns the ID of the new scene.

Bool om::physics::context::PhysicsContext::deleteScene ( PhysicsSceneID  scene)

Delete the scene in the context with the specified ID.

The method returns whether or not the scene was able to be deleted.

void om::physics::context::PhysicsContext::clearScenes ( )

Remove all scenes from this context.

Bool om::physics::context::PhysicsContext::addSceneObject ( PhysicsSceneID  scene,
PhysicsObjectID  object 
)

Add an existing object to the scene with the given ID.

An object can be part of more than one scene. The method returns whether or not the object was able to be added to the scene.

Bool om::physics::context::PhysicsContext::removeSceneObject ( PhysicsSceneID  scene,
PhysicsObjectID  object 
)

Remove an existing object from the scene with the given ID.

The method returns whether or not the object was able to be removed from the scene.

Bool om::physics::context::PhysicsContext::addSceneCollider ( PhysicsSceneID  scene,
ColliderID  collider 
)

Add an existing collider to the scene with the given ID.

A collider can be part of more than one scene. The method returns whether or not the collider was able to be added to the scene.

Bool om::physics::context::PhysicsContext::removeSceneCollider ( PhysicsSceneID  scene,
ColliderID  collider 
)

Remove an existing collider from the scene with the given ID.

The method returns whether or not the collider was able to be removed from the scene.

Bool om::physics::context::PhysicsContext::addSceneConstraint ( PhysicsSceneID  scene,
ConstraintID  constraint 
)

Add an existing constraint to the scene with the given ID.

A constraint can be part of more than one scene. The method returns whether or not the constraint was able to be added to the scene.

Bool om::physics::context::PhysicsContext::removeSceneConstraint ( PhysicsSceneID  scene,
ConstraintID  constraint 
)

Remove an existing constraint from the scene with the given ID.

The method returns whether or not the constraint was able to be removed from the scene.

Bool om::physics::context::PhysicsContext::addSceneForce ( PhysicsSceneID  scene,
ForceID  force 
)

Add an existing force to the scene with the given ID.

A force can be part of more than one scene. The method returns whether or not the force was able to be added to the scene.

Bool om::physics::context::PhysicsContext::removeSceneForce ( PhysicsSceneID  scene,
ForceID  force 
)

Remove an existing force from the scene with the given ID.

The method returns whether or not the force was able to be removed from the scene.

Bool om::physics::context::PhysicsContext::addSceneField ( PhysicsSceneID  scene,
ForceFieldID  forceField 
)

Add an existing force field to the scene with the given ID.

A force field can be part of more than one scene. The method returns whether or not the force field was able to be added to the scene.

Bool om::physics::context::PhysicsContext::removeSceneField ( PhysicsSceneID  scene,
ForceFieldID  forceField 
)

Remove an existing force field from the scene with the given ID.

The method returns whether or not the force field was able to be removed from the scene.

CollisionBroadphase* om::physics::context::PhysicsContext::getSceneBroadphase ( PhysicsSceneID  scene) const

Return the collision broadphase that this context is using to find potentially colliding pairs for the given scene.

If the broadphase is NULL, the context uses a slower O(N^2) algorithm to find collisions.

Bool om::physics::context::PhysicsContext::setSceneBroadphase ( PhysicsSceneID  scene,
CollisionBroadphase newBroadphase 
)

Set the collision broadphase that this context is using to find potentially colliding pairs for the given scene.

The method returns whether or not the broadphase object can be successfully used to find collisions.

If the broadphase is NULL, the context uses a slower O(N^2) algorithm to find collisions.

CollisionNarrowphase* om::physics::context::PhysicsContext::getNarrowphase ( ) const
inline

Return the collision narrowphase that this ccontext is using to do collision detection between collider pairs.

If the narrowphase object is NULL, the context cannot detect any collisions.

Bool om::physics::context::PhysicsContext::setNarrowphase ( CollisionNarrowphase newNarrowphase)

Set the collision narrowphase that this context is using to do collision detection between collider pairs.

The method returns whether or not the narrowphase object can be successfully used to find collisions.

If the narrowphase object is NULL, the context cannot detect any collisions.

static void om::physics::context::PhysicsContext::applyForce ( SceneInfo scene,
Float  dt 
)
static

Apply forces to all objects in the specified scene.

static void om::physics::context::PhysicsContext::integrateForce ( SceneInfo scene,
Float  dt 
)
static

Integrate the force vectors to velocity for all objects in the specified scene.

static void om::physics::context::PhysicsContext::integrateVelocity ( SceneInfo scene,
Float  dt 
)
static

Integrate the velocity vectors to position for all objects in the specified scene.

static void om::physics::context::PhysicsContext::updateObjectTransforms ( SceneInfo scene)
static

Update the data dependent on the local-to-world transformations for all of the objects in this context.

static void om::physics::context::PhysicsContext::updateColliderTransforms ( SceneInfo scene)
static

Update the data dependent on the local-to-world transformations for all of the colliders in this context.

void om::physics::context::PhysicsContext::updateCollisions ( const SceneInfo scene,
const CollisionRequest request,
CollisionResultSet results 
)

Update all of the collisions that there are in this context.

void om::physics::context::PhysicsContext::solveConstraints ( SceneInfo scene,
const constraints::ConstraintRequest request,
Float  dt 
)

Solve all of the constraints in this context for the specified parameters.

static void om::physics::context::PhysicsContext::solveConstraintIsland ( const ConstraintIsland island,
const constraints::ConstraintRequest request,
Float  dt 
)
static

Solve a constraint island with the specified parameters.

void om::physics::context::PhysicsContext::rebuildConstraintIslands ( SceneInfo scene)

Rebuild the current set of constraint islands that this context is solving.

void om::physics::context::PhysicsContext::addConstraintToIslands ( SceneInfo scene,
const ConstraintInfo constraint 
)

Add the specified constraint to the current constraint islands for this context.

static UInt32 om::physics::context::PhysicsContext::newIsland ( SceneInfo scene)
inlinestatic

Create a new constraint island and return its index.

Member Data Documentation

const UInt32 om::physics::context::PhysicsContext::INVALID_ID = UInt32(-1)
static

The ID indicating an invalid object.

const UInt32 om::physics::context::PhysicsContext::ROOT_OBJECT_ID = 0
static

The ID of the root-level object for all collision shapes with no object.

TransformPool om::physics::context::PhysicsContext::transforms

A pool of transform states for the objects in this context.

VelocityPool om::physics::context::PhysicsContext::velocities

A pool of velocity states for the objects in this context.

MassPool om::physics::context::PhysicsContext::masses

A pool of mass states for the objects in this context.

ObjectStatePool om::physics::context::PhysicsContext::objects

A pool of the objects that are currently in this context.

ColliderPool om::physics::context::PhysicsContext::colliders

A pool of the colliders that are currently in this context.

ConstraintPool om::physics::context::PhysicsContext::constraints

A pool information about the constraints that are currently in this context.

ForcePool om::physics::context::PhysicsContext::forces

A pool of the colliders that are currently in this context.

FieldPool om::physics::context::PhysicsContext::fields

A pool of the force fields that are currently in this context.

ScenePool om::physics::context::PhysicsContext::scenes

A pool of the scenes that are currently in this context.

CollisionNarrowphase* om::physics::context::PhysicsContext::narrowphase

An object that this context is using to do collision detection between collider pairs.

CollisionResultSet om::physics::context::PhysicsContext::collisionResults

An object that stores temporary collision results for the context.


The documentation for this class was generated from the following file: