Physics Class Reference

#include <Physics.h>

Inherits ModuleInterface.

Collaboration diagram for Physics:

List of all members.


Classes

class  ConverterToV1_0a4

Public Member Functions

 Physics ()
virtual ~Physics ()
virtual bool loadConfig (std::string configFile)
virtual void cleanup ()
virtual std::string getName ()
virtual EventcreateSyncEvent ()
void registerPhysicsObjectManagerFactory (PhysicsObjectManagerFactory *factory)
void registerSynchronisationModelFactory (SynchronisationModelFactory *factory)
void init ()
void start ()
void startOnEvent ()
void kill ()
void simulate ()
bool addPhysicsObject (PhysicsObjectInterface *object)
bool removePhysicsObject (PhysicsObjectInterface *object)
PhysicsObjectInterfaceremovePhysicsObject (PhysicsObjectID physicsObjectID)
bool addSystemThreadListener (SystemThreadListenerInterface *listener)
bool removeSystemThreadListener (SystemThreadListenerInterface *listener)
bool addSimulationStepListener (SimulationStepListenerInterface *listener)
bool removeSimulationStepListener (SimulationStepListenerInterface *listener)
void update (float dt)
oops::SimulationgetSimulation ()
oops::XMLLoadergetXMLLoader ()
unsigned getSimulationTime ()
float getStepSize ()
bool isPhysicsServer ()
bool doesPhysicsCalculations ()

Static Public Attributes

static inVRsUtilities::Timer physicsTimer = inVRsUtilities::Timer(true)

Protected Member Functions

PhysicsObjectManagercreatePhysicsObjectManager (std::string className, ArgumentVector *args)
SynchronisationModelcreateSynchronisationModel (std::string className, ArgumentVector *args)
void step ()
void handleEvents ()
void handleSimulationStepListener (float dt)
void setStartTime (double time)
void setSynchronisationModel (std::string modelName, ArgumentVector *args)

Static Protected Member Functions

static void run (void *args)

Protected Attributes

bool alreadyCleanedUp
 Used to ignore method calls after cleanup is called.
OSG::Lock * simulationStepLock
 Lock for simulation step so that no PhysicsObject can be removed.
OSG::Lock * systemThreadListenerLock
 Lock for systemThreadListener-list.
OSG::Lock * simulationStepListenerLock
 Lock for simulationStepListener-list.
oops::Simulationsimulation
 Simulation instance running the underlying simulation.
oops::XMLLoaderxmlLoader
 XMLLoader used for loading physics objects from file.
float stepSize
 number of seconds between two simulation steps
double simulationStartTime
 time when the simulation is started -> needed to synchronise simulationTimes!!!
unsigned simulationTime
float simLastTime
 timestamp of last simulation call (used in Physics::simulate)
float simTimeToNextStep
 time until next simulation step (used in Physics::simulate)
float simFpsTime
 time since last FPS output, done every sec (used in Physics::simulate)
unsigned simFpsCounter
 FPS counter (used in Physics::simulate).
float simulationLoad
 Load of the Physics Thread (used in Physics::run).
std::vector
< PhysicsObjectManagerFactory * > 
objectManagerFactories
 factories for PhysicsObjectManager
PhysicsObjectManagerobjectManager
 actually used objectManager
std::vector
< SystemThreadListenerInterface * > 
systemThreadListener
 list for all registered SystemThreadListener
std::vector
< SimulationStepListenerInterface * > 
simulationStepListener
 list for all registered SimulationStepListener
EventPipeincomingEvents
 EventPipe for incoming Events.
std::vector
< SynchronisationModelFactory * > 
synchronisationModelFactories
 factories for SynchronisationModels
SynchronisationModelsynchronisationModel
 Model which handles synchronisation between servers and clients.
OSG::Thread * physicsThread
 list with the IDs of all directly (network link) connected Users

Static Protected Attributes

static volatile double startTime
static Physicssingleton = NULL
 Module instance stored to be accessed by run-method.
static volatile bool running
 bool indicating if the physics thread is running
static volatile bool shutdown
 bool indicating that the physics thread should be killed
static volatile bool waitForEvent
 bool indicating that the simulation should start when event is received

