00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00046 #include "../include/IPSA/SoJointBall.h"
00047 #include "../include/IPSA/SoPhysics.h"
00048
00049 #include <Inventor/nodes/SoSphere.h>
00050 #include <Inventor/nodes/SoTranslation.h>
00051 #include <Inventor/nodekits/SoShapeKit.h>
00052 #include <Inventor/actions/SoCallbackAction.h>
00053
00054 #include <cassert>
00055
00056 SO_KIT_SOURCE(SoJointBall);
00057
00060 void SoJointBall::initClass()
00061 {
00062 SO_KIT_INIT_CLASS(SoJointBall, SoJoint, "Joint");
00063 }
00064
00065
00072 SoJointBall::SoJointBall(const SbString& BodyOne, const SbString& BodyTwo, const SbString& nodeName)
00073 : SoJoint(BodyOne,BodyTwo,nodeName)
00074 {
00075 SO_KIT_CONSTRUCTOR(SoJointBall);
00076 isBuiltIn = TRUE;
00077
00078 SO_KIT_ADD_FIELD(soAnchor,(0.0,0.0,0.0));
00079 SO_KIT_ADD_FIELD(CFM,(INIT_CFM));
00080 SO_KIT_ADD_FIELD(ERP,(INIT_ERP));
00081
00082 SO_KIT_INIT_INSTANCE();
00083
00084 updateOdeParametersTrigger.appendConnection(&CFM);
00085 updateOdeParametersTrigger.appendConnection(&ERP);
00086 }
00087
00088
00089 void SoJointBall::setParams()
00090 {
00091
00092 dJointSetBallParam(soJointId,dParamCFM,CFM.getValue());
00093 dJointSetBallParam(soJointId,dParamERP,ERP.getValue());
00094 }
00095
00096
00102 void SoJointBall::createOdeJoint(const dWorldID soWorldId)
00103 {
00104 soJointId = dJointCreateBall(soWorldId, soJointGroupId);
00105 }
00106
00107
00114 void SoJointBall::updateOdeJointProperties(const SbMatrix& modelMatrix)
00115 {
00116
00117
00118 SbVec3f anchorbase = soAnchor.getValue();
00119 SbVec3f ranchorbase;
00120
00121 SbMatrix mm = modelMatrix;
00122 mm.multVecMatrix(anchorbase, ranchorbase);
00123
00124 dJointSetBallAnchor(soJointId, ranchorbase[0], ranchorbase[1], ranchorbase[2]);
00125 }
00126
00127
00128 SoNode* SoJointBall::createVisualisation()
00129 {
00130 SoShapeKit* result = new SoShapeKit;
00131
00132 SoSphere* sphere = new SoSphere;
00133 sphere->radius.setValue(30 * VisualisationScale.getValue());
00134 result->setPart("shape", sphere);
00135
00136 SoTranslation* translation = new SoTranslation;
00137 translation->translation.setValue(this->soAnchor.getValue());
00138 result->setPart("transform", translation);
00139
00140 return result;
00141 }