SoPhysics Class Reference
[libipsa classesPhysic Classes]

Defines the base class for Inventor physic object. More...

#include <SoPhysics.h>

Inheritance diagram for SoPhysics:

Inheritance graph
[legend]

List of all members.

Public Member Functions

virtual SoBaseKit * copy (SbBool copyConnections) const
void createOdeBody (SoCallbackAction *action)
dBodyID getBody ()
SoSFVec3f getCurrentForce ()
SoSFVec3f getCurrentLinearVel ()
SoSFVec3f getCurrentPosition ()
SoSFVec3f getCurrentTorque ()
SbMatrix getMatrixTransform ()
SbMatrix getOIMatrixTransform ()
dWorldID getWorld ()
void resetOdeBody (SoCallbackAction *action)
void setCollisionShapeVisibility (SbBool visible)
void setForce (const SbVec3f &force)
void setForceAtPosition (const SbVec3f &force, const SbVec3f &position)
void setLinearVel (const SbVec3f &vel)
void setRelForce (const SbVec3f &force)
void setRelForceAtPosition (const SbVec3f &force, const SbVec3f &position)
void setTorque (const SbVec3f &torque)
virtual SbBool setUpConnections (SbBool onOff, SbBool doItAlways=FALSE)
void setWorld (dWorldID w)
 SoPhysics (const SbString &nodeName="")
void updateOdeBody (SoCallbackAction *action)
virtual ~SoPhysics ()

Static Public Member Functions

static void initClass ()
static SoCallbackAction::Response InitialiseOdeBodiesCB (void *userdata, SoCallbackAction *, const SoNode *node)
static SoCallbackAction::Response ResetOdeBodiesCB (void *userdata, SoCallbackAction *action, const SoNode *node)
static SoCallbackAction::Response UpdateOdeBodiesCB (void *, SoCallbackAction *action, const SoNode *node)

Public Attributes

SoSFVec3f angVelocity
SoSFBool AUTO_UPDATE_COLLISION_SHAPE
SoSFBool drawCollisionShape
SoMFVec3f forceField
SoMFVec3f forcePos
SoMFVec3f inertia
SoMFNode jointList
SoSFVec3f linVelocity
SoSFFloat mass
SoSFBool measureContactForces
SoSFVec3f scale
SoMFVec3f torqueField

Protected Member Functions

virtual dMass getInitialMass ()
virtual void updateDependentObjects ()
virtual void updateOIPosition ()

Protected Attributes

dBodyID body
SbMatrix CoinRefTransform
SoFieldSensor fieldUpdateSensor
SoSFTrigger fieldUpdateTrigger
dGeomID geom
SbVec3f init_angVelocity
SbVec3f init_linVelocity
bool isInitialised
dWorldID myWorld
SoMatrixTransform * transform
SoFieldSensor updateDependentObjectsSensor
SoSFTrigger updateDependentObjectsTrigger

Private Member Functions

 SO_KIT_CATALOG_ENTRY_HEADER (visualisationShape)
 SO_KIT_CATALOG_ENTRY_HEADER (ODETransform)
 SO_KIT_CATALOG_ENTRY_HEADER (collisionShape)
 SO_KIT_CATALOG_ENTRY_HEADER (reset)
 SO_KIT_CATALOG_ENTRY_HEADER (separator)
 SO_KIT_HEADER (SoPhysics)
void updateOdeBodyParameters (const SbMatrix &actionModelMatrix)

Static Private Member Functions

static void FieldChangedCB (void *data, SoSensor *)
static void UpdateDependentObjectsCB (void *data, SoSensor *sensor)


Detailed Description

Defines the base class for Inventor physic object.

There are different types of physics which are described more precisely in the inherited classes of SoPhysics.

See How to create a new IPSA physics body for detailed instructions on how to create new IPSA collision shapes.

Definition at line 46 of file SoPhysics.h.


Constructor & Destructor Documentation

SoPhysics::SoPhysics ( const SbString &  nodeName = ""  ) 

The constructor of SoPhysics Creates the SoFieldSensor instances, calls SoBaseKit::setName() and at last SoPhysics::setUpConnections() with TRUE for both parameters.

Parameters:
nodeName name of the node in the Inventor scenegraph

Definition at line 362 of file SoPhysics.cpp.

References angVelocity, AUTO_UPDATE_COLLISION_SHAPE, drawCollisionShape, FieldChangedCB(), fieldUpdateSensor, fieldUpdateTrigger, forceField, forcePos, inertia, jointList, linVelocity, mass, measureContactForces, scale, torqueField, UpdateDependentObjectsCB(), and updateDependentObjectsSensor.

SoPhysics::~SoPhysics (  )  [virtual]

The virtual standard destructor of SoPhysics. It destroys all sensors and sets them to NULL.

Definition at line 424 of file SoPhysics.cpp.

References body.


Member Function Documentation

SoBaseKit * SoPhysics::copy ( SbBool  copyConnections  )  const [virtual]

The overwritten copy() method

Parameters:
copyConnections copy connections if true

Reimplemented in SoPhysicsTriMesh.

Definition at line 441 of file SoPhysics.cpp.

References body, CoinRefTransform, geom, isInitialised, myWorld, and transform.

Referenced by SoPhysicsTriMesh::copy().

void SoPhysics::createOdeBody ( SoCallbackAction *  action  ) 

Creates an SoPhysics object. This method creates a SoPhysics body using the current soWorldId. Additional the parameters of the object fields and the geom given by collisionShape are set. The method initialises the mass, velocities.

Parameters:
action UNUSED

Definition at line 584 of file SoPhysics.cpp.

References angVelocity, body, CoinRefTransform, geom, SoCollisionShape::getCOG(), SoCollisionShape::getGeom(), getInitialMass(), init_angVelocity, init_linVelocity, isInitialised, linVelocity, myWorld, SoCollisionShape::setVisualisationStatus(), transform, and updateOdeBodyParameters().

Referenced by InitialiseOdeBodiesCB().

void SoPhysics::FieldChangedCB ( void *  data,
SoSensor *   
) [static, private]

This method is called when a field connected to SoPhysics::fieldUpdateTrigger is updated. It updates the ODE parameters mass, linear velocity and angular velocity accordingly. Also the visibility of the collisionShape is toggled depending on the value of SoPhysics::drawCollisionShape.

Parameters:
data object of supertype SoPhysics* to operate on

Definition at line 469 of file SoPhysics.cpp.

References angVelocity, body, drawCollisionShape, isInitialised, linVelocity, mass, setLinearVel(), and SoCollisionShape::setVisualisationStatus().

Referenced by setUpConnections(), and SoPhysics().

dBodyID SoPhysics::getBody (  ) 

Returns:
bodyID: the dBodyID structure of the physics body in the ODE engine.

Definition at line 747 of file SoPhysics.cpp.

References body.

Referenced by SoJoint::InitOdeJointsCB(), ListBodyContacts::vExecute(), ListBody2BodyForces::vExecute(), and ListBody2BodyContacts::vExecute().

SoSFVec3f SoPhysics::getCurrentForce (  ) 

This method returns the current force vector of the object.

Returns:
forceXYZ: the current force vector the physics body.

Definition at line 757 of file SoPhysics.cpp.

References body.

Referenced by GetBodyForce::vExecute().

SoSFVec3f SoPhysics::getCurrentLinearVel (  ) 

Returns:
velocityXYZ: the current linear velocity vector of the physics body.

Definition at line 782 of file SoPhysics.cpp.

References body.

SoSFVec3f SoPhysics::getCurrentPosition (  ) 

Returns:
positionXYZ: the current position vector of the physics bodies' center of mass in world coordinates.
Warning:
The function returns the position of the bodies' COG. With trimeshes this could give an unexpected result, as the COG becomes calculated during trimesh initialisation and may be not known in advance.

Definition at line 799 of file SoPhysics.cpp.

References body.

Referenced by GetBodyPosition::vExecute().

SoSFVec3f SoPhysics::getCurrentTorque (  ) 

Returns:
torqueXYZ: current torque vector of the physics body.

Definition at line 769 of file SoPhysics.cpp.

References body.

Referenced by GetBodyTorque::vExecute().

dMass SoPhysics::getInitialMass (  )  [protected, virtual]

The method returns the mass of the object.

Returns:
mass: the mass of the object

Reimplemented in SoPhysicsBox, SoPhysicsCapsule, SoPhysicsCylinder, SoPhysicsSphere, SoPhysicsTorus, and SoPhysicsTriMesh.

Definition at line 544 of file SoPhysics.cpp.

References inertia, and mass.

Referenced by createOdeBody().

SbMatrix SoPhysics::getMatrixTransform (  ) 

Returns:
transform: current transformation matrix of the physics body.

Definition at line 813 of file SoPhysics.cpp.

References body.

Referenced by updateOIPosition(), and GetBodyRotation::vExecute().

SbMatrix SoPhysics::getOIMatrixTransform (  ) 

Returns:
transform: current transformation matrix of the visualisation shape.

Definition at line 828 of file SoPhysics.cpp.

References transform.

dWorldID SoPhysics::getWorld (  ) 

Returns:
worldID: the ID of the ODE world which is currently set on the physics body.

Definition at line 570 of file SoPhysics.cpp.

References myWorld.

Referenced by SoJoint::InitOdeJointsCB().

void SoPhysics::initClass (  )  [static]

Initialises the class and it's type id variables.

Reimplemented in SoPhysicsBox, SoPhysicsCapsule, SoPhysicsCylinder, SoPhysicsSphere, SoPhysicsTorus, and SoPhysicsTriMesh.

Definition at line 350 of file SoPhysics.cpp.

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

Inits the bodies. This method traverses the Inventor tree and creates the respective ODEBody for each SoPhysics node. Additionally it calls SoPhysics::setUpConnections() on the instance which can not be done in the constructor since the method SoPhysics::setUpConnections() is virtual and can not be called safely inside the constructor.

Parameters:
userdata pointer to an SoWorldPhysics object
action UNUSED
node node with supertype SoPhysics

Definition at line 936 of file SoPhysics.cpp.

References createOdeBody(), SoWorldPhysics::ownworld, setUpConnections(), and setWorld().

Referenced by SoWorldPhysics::initialiseWorld().

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

Reset SoPhysics objects. This method traverses the Inventor tree and calls for each SoPhysics node the resetupdateODE().

Parameters:
userdata UNUSED
action UNUSED
node node with supertype SoPhysics

Definition at line 974 of file SoPhysics.cpp.

References resetOdeBody().

Referenced by SoWorldPhysics::resetWorld().

void SoPhysics::resetOdeBody ( SoCallbackAction *  action  ) 

This method resets the ODE body transform and velocity vector to the initial values and updates the open inventor model by calling SoPhysics::updateOIPosition().

Parameters:
action UNUSED

Definition at line 682 of file SoPhysics.cpp.

References angVelocity, init_angVelocity, init_linVelocity, isInitialised, linVelocity, and updateOdeBodyParameters().

Referenced by ResetOdeBodiesCB().

void SoPhysics::setCollisionShapeVisibility ( SbBool  visible  ) 

Toggle the visibility of the collision shape.

Parameters:
visible turn visibility on if true, turn it off otherwise.

Definition at line 903 of file SoPhysics.cpp.

References drawCollisionShape.

Referenced by SetDrawShape::vExecute().

void SoPhysics::setForce ( const SbVec3f &  force  ) 

Sets a force on the given physics body.

Parameters:
force specifies the forces in X, Y and Z direction in world coords.

Definition at line 838 of file SoPhysics.cpp.

References body.

Referenced by SetBodyForce::vExecute().

void SoPhysics::setForceAtPosition ( const SbVec3f &  force,
const SbVec3f &  position 
)

Sets a force force on the given physics body at position position.

Parameters:
force specifies the forces in X, Y and Z direction in world coords.
position specifies the position in X, Y and Z value in world coords..

Definition at line 849 of file SoPhysics.cpp.

References body.

Referenced by updateOdeBody().

void SoPhysics::setLinearVel ( const SbVec3f &  vel  ) 

Sets a linear velocity on the given physics body.

Parameters:
vel specifies the velocities in X, Y and Z direction.

Definition at line 884 of file SoPhysics.cpp.

References body.

Referenced by FieldChangedCB(), updateOdeBodyParameters(), and SetBodyVelocity::vExecute().

void SoPhysics::setRelForce ( const SbVec3f &  relForce  ) 

Sets a relative force on the given physics body.

Parameters:
relForce specifies the forces in X, Y and Z direction in the bodies frame of reference..

Definition at line 874 of file SoPhysics.cpp.

References body.

Referenced by SetBodyRelForce::vExecute().

void SoPhysics::setRelForceAtPosition ( const SbVec3f &  force,
const SbVec3f &  position 
)

Sets a force force on the given physics body at position position.

Parameters:
force specifies the forces in X, Y and Z direction in the bodies frame of reference.
position specifies the position in X, Y and Z value in the bodies frame of reference..

Definition at line 862 of file SoPhysics.cpp.

References body.

void SoPhysics::setTorque ( const SbVec3f &  torque  ) 

Sets a torque on the given physics body.

Parameters:
torque specifies the torques in X, Y and Z direction.

Definition at line 893 of file SoPhysics.cpp.

References body.

Referenced by updateOdeBody().

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

This method attaches the SoPhysics::fieldUpdateTrigger to SoPhysics::fieldUpdateSensor and SoPhysics::updateDependentObjectsTrigger to SoPhysics::updateDependentObjectsSensor. Before the triggers are attached the methods SoPhysics::FieldChangedCB and SoPhysics::UpdateDependentObjectsCB are called.

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 509 of file SoPhysics.cpp.

References FieldChangedCB(), fieldUpdateSensor, fieldUpdateTrigger, UpdateDependentObjectsCB(), updateDependentObjectsSensor, and updateDependentObjectsTrigger.

Referenced by InitialiseOdeBodiesCB().

void SoPhysics::setWorld ( dWorldID  w  ) 

Sets the worldID of the world to which the physics body should belong to.

Parameters:
w the ID of the ODE world to use.

Definition at line 561 of file SoPhysics.cpp.

References myWorld.

Referenced by InitialiseOdeBodiesCB().

SoPhysics::SO_KIT_CATALOG_ENTRY_HEADER ( visualisationShape   )  [private]

SoPhysics::SO_KIT_CATALOG_ENTRY_HEADER ( ODETransform   )  [private]

SoPhysics::SO_KIT_CATALOG_ENTRY_HEADER ( collisionShape   )  [private]

SoPhysics::SO_KIT_CATALOG_ENTRY_HEADER ( reset   )  [private]

SoPhysics::SO_KIT_CATALOG_ENTRY_HEADER ( separator   )  [private]

SoPhysics::SO_KIT_HEADER ( SoPhysics   )  [private]

SoPhysics::updateDependentObjects (  )  [inline, protected, virtual]

This method must be overridden by any subclass of SoPhysics if the collision shape and the visualisation of the object should be change if a monitored property changes.

Reimplemented in SoPhysicsBox, SoPhysicsCapsule, SoPhysicsCylinder, and SoPhysicsSphere.

Definition at line 114 of file SoPhysics.h.

Referenced by UpdateDependentObjectsCB().

void SoPhysics::UpdateDependentObjectsCB ( void *  data,
SoSensor *  sensor 
) [static, private]

This method calls the updateDependentObjects() method on the passed in data object if any of the fields connected to SoPhysics::updateDependentObjectsTrigger change their value.

Parameters:
data void pointer to an SoPhysics object on which updateDependentObjects is called
sensor UNUSED

Definition at line 916 of file SoPhysics.cpp.

References updateDependentObjects().

Referenced by setUpConnections(), and SoPhysics().

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

Updates the SoPhysics objects. This method traverses the Inventor tree and calls for each SoPhysics node the updateOdeBody().

Parameters:
userdata UNUSED
action UNUSED
node node with supertype SoPhysics

Definition at line 957 of file SoPhysics.cpp.

References updateOdeBody().

Referenced by SoWorldPhysics::StepOde().

void SoPhysics::updateOdeBody ( SoCallbackAction *  action  ) 

This method applies forces and torques to the physics object and sets a new position for the open inventor model by calling SoPhysics::updateOIPosition().

Parameters:
action UNUSED

Definition at line 654 of file SoPhysics.cpp.

References forceField, forcePos, isInitialised, setForceAtPosition(), setTorque(), torqueField, and updateOIPosition().

Referenced by UpdateOdeBodiesCB().

void SoPhysics::updateOdeBodyParameters ( const SbMatrix &  actionModelMatrix  )  [private]

This method sets the SoPhysics::scale, ODE body position, rotation, linear and angular velocity.

Definition at line 698 of file SoPhysics.cpp.

References SoCollisionShape::alignment, body, SoCollisionShape::CENTERED, SoCollisionShape::getCOG(), init_angVelocity, init_linVelocity, scale, setLinearVel(), SoCollisionShape::STANDARD, and updateOIPosition().

Referenced by createOdeBody(), and resetOdeBody().

void SoPhysics::updateOIPosition (  )  [protected, virtual]

This function sets the open inventor position. It may be overridden for derived classed.

Reimplemented in SoPhysicsTriMesh.

Definition at line 633 of file SoPhysics.cpp.

References CoinRefTransform, getMatrixTransform(), and transform.

Referenced by updateOdeBody(), and updateOdeBodyParameters().


Member Data Documentation

The angular velocity of the physics object (default = {0.0f, 0.0f, 0.0f}).

Definition at line 99 of file SoPhysics.h.

Referenced by createOdeBody(), FieldChangedCB(), resetOdeBody(), and SoPhysics().

The contents of this field determines if the properties of the collision shape object get automatically updated to match those of the parent physics object.

The default value of this field is TRUE.

An example is provided in the file /iv/test_AUTO_UPDATE_COLLISION_SHAPE.iv

Definition at line 96 of file SoPhysics.h.

Referenced by SoPhysics(), SoPhysicsSphere::updateDependentObjects(), SoPhysicsCylinder::updateDependentObjects(), and SoPhysicsBox::updateDependentObjects().

SoPhysics::body [protected]

The is variable describes the reference transformation between the actual center of gravity and the visualisation of the SoPhysics object.

Definition at line 117 of file SoPhysics.h.

Referenced by copy(), createOdeBody(), SoPhysicsCylinder::SoPhysicsCylinder(), and updateOIPosition().

CollisionShape is drawn if true and hidden if false (default = FALSE).

Definition at line 108 of file SoPhysics.h.

Referenced by FieldChangedCB(), setCollisionShapeVisibility(), and SoPhysics().

This sensor monitors the SoPhysics::fieldUpdateTrigger member and calls SoPhysics::FieldChangedCB() if it changes.

Definition at line 126 of file SoPhysics.h.

Referenced by setUpConnections(), and SoPhysics().

This field is monitored by SoPhysics::fieldUpdateSensor. If a new field should trigger an update of the ODE internal values connect it with the command

 fieldUpdateTrigger.appendConnection(&newFieldName);
in the constructor.

Definition at line 125 of file SoPhysics.h.

Referenced by setUpConnections(), and SoPhysics().

A list of the forces acting on the physics object (default = {0.0f, 0.0f, 0.0f}).

Definition at line 102 of file SoPhysics.h.

Referenced by SoPhysics(), and updateOdeBody().

A list with the points which the force is applied to (default = {0.0f, 0.0f, 0.0f}).

Definition at line 103 of file SoPhysics.h.

Referenced by SoPhysics(), and updateOdeBody().

SoPhysics::geom [protected]

Stores the ODE internal ID of the collision shape object (default = NULL)
. This value is fetched from the collision shape stored in SoPhysics::collisionShape.

Definition at line 123 of file SoPhysics.h.

Referenced by copy(), createOdeBody(), SoPhysicsTriMesh::getInitialMass(), SoPhysicsTriMesh::updateOIPosition(), ListBodyContacts::vExecute(), and ListBody2BodyContacts::vExecute().

This is a 3x3 matrix that describes how the body's mass is distributed around the center of mass (default (sphere with mass=1.0 and radius=1.0) = { {0.4f, 0.0f, 0.0f}, {0.0f, 0.4f, 0.0f}, {0.0f, 0.0f, 0.4f} }).

Definition at line 104 of file SoPhysics.h.

Referenced by SoPhysicsTorus::getInitialMass(), SoPhysicsSphere::getInitialMass(), SoPhysicsCylinder::getInitialMass(), SoPhysicsCapsule::getInitialMass(), SoPhysicsBox::getInitialMass(), getInitialMass(), and SoPhysics().

SbVec3f SoPhysics::init_angVelocity [protected]

Definition at line 132 of file SoPhysics.h.

Referenced by createOdeBody(), resetOdeBody(), and updateOdeBodyParameters().

SbVec3f SoPhysics::init_linVelocity [protected]

Definition at line 131 of file SoPhysics.h.

Referenced by createOdeBody(), resetOdeBody(), and updateOdeBodyParameters().

Prevents executing methods on an unitialised object (default = FALSE).
This is set to TRUE once SoPhysics::createOdeBody() was executed successfully.

Definition at line 119 of file SoPhysics.h.

Referenced by copy(), createOdeBody(), FieldChangedCB(), resetOdeBody(), and updateOdeBody().

The jointList of the physics object (default = NULL).

Definition at line 100 of file SoPhysics.h.

Referenced by SoPhysics().

The lineare velocity of the physics object (default = {0.0f, 0.0f, 0.0f}).

Definition at line 98 of file SoPhysics.h.

Referenced by createOdeBody(), FieldChangedCB(), resetOdeBody(), and SoPhysics().

SoFrictionCone objects are drawn if set to TRUE (default = FALSE).

Definition at line 109 of file SoPhysics.h.

Referenced by SoWorldPhysics::NearCallback(), and SoPhysics().

SoPhysics::myWorld [protected]

Stores the worldID in which the physics object is localized (default = NULL).
This should be set by an instance of SoWorldPhysics by executing SoWorldPhysics::initialiseWorld().

Definition at line 121 of file SoPhysics.h.

Referenced by copy(), createOdeBody(), getWorld(), and setWorld().

A list of the torques acting on the physics object (default = {0.0f, 0.0f, 0.0f}).

Definition at line 101 of file SoPhysics.h.

Referenced by SoPhysics(), and updateOdeBody().

SoPhysics::transform [protected]

The transformation of the Inventor model from the origin according to ODE (default = NULL).
This is calculated in SoPhysics::updateOIPosition().

Definition at line 116 of file SoPhysics.h.

Referenced by copy(), createOdeBody(), getOIMatrixTransform(), and updateOIPosition().

This sensor monitors the SoPhysics::updateDependentObjectsTrigger member and calls SoPhysics::UpdateDependentObjectsCB() if it changes.

Definition at line 128 of file SoPhysics.h.

Referenced by setUpConnections(), and SoPhysics().

This field is monitored by SoPhysics::updateDependentObjectsSensor. If a new field in the base class or derived classes should trigger an update of the dependent objects (visualisation/collision shape) connect it with the command

 updateDependentObjectsTrigger.appendConnection(&newFieldName);
in the constructor of the appropriate class.

Definition at line 127 of file SoPhysics.h.

Referenced by setUpConnections(), SoPhysicsBox::SoPhysicsBox(), SoPhysicsCylinder::SoPhysicsCylinder(), SoPhysicsSphere::SoPhysicsSphere(), and SoPhysicsTorus::SoPhysicsTorus().


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