Static Private Attributes

static XmlConfigurationLoader xmlConfigLoader

Friends

class ChangedUserDataEvent
class PhysicsObjectManager
class SynchronisePhysicsEvent
class SynchronisationModel
class StartSimulationEvent
class ChangeSynchronisationModelEvent

Detailed Description

inVRs module for multi-user physics simulation. The Physics class is an inVRs module for physics simulation in a networked multi-user virtual environment. The physics simulation is based on the oops library which is an object oriented wrapper to the Open Dynamics Engine (ODE). The distribution of the simulation is managed by a plugable ObjectManager which handles the synchronisation of the physics data. The plugin-mechanism allows the module to be used in any network structure.

Constructor & Destructor Documentation

Physics::Physics (  ) 

Constructor initializes basic variables. The constructor registers the module at the SystemCore, creates a new instance of the oops::simulation class and configures this class. It furthermore registers the PhysicsEventFactory to the EventManager and creates the default PhysicsObjectManagerFactories.

Physics::~Physics (  )  [virtual]

Destructor cleans up the Module. The destructor deletes all registered PhysicsObjectManagerFactories and deletes the instance of the oops::simulation class.


Member Function Documentation

bool Physics::addPhysicsObject ( PhysicsObjectInterface object  ) 

Adds a new PhysicsObject to the Simulation. The method forwards the call to the used objectManager.

Returns:
true if the object could be added, false otherwise

bool Physics::addSimulationStepListener ( SimulationStepListenerInterface listener  ) 

Registers a SimulationStepListener. The method adds the passed listener to the simulationStepListener list. These listener will then be notified every time the step method is called.

Parameters:
listener SimulationStepListener which should be added
Returns:
true if the listener could be registered, false if not

bool Physics::addSystemThreadListener ( SystemThreadListenerInterface listener  ) 

Registers a SystemThreadListener. The method adds the passed listener to the systemThreadListener list. These listener will then be notified every time the update method is called. NOTE: The method has to be called from the system thread! There is no Lock which allows this registration from another thread! It is suggested you register the listener in the constructor of the implemented class and check on the callback if the object is already added to the simulation.

Parameters:
listener SystemThreadListener which should be added
Returns:
true if the listener could be registered, false if not

void Physics::cleanup (  )  [virtual]

Cleans up the Module. The method deletes all registered PhysicsObjects and the ObjectManager

Reimplemented from ModuleInterface.

PhysicsObjectManager * Physics::createPhysicsObjectManager ( std::string  className,
ArgumentVector args 
) [protected]

Parses the Element <userData> from the xml-configuration.

Parameters:
xml Pointer to the XML reader
Returns:
true if element could be parsed correctly Returns a new PhysicsObjectManager of the passed class-type. The method asks all registered PhysicsObjectManagerFactories to create a new PhysicsObjectManager with the passed className. If a matching factory is found the new Manager is returned.
Parameters:
className name of the PhysicsObjectManager which should be created
args arguments given to the factory
Returns:
new PhysicsObjectManager if factory is found, NULL otherwise

Event * Physics::createSyncEvent (  )  [virtual]

Returns a SynchronisePhysicsEvent. The event is used to synchronise the current state of the Module to new users.

Returns:
SynchronisePhysicsEvent which includes all relevant Physics data

Reimplemented from ModuleInterface.

SynchronisationModel * Physics::createSynchronisationModel ( std::string  className,
ArgumentVector args 
) [protected]

Returns a new SynchronisationModel of the passed class-type. The method asks all registered SynchronisationModelFactories to create a new SynchronisationModel with the passed className. If a matching factory is found the new Model is returned.

Parameters:
className name of the SynchronisationModel which should be created
args arguments passed to the factory
Returns:
new SynchronisationModel if factory is found, NULL otherwise

bool Physics::doesPhysicsCalculations (  ) 

Returns if the physics module does physics calculations (either server or client side)

std::string Physics::getName (  )  [virtual]

Returns the name of the Module.

Returns:
Name of the Module (Physics)

Implements ModuleInterface.

Simulation * Physics::getSimulation (  ) 

