00001 #ifndef IPSA_SOPHYSICS_H
00002 #define IPSA_SOPHYSICS_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00027 #include "IPSA.h"
00028
00029 #include <Inventor/actions/SoCallbackAction.h>
00030 #include <Inventor/nodekits/SoBaseKit.h>
00031 #include <Inventor/SbLinear.h>
00032 #include <Inventor/fields/SoSFFloat.h>
00033 #include <Inventor/fields/SoSFVec3f.h>
00034 #include <Inventor/fields/SoMFVec3f.h>
00035 #include <Inventor/fields/SoMFNode.h>
00036 #include <Inventor/fields/SoSFBool.h>
00037 #include <Inventor/fields/SoSFEnum.h>
00038 #include <Inventor/fields/SoSFTrigger.h>
00039 #include <Inventor/sensors/SoFieldSensor.h>
00040
00041 #include <ode/ode.h>
00042
00043 class SoSensor;
00044 class SoMatrixTransform;
00045
00046 class IPSA_IMPORT_EXPORT SoPhysics : public SoBaseKit
00047 {
00048
00049 SO_KIT_HEADER(SoPhysics);
00050
00051
00052 SO_KIT_CATALOG_ENTRY_HEADER(separator);
00053 SO_KIT_CATALOG_ENTRY_HEADER(reset);
00054 SO_KIT_CATALOG_ENTRY_HEADER(collisionShape);
00055 SO_KIT_CATALOG_ENTRY_HEADER(ODETransform);
00056 SO_KIT_CATALOG_ENTRY_HEADER(visualisationShape);
00057
00058 public:
00059
00060 SoPhysics(const SbString& nodeName = "");
00061
00062
00063 virtual ~SoPhysics();
00064
00065 virtual SoBaseKit* copy(SbBool copyConnections) const;
00066 virtual SbBool setUpConnections(SbBool onOff, SbBool doItAlways = FALSE);
00067 static void initClass();
00068 static SoCallbackAction::Response InitialiseOdeBodiesCB(void* userdata, SoCallbackAction*, const SoNode* node);
00069 static SoCallbackAction::Response UpdateOdeBodiesCB(void*, SoCallbackAction* action, const SoNode* node);
00070 static SoCallbackAction::Response ResetOdeBodiesCB(void* userdata, SoCallbackAction* action, const SoNode* node);
00071
00072 void setCollisionShapeVisibility(SbBool visible);
00073
00074 void setForce(const SbVec3f& force);
00075 void setRelForce(const SbVec3f& force);
00076 void setForceAtPosition(const SbVec3f& force, const SbVec3f& position);
00077 void setRelForceAtPosition(const SbVec3f& force, const SbVec3f& position);
00078
00079 void setLinearVel(const SbVec3f& vel);
00080 void setTorque(const SbVec3f& torque);
00081
00082 void createOdeBody(SoCallbackAction* action);
00083 void updateOdeBody(SoCallbackAction* action);
00084 void resetOdeBody(SoCallbackAction* action);
00085 void setWorld(dWorldID w);
00086 dWorldID getWorld();
00087
00088 SoSFVec3f getCurrentForce();
00089 SoSFVec3f getCurrentTorque();
00090 SoSFVec3f getCurrentLinearVel();
00091 SoSFVec3f getCurrentPosition();
00092 SbMatrix getMatrixTransform();
00093 SbMatrix getOIMatrixTransform();
00094 dBodyID getBody();
00095
00096 SoSFBool AUTO_UPDATE_COLLISION_SHAPE;
00097 SoSFFloat mass;
00098 SoSFVec3f linVelocity;
00099 SoSFVec3f angVelocity;
00100 SoMFNode jointList;
00101 SoMFVec3f torqueField;
00102 SoMFVec3f forceField;
00103 SoMFVec3f forcePos;
00104 SoMFVec3f inertia;
00105
00106 SoSFVec3f scale;
00107
00108 SoSFBool drawCollisionShape;
00109 SoSFBool measureContactForces;
00110
00111 protected:
00112 virtual dMass getInitialMass();
00113 virtual void updateOIPosition();
00114 virtual void updateDependentObjects() {;}
00115
00116 SoMatrixTransform* transform;
00117 SbMatrix CoinRefTransform;
00118
00119 bool isInitialised;
00120
00121 dWorldID myWorld;
00122 dBodyID body;
00123 dGeomID geom;
00124
00125 SoSFTrigger fieldUpdateTrigger;
00126 SoFieldSensor fieldUpdateSensor;
00127 SoSFTrigger updateDependentObjectsTrigger;
00128 SoFieldSensor updateDependentObjectsSensor;
00129
00130
00131 SbVec3f init_linVelocity;
00132 SbVec3f init_angVelocity;
00133
00134 private:
00135 static void UpdateDependentObjectsCB(void* data, SoSensor* sensor);
00136 static void FieldChangedCB(void* data, SoSensor*);
00137 void updateOdeBodyParameters(const SbMatrix& actionModelMatrix);
00138 };
00139
00140 #endif