00001 #ifndef IPSA_SOJOINT_H
00002 #define IPSA_SOJOINT_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 #include "SoPhysics.h"
00029
00030 #include <Inventor/actions/SoCallbackAction.h>
00031 #include <Inventor/fields/SoSFNode.h>
00032 #include <Inventor/fields/SoSFVec3f.h>
00033 #include <Inventor/fields/SoSFTrigger.h>
00034 #include <Inventor/nodekits/SoBaseKit.h>
00035 #include <Inventor/nodes/SoSeparator.h>
00036 #include <Inventor/SbString.h>
00037 #include <Inventor/sensors/SoFieldSensor.h>
00038
00039 #include <ode/ode.h>
00040
00041 class SoTransform;
00042 class SoFieldSensor;
00043
00044 class IPSA_IMPORT_EXPORT SoJoint : public SoBaseKit {
00045
00046 SO_KIT_HEADER(SoJoint);
00047
00048 SO_KIT_CATALOG_ENTRY_HEADER(visualisationShape);
00049
00050 public:
00051
00052 SoJoint(const SbString& BodyOne = "", const SbString& BodyTwo = "", const SbString& nodeName = "");
00053
00054 virtual ~SoJoint();
00055
00056 virtual SoBaseKit* copy(SbBool copyConnections) const;
00057 virtual SbBool setUpConnections(SbBool onOff,SbBool doItAlways = FALSE);
00058 static void initClass();
00059
00060 virtual void setParams() {;}
00061
00062 static SoCallbackAction::Response InitOdeJointsCB(void * userdata, SoCallbackAction* action, const SoNode* node);
00063 dJointID getJointID();
00064
00065 virtual void setTorque(dReal torque1 = 0.0f, dReal torque2 = 0.0f, dReal torque3 = 0.0f);
00066 virtual void setForce(dReal force1 = 0.0f);
00067 SoSFVec3f getTorque(int idx);
00068 SoSFVec3f getForce(int idx);
00069 void destroyJoint();
00070
00071 SoSFName Bodyname1;
00072 SoSFName Bodyname2;
00073 SoSFFloat VisualisationScale;
00074 SoSFBool drawVisualisationShape;
00075
00076 const float INIT_CFM;
00077 const float INIT_ERP;
00078
00079 dJointFeedback* soJointFeedback;
00080
00081 protected:
00082 SoPhysics* getPhysicsBody1();
00083 SoPhysics* getPhysicsBody2();
00084 SoPhysics* getPhysicsBody(const SbName& bodyname);
00085 virtual void createOdeJoint(const dWorldID soWorldId);
00086 virtual void updateOdeJointProperties(const SbMatrix& modelMatrix);
00087 virtual SoNode* createVisualisation() {return new SoSeparator;}
00088 static void GenerateCylinderAlignmentRotation(const SbVec3f& axis, SoTransform& transform);
00089
00090 SoSFTrigger updateOdeParametersTrigger;
00091 SoFieldSensor updateOdeParametersSensor;
00092 SoFieldSensor drawVisualisationShapeSensor;
00093 dJointGroupID soJointGroupId;
00094 dJointID soJointId;
00095 bool isInitialised;
00096 private:
00097 static void IPSAJointDrawVisualisationChangedCB(void* data, SoSensor*);
00098 static void IPSAUpdateOdeParametersCB(void* data, SoSensor*);
00099 };
00100
00101 #endif