Returns the simulation instance. The method returns the instance of the oops::Simulation class

Returns:
instance of the oops::Simulation class

unsigned Physics::getSimulationTime (  ) 

Returns the current simulation time. The method returns the current simulation time.

Returns:
current simulation time

float Physics::getStepSize (  ) 

Returns the duration of one simulation step in seconds.

Returns:
size of one simulation step

oops::XMLLoader * Physics::getXMLLoader (  ) 

Returns the XMLLoader used for loading physics objects. The method returns the XMLLoader instance which is used internally for loading RigidBodies, ArticulatedBodies, Joints and Geometries.

Returns:
instance of the oops::XMLLoader class

void Physics::handleEvents (  )  [protected]

Handles all incoming Physics-Events. The method reads all incoming Events from the EventPipe and executes them.

void Physics::handleSimulationStepListener ( float  dt  )  [protected]

Notifies all registered SimulationStepListener that a new step occurs. The method calls the step-method of all registered SimulationStepListener.

Parameters:
dt the passed timestep, which is equal to the stepSize

void Physics::init (  ) 

Initializes the Physics Module. The method has to be called after the loadConfig method was initiated. Therefore it is used to initialize data that needs this or other Modules to be configured already. In the moment it only requests an EventPipe from the EventManager.

bool Physics::isPhysicsServer (  ) 

Returns if the physics module acts as server for some objects

void Physics::kill (  ) 

Kills the Physics Simulation Thread. The method kills the Physics Simulation Thread and waits until the Thread has terminated before it returns.

bool Physics::loadConfig ( std::string  configFile  )  [virtual]

Loads the configuration for the Module from a config file. The method parses the passed XML file and configures the Module according to the data in the config file.

Parameters:
configFile URL of the configFile which should be loaded
Returns:
true if the loading of the configuration succeeded, false otherwise

Implements ModuleInterface.

void Physics::registerPhysicsObjectManagerFactory ( PhysicsObjectManagerFactory factory  ) 

Registers a new PhysicsObjectManagerFactory to the Module. The passed factory is stored in the Module and is used to build the apropriate PhysicsObjectManager in the loadConfig-method if this Manager is configured in the XML-file. The factory will be deleted by the Physics Module when the destructor is called.

Parameters:
factory PhysicsObjectManagerFactory which should be registered

void Physics::registerSynchronisationModelFactory ( SynchronisationModelFactory factory  ) 

Registers a new SynchronisationModelFactory to the Module. The passed factory is stored in the Module and is used to build the appropriate SynchronisationModel in the loadConfig-method if this Model is configured in the XML-file. The factory will be deleted by the Physics Module when the destructor is called.

Parameters:
factory SynchronisationModelFactory which should be registered

PhysicsObjectInterface * Physics::removePhysicsObject ( PhysicsObjectID  physicsObjectID  ) 

Removes a PhysicsObject from the Simulation. The method forwards the call to the used objectManager.

Returns:
true if the object could be removed, false otherwise

bool Physics::removePhysicsObject ( PhysicsObjectInterface object  ) 

Removes a PhysicsObject from the Simulation. The method forwards the call to the used objectManager.

Returns:
true if the object could be removed, false otherwise

bool Physics::removeSimulationStepListener ( SimulationStepListenerInterface listener  ) 

Removes a registered SimulationStepListener. The method removes the passed listener from the simulationStepListener list.

Parameters:
listener SimulationStepListener which should be removed
Returns:
true if the listener could be removed, false otherwise

bool Physics::removeSystemThreadListener ( SystemThreadListenerInterface listener  ) 

Removes a registered SystemThreadListener. The method removes the passed listener from the systemThreadListener list. NOTE: The method has to be called from the system thread! It is suggested that the method is called by the destructor of the implemented class.

Parameters:
listener SystemThreadListener which should be removed
Returns:
true if the listener could be removed, false otherwise

void Physics::run ( void *  args  )  [static, protected]

Runs the physics simulation until it is killed. The method runs in an own thread and loops until the Physics::kill method is called. It does the Physics simulation by calling the step-method after the number of seconds defined as stepSize are passed.

Parameters:
args is not used, only needed to match to the Threading-interface

void Physics::setStartTime ( double  time  )  [protected]

void Physics::setSynchronisationModel ( std::string  modelName,
ArgumentVector args 
) [protected]

Changes the used SynchronisationModel during runtime The method is called by the PhysicsChangeSynchronisationModelEvent in order to change the used SynchronisationModel during runtime

Parameters:
modelName Name of the new SynchronisationModel
args Arguments for the Model

void Physics::simulate (  ) 

Runs the Physics Simulation in the same Thread. The method determines how much time elapsed since the last call and runs the according number of simulation steps. The simulation itself is done in the same thread as the method was called. This allows to run the Physics Simulation in single threaded mode. NOTE: If you want to run the simulation in the same Thread as the rest then don't call the start method!

void Physics::start (  ) 

Starts the Physics Simulation in an own Thread. The method creates a new Thread and starts the static Physics::run-method which runs the physics simulation.

void Physics::startOnEvent (  ) 

Starts the Physics Simulation in an own Thread after a StartPhysicsSimulationEvent is received. This is used to synchronise multiple participants.

void Physics::step (  )  [protected]

Runs a simulation step. The method handles the incoming Events and Messages, notifies the SimulationStepListener, synchronises the PhysicsObjectManager and run the virtual simulation step.

void Physics::update ( float  dt  )  [virtual]

Update call for system thread. The method call notifies all registered systemThreadListener.

Parameters:
dt elapsed time since last system thread call

Reimplemented from ModuleInterface.


Friends And Related Function Documentation

friend class ChangedUserDataEvent [friend]

friend class ChangeSynchronisationModelEvent [friend]

friend class PhysicsObjectManager [friend]

friend class StartSimulationEvent [friend]

friend class SynchronisationModel [friend]

friend class SynchronisePhysicsEvent [friend]


Member Data Documentation

bool Physics::alreadyCleanedUp [protected]

Used to ignore method calls after cleanup is called.

EventPipe for incoming Events.

actually used objectManager

OSG::Thread* Physics::physicsThread [protected]

list with the IDs of all directly (network link) connected Users

map with the relevant data for each user Pointer to physics Thread, used to not start Thread two times

volatile bool Physics::running [static, protected]

bool indicating if the physics thread is running

volatile bool Physics::shutdown [static, protected]

bool indicating that the physics thread should be killed

unsigned Physics::simFpsCounter [protected]

FPS counter (used in Physics::simulate).

float Physics::simFpsTime [protected]

time since last FPS output, done every sec (used in Physics::simulate)

float Physics::simLastTime [protected]

timestamp of last simulation call (used in Physics::simulate)

float Physics::simTimeToNextStep [protected]

time until next simulation step (used in Physics::simulate)

Simulation instance running the underlying simulation.

float Physics::simulationLoad [protected]

Load of the Physics Thread (used in Physics::run).

double Physics::simulationStartTime [protected]

time when the simulation is started -> needed to synchronise simulationTimes!!!

list for all registered SimulationStepListener

OSG::Lock* Physics::simulationStepListenerLock [protected]

Lock for simulationStepListener-list.

OSG::Lock* Physics::simulationStepLock [protected]

Lock for simulation step so that no PhysicsObject can be removed.

unsigned Physics::simulationTime [protected]

step counter since simulation start. will be increased every simulation step, unsigned seems to be enough since the simulation can run about 50 days with a simulation rate of 1000 steps per second, where ODE surely crashes before ;-)

OSG_USING_NAMESPACE Physics * Physics::singleton = NULL [static, protected]

Module instance stored to be accessed by run-method.

volatile double Physics::startTime [static, protected]

float Physics::stepSize [protected]

number of seconds between two simulation steps

Model which handles synchronisation between servers and clients.

factories for SynchronisationModels

list for all registered SystemThreadListener

OSG::Lock* Physics::systemThreadListenerLock [protected]

Lock for systemThreadListener-list.

volatile bool Physics::waitForEvent [static, protected]

bool indicating that the simulation should start when event is received

XMLLoader used for loading physics objects from file.


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

Generated on Wed Oct 20 16:11:59 2010 for inVRs by doxygen 1.5.8