SoWorldPhysics Class Reference
[libipsa classes]

Defines the physical world and its properties. More...

#include <SoWorldPhysics.h>

Collaboration diagram for SoWorldPhysics:

Collaboration graph
[legend]

List of all members.

Public Types


Public Member Functions

float getStepsize ()
void initialiseWorld ()
bool isScheduled ()
virtual SbBool readInstance (SoInput *in, unsigned short flags)
void resetWorld ()
void schedule ()
void setStepsize (float stepSizeInSeconds)
virtual SbBool setUpConnections (SbBool onOff, SbBool doItAlways=FALSE)
 SoWorldPhysics (const SbString &nodeName="", int numChildren=5)
void unschedule ()
virtual ~SoWorldPhysics ()

Static Public Member Functions

static void ApplyActionToWorldPhysicNodesInGraph (SoCallbackAction::SoCallbackActionCB &cb, SoNode *root, void *userdata=NULL)
static void DeInit ()
static void Init ()
static void initClass ()
static void initClasses ()
static SoCallbackAction::Response InitialiseWorldCB (void *userdata, SoCallbackAction *, const SoNode *node)
static bool IsNaN (double value)
static void NearCallback (void *data, dGeomID o1, dGeomID o2)
static SoCallbackAction::Response ResetWorldCB (void *userdata, SoCallbackAction *action, const SoNode *node)
static SoCallbackAction::Response ScheduleWorldCB (void *userdata, SoCallbackAction *, const SoNode *node)
static void StepOde (void *data, SoSensor *)
static SoCallbackAction::Response UnscheduleWorldCB (void *userdata, SoCallbackAction *, const SoNode *node)
static SoCallbackAction::Response UpdateSingleWorldCB (void *, SoCallbackAction *action, const SoNode *node)

Public Attributes

SoSFFloat CFM
SoSFEnum ContactApprox
dJointGroupID contactgroup
const float DEFAULT_ODE_STEPSIZE
SoSFFloat ERP
SoSFVec3f gravity
const int MAX_BODY_CONTACTS
dSpaceID ownspace
dWorldID ownworld
SoSFInt32 sf1maxiterations
SoSFFloat SoftCFM
SoSFFloat SoftERP
SoSFEnum stepping

Protected Attributes

SbBool connectionsSetUp
SoFieldSensor updateOdeParamtersSensor
SoSFTrigger updateOdeParamtersTrigger

Private Member Functions

 SO_NODE_HEADER (SoWorldPhysics)

Static Private Member Functions

static void updateOdeParamtersCB (void *data, SoSensor *)

Private Attributes

std::vector< dJointFeedback > iContactFeedback
SoTimerSensor sens
SoSFFloat stepsize

Static Private Attributes

static bool bClassesInitialised = false
static bool bOdeColliderInitialised = false
static double frictioncoeff [SoCollisionShape::NO_OF_SURFACEMATERIALS][SoCollisionShape::NO_OF_SURFACEMATERIALS]


Detailed Description

Defines the physical world and its properties.

This class initialises the joints, bodies and collisionshapes by traversing the Inventor tree and computes the changes made to these elements.

Definition at line 43 of file SoWorldPhysics.h.


Member Enumeration Documentation

Enumerator:
BOXFRICTION 
PYRAMIDFRICTION 

Definition at line 90 of file SoWorldPhysics.h.

Enumeration for the different stepping types which can be used in ODE for the physics simulation.

Enumerator:
WORLDSTEP 
QUICKSTEP 
STEPFAST1 

Definition at line 100 of file SoWorldPhysics.h.


Constructor & Destructor Documentation

SoWorldPhysics::SoWorldPhysics ( const SbString &  nodeName = "",
int  numChildren = 5 
)

The standard constructor of SoWorldPhysics. Finally the method SoWorldPhysics::setUpConnections() is called to attach the field sensors to their fields

Parameters:
nodeName name of the node in the Inventor scenegraph
numChildren expected number of children (used to reserve memory beforehand)

Definition at line 235 of file SoWorldPhysics.cpp.

References BOXFRICTION, CFM, ContactApprox, contactgroup, DEFAULT_ODE_STEPSIZE, ERP, gravity, iContactFeedback, ownspace, ownworld, PYRAMIDFRICTION, QUICKSTEP, sens, setUpConnections(), sf1maxiterations, SoftCFM, SoftERP, STEPFAST1, StepOde(), stepping, stepsize, updateOdeParamtersCB(), updateOdeParamtersSensor, updateOdeParamtersTrigger, and WORLDSTEP.

SoWorldPhysics::~SoWorldPhysics (  )  [virtual]

The virtual standard destructor of SoWorldPhysics.

Definition at line 292 of file SoWorldPhysics.cpp.

References ownworld.


Member Function Documentation

void SoWorldPhysics::ApplyActionToWorldPhysicNodesInGraph ( SoCallbackAction::SoCallbackActionCB &  cb,
SoNode *  root,
void *  userdata = NULL 
) [static]

This method creates an SoCallbackAction with SoWorldPhysics as classTypeID and applies the passed in CallbackActionCB on every node found in the Inventor subgraph of root as a postcallback.

Parameters:
cb functionpointer to an SoCallbackActionCB
root Inventor node of type SoNode which the action should be applied to
userdata data pointer which is passed to the postcallback as userdata

Definition at line 690 of file SoWorldPhysics.cpp.

Referenced by IpsaSimulator::buildScenery(), IpsaSimulator::reset(), IpsaSimulator::schedule(), UnscheduleIPSA::vExecute(), and ScheduleIPSA::vExecute().

void SoWorldPhysics::DeInit (  )  [static]

Cleanup ODE by closing all ODE related resources.

Definition at line 218 of file SoWorldPhysics.cpp.

References bOdeColliderInitialised.

Referenced by IpsaSimulator::reload(), and IpsaSimulator::~IpsaSimulator().

float SoWorldPhysics::getStepsize (  ) 

Returns the currently used ODE stepsize.

Returns:
stepsize in seconds. Default value is SoWorldPhysics::DEFAULT_ODE_STEPSIZE.

Definition at line 723 of file SoWorldPhysics.cpp.

References stepsize.

Referenced by updateOdeParamtersCB().

void SoWorldPhysics::Init (  )  [static]

Initialises ODE

Definition at line 205 of file SoWorldPhysics.cpp.

References bOdeColliderInitialised.

Referenced by initClass(), and IpsaSimulator::reload().

void SoWorldPhysics::initClass (  )  [static]

Initialises the class and it's type id variables.

Definition at line 194 of file SoWorldPhysics.cpp.

References Init().

Referenced by initClasses().

void SoWorldPhysics::initClasses (  )  [static]

This method initialises all ipsa classes by calling the initClass() method on every IPSA class.

Definition at line 768 of file SoWorldPhysics.cpp.

References bClassesInitialised, and initClass().

Referenced by IpsaSimulator::IpsaSimulator().

void SoWorldPhysics::initialiseWorld (  ) 

Initialises the physical world. This method initialises all collisionshapes, all bodies and all joints in the current world.

Definition at line 593 of file SoWorldPhysics.cpp.

References SoCollisionShape::InitCollisionShapesCB(), SoPhysics::InitialiseOdeBodiesCB(), and SoJoint::InitOdeJointsCB().

Referenced by InitialiseWorldCB().

SoCallbackAction::Response SoWorldPhysics::InitialiseWorldCB ( void *  userdata,
SoCallbackAction *  action,
const SoNode *  node 
) [static]

This method calls initialiseWorld() on every SoWorldPhysics object passed to it through an SoCallbackAction.

Parameters:
userdata UNUSED
action UNUSED
node node of type SoWorldPhysics

Definition at line 621 of file SoWorldPhysics.cpp.

References initialiseWorld().

Referenced by IpsaSimulator::buildScenery().

bool SoWorldPhysics::IsNaN ( double  value  )  [static]

Tests whether the passed in variable has the value NaN. According to the IEEE floating point spec this test is only true if the value is NaN.

Parameters:
value the double value to test for NaN
Returns:
true if value is NaN, false otherwise

Definition at line 758 of file SoWorldPhysics.cpp.

Referenced by NearCallback().

SoWorldPhysics::isScheduled (  )  [inline]

Returns:
true if current world is scheduled, false otherwise

Definition at line 77 of file SoWorldPhysics.h.

void SoWorldPhysics::NearCallback ( void *  data,
dGeomID  o1,
dGeomID  o2 
) [static]

Creates a contact joint for the collision handling. This method creates a contact joint and sets its attributes for the refered bodies. If the two bodies are connected by a joint the method exits without doing anything.

If measureContactForces is set on one of the bodies a friction cone is created and added to the scenegraph.

Parameters:
data pointer which is cast to an SoWorldPhysics object
o1 the dGeomID of body 1
o2 the dGeomID of body 2

Definition at line 311 of file SoWorldPhysics.cpp.

References ContactApprox, contactgroup, frictioncoeff, iContactFeedback, IsNaN(), MAX_BODY_CONTACTS, SoPhysics::measureContactForces, SoCollisionShape::NO_OF_SURFACEMATERIALS, ownworld, SoftCFM, SoftERP, and SoCollisionShape::surfaceMaterial.

Referenced by UpdateSingleWorldCB().

SbBool SoWorldPhysics::readInstance ( SoInput *  in,
unsigned short  flags 
) [virtual]

This method is called when the node is read from an Inventor file. It is implemented as suggested in the Inventor Toolmaker book and calls SoWorldPhysics::setUpConnections() to detach the sensors, then SoSeparator::readInstance() and afterwards SoWorldPhysics::setUpConnections() again to reattach the sensors.

Parameters:
in the input stream to read the node from
flags some coin specific flags (not of interest)

Definition at line 492 of file SoWorldPhysics.cpp.

References setUpConnections().

void SoWorldPhysics::resetWorld (  ) 

Resets all SoWorldPhysics and SoPhysics in subgraph. This method calls ResetPhysicBodyCB on every SoPhysics object and reinitializes all joints to their initial values in the inventor graph passed in through the data pointer.

Definition at line 570 of file SoWorldPhysics.cpp.

References contactgroup, iContactFeedback, SoJoint::InitOdeJointsCB(), SoFrictionCone::RemoveAllFrictionConesFromGraph(), and SoPhysics::ResetOdeBodiesCB().

Referenced by ResetWorldCB().

SoCallbackAction::Response SoWorldPhysics::ResetWorldCB ( void *  userdata,
SoCallbackAction *  action,
const SoNode *  node 
) [static]

This method calls resetWorld() on every SoWorldPhysics object passed to it through an SoCallbackAction.

Parameters:
userdata UNUSED
action UNUSED
node node of type SoWorldPhysics

Definition at line 638 of file SoWorldPhysics.cpp.

References resetWorld().

Referenced by IpsaSimulator::reset().

void SoWorldPhysics::schedule (  ) 

Schedules the ODE timer which means that the simulation is started or resumed.

Definition at line 731 of file SoWorldPhysics.cpp.

References sens.

Referenced by ScheduleWorldCB().

SoCallbackAction::Response SoWorldPhysics::ScheduleWorldCB ( void *  userdata,
SoCallbackAction *  action,
const SoNode *  node 
) [static]

This method calls schedule() on every SoWorldPhysics object passed to it through an SoCallbackAction.

Parameters:
userdata UNUSED
action UNUSED
node node of type SoWorldPhysics

Definition at line 655 of file SoWorldPhysics.cpp.

References schedule().

Referenced by IpsaSimulator::schedule(), and ScheduleIPSA::vExecute().

void SoWorldPhysics::setStepsize ( float  stepSizeInSeconds  ) 

Sets the stepsize which is used by ODE to calculate the timesteps. If the value is greater than 0.0 the value is set as the new stepsize, otherwise the value is rejected and the old one is used.

Parameters:
stepSizeInSeconds the new stepsize in [seconds].

Definition at line 704 of file SoWorldPhysics.cpp.

References stepsize.

Referenced by SetStepsizeIPSA::vExecute().

SbBool SoWorldPhysics::setUpConnections ( SbBool  onOff,
SbBool  doItAlways = FALSE 
) [virtual]

Attachs different sensors to the corresponding fields. This method monitors field-changes on the gravity, ERP, CFM and stepsize variables and calls the SoWorldPhysics::updateOdeParamtersCB if necessary.

Parameters:
onOff attach sensors if TRUE, detach sensors if FALSE
doItAlways always perform attach/detach of sensors if this parameter is TRUE
Returns:
SbBool

Definition at line 460 of file SoWorldPhysics.cpp.

References connectionsSetUp, updateOdeParamtersCB(), updateOdeParamtersSensor, and updateOdeParamtersTrigger.

Referenced by readInstance(), and SoWorldPhysics().

SoWorldPhysics::SO_NODE_HEADER ( SoWorldPhysics   )  [private]

void SoWorldPhysics::StepOde ( void *  data,
SoSensor *   
) [static]

Steps the ODEWorld. This method updates the ODEWorld by calling the UpdateSingleWorldCB on every SoWorldPhysics object and SoPhysics::UpdateOdeBodiesCB on every SoPhysics object in the inventor graph passed in through the data pointer.

Parameters:
data pointer to the inventor graph to step through

Definition at line 549 of file SoWorldPhysics.cpp.

References SoPhysics::UpdateOdeBodiesCB(), and UpdateSingleWorldCB().

Referenced by SoWorldPhysics(), and StepIPSA::vExecute().

void SoWorldPhysics::unschedule (  ) 

Unschedules the ODE timer which means that the simulation is stopped or paused.

Definition at line 741 of file SoWorldPhysics.cpp.

References sens.

Referenced by UnscheduleWorldCB().

SoCallbackAction::Response SoWorldPhysics::UnscheduleWorldCB ( void *  userdata,
SoCallbackAction *  action,
const SoNode *  node 
) [static]

This method calls unschedule() on every SoWorldPhysics object passed to it through an SoCallbackAction.

Parameters:
userdata UNUSED
action UNUSED
node node of type SoWorldPhysics

Definition at line 672 of file SoWorldPhysics.cpp.

References unschedule().

Referenced by IpsaSimulator::schedule(), and UnscheduleIPSA::vExecute().

void SoWorldPhysics::updateOdeParamtersCB ( void *  data,
SoSensor *   
) [static, private]

Callback function which is called everytime one of the gravity, ERP, CFM or stepsize variables changes and updates the ODE values and the interval of the timersensor.

Parameters:
data pointer which is cast into an SoWorldPhysics object

Definition at line 431 of file SoWorldPhysics.cpp.

References CFM, ERP, getStepsize(), gravity, ownworld, and sens.

Referenced by setUpConnections(), and SoWorldPhysics().

SoCallbackAction::Response SoWorldPhysics::UpdateSingleWorldCB ( void *  userdata,
SoCallbackAction *  action,
const SoNode *  node 
) [static]

Updates the SoWorldPhysics objects. This method traverses the Inventor tree and computes for each SoWorldPhysics node the current state and deletes all the temporary contact joints and friction cones.

Parameters:
userdata UNUSED
action UNUSED
node node of type SoWorldPhysics

Definition at line 509 of file SoWorldPhysics.cpp.

References contactgroup, iContactFeedback, NearCallback(), ownspace, ownworld, QUICKSTEP, SoFrictionCone::RemoveAllFrictionConesFromGraph(), stepping, stepsize, and WORLDSTEP.

Referenced by StepOde().


Member Data Documentation

bool SoWorldPhysics::bClassesInitialised = false [static, private]

This static variable stores if SoWorldPhysics::initClasses() has already been called to avoid multiple initialisations of the IPSA classes (default = false).

Definition at line 125 of file SoWorldPhysics.h.

Referenced by initClasses().

bool SoWorldPhysics::bOdeColliderInitialised = false [static, private]

This static variable stores if SoWorldPhysics::initClass() has already been called and ODE has been initialised to avoid multiple initialisations of the ODE engine (default = false).

Definition at line 124 of file SoWorldPhysics.h.

Referenced by DeInit(), and Init().

CFM defines constraint force mixing (default = 1E-8f).
If CFM is set to zero, the constraint will be hard. If CFM is set to a positive value, it will be possible to violate the constraint by ``pushing on it'' (for example, for contact constraints by forcing the two contacting objects together)

Definition at line 86 of file SoWorldPhysics.h.

Referenced by SoWorldPhysics(), and updateOdeParamtersCB().

Stores if the field sensors are attached or not.

Definition at line 115 of file SoWorldPhysics.h.

Referenced by setUpConnections().

(default = SoWorldPhysics::BOXFRICTION);

Definition at line 96 of file SoWorldPhysics.h.

Referenced by NearCallback(), and SoWorldPhysics().

A contactgroup consisting of several geoms.

Definition at line 97 of file SoWorldPhysics.h.

Referenced by NearCallback(), resetWorld(), SoWorldPhysics(), and UpdateSingleWorldCB().

The value of stepsize used by ODE is 0.004f [sec].

Definition at line 110 of file SoWorldPhysics.h.

Referenced by SoWorldPhysics().

The error reduction parameter (erp) specifies what proportion of the joint error will be fixed during the next simulation step (default = 0.2f).
If ERP=0 then no correcting force is applied and the bodies will eventually drift apart as the simulation proceeds. If ERP=1 then the simulation will attempt to fix all joint error during the next time step. However, setting ERP=1 is not recommended, as the joint error will not be completely fixed due to various internal approximations. A value of ERP=0.1 to 0.8 is recommended .

Definition at line 85 of file SoWorldPhysics.h.

Referenced by SoWorldPhysics(), and updateOdeParamtersCB().

double SoWorldPhysics::frictioncoeff [static, private]

Initial value:

{

    { 0.0, 1.0, 0.0, 0.0, 0.0 ,0.0}, 
    { 1.0, 1.0, 1.0, 1.0, 1.0 ,1.0}, 
    { 0.0, 1.0, 0.4, 0.3, 0.3 ,0.5}, 
    { 0.0, 1.0, 0.3, 0.4, 0.6 ,0.8}, 
    { 0.0, 1.0, 0.2, 0.3, 0.7 ,0.8}, 
    { 0.0, 1.0, 0.5, 0.8, 0.8 ,1.0}  
}
This is a table which contains the friction coefficient for all the combinations of surface materials defined in SoCollisionshape::eSurfaceMaterial.

Definition at line 127 of file SoWorldPhysics.h.

Referenced by NearCallback().

The gravity vector of the current world (default = {0.0f, -9.81f, 0.0f}).
Default value is gravity on earth.

Definition at line 84 of file SoWorldPhysics.h.

Referenced by SoWorldPhysics(), and updateOdeParamtersCB().

The contactjoint feedback is stored in this vector for later use.
It is just necessary to reserve memory for the dJointFeedback structures for ODE to keep them around. Otherwise they will get deleted and ODE can not be queried about their values anymore.

Definition at line 122 of file SoWorldPhysics.h.

Referenced by NearCallback(), resetWorld(), SoWorldPhysics(), and UpdateSingleWorldCB().

Maximum number of contact points per body to consider for collision calculations (value = 64).

Definition at line 109 of file SoWorldPhysics.h.

Referenced by NearCallback().

The spaceID of the current SoWorldPhysics.

Definition at line 82 of file SoWorldPhysics.h.

Referenced by SoCollisionShape::InitCollisionShapesCB(), SoWorldPhysics(), and UpdateSingleWorldCB().

This timer sensor is used to step through the ODE world.
It calls SoWorldPhysics::StepOde() on every timer interrupt. The value stored in SoWorldPhysics::stepsize is used as timestep.

Definition at line 121 of file SoWorldPhysics.h.

Referenced by schedule(), SoWorldPhysics(), unschedule(), and updateOdeParamtersCB().

(default = 5)

Definition at line 107 of file SoWorldPhysics.h.

Referenced by SoWorldPhysics().

(default = 0.001f)

Definition at line 88 of file SoWorldPhysics.h.

Referenced by NearCallback(), and SoWorldPhysics().

(default = -1.0f)
Unused if value < 0.

Definition at line 87 of file SoWorldPhysics.h.

Referenced by NearCallback(), and SoWorldPhysics().

Defines which stepping method to use in ODE (default = SoWorldPhysics::QUICKSTEP).

Definition at line 106 of file SoWorldPhysics.h.

Referenced by SoWorldPhysics(), and UpdateSingleWorldCB().

The stepsize of the SoWorldPhysics object (default = SoWorldPhysics::DEFAULT_ODE_STEPSIZE).

Definition at line 120 of file SoWorldPhysics.h.

Referenced by getStepsize(), setStepsize(), SoWorldPhysics(), and UpdateSingleWorldCB().

Sensor which reacts on changes to SoWorldPhysics::updateOdeParamtersTrigger by calling SoWorldPhysics::updateOdeParamtersCB().

Definition at line 114 of file SoWorldPhysics.h.

Referenced by setUpConnections(), and SoWorldPhysics().

Variable which triggers a change in the connected SoWorldPhysics::updateOdeParamtersSensor by calling SoWorldPhysics::updateOdeParamtersCB() if any of the following variables change their value:

Definition at line 113 of file SoWorldPhysics.h.

Referenced by setUpConnections(), and SoWorldPhysics().


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

Get IPSA - Inventor Physics Simulation API at SourceForge.net. Fast, secure and Free Open Source software downloads
Generated on Sat Mar 10 20:00:21 2012 for IPSA by  doxygen 1.5.8