00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00101 #include "../include/IPSA/SoJointSlider.h"
00102 #include "../include/IPSA/SoPhysics.h"
00103
00104 #include <Inventor/nodes/SoCylinder.h>
00105 #include <Inventor/nodes/SoTransform.h>
00106 #include <Inventor/nodekits/SoShapeKit.h>
00107 #include <Inventor/actions/SoCallbackAction.h>
00108
00109 SO_KIT_SOURCE(SoJointSlider);
00110
00113 void
00114 SoJointSlider::initClass()
00115 {
00116 SO_KIT_INIT_CLASS(SoJointSlider, SoJoint, "Joint");
00117 }
00118
00119
00126 SoJointSlider::SoJointSlider(const SbString& BodyOne, const SbString& BodyTwo, const SbString& nodeName)
00127 : SoJoint(BodyOne,BodyTwo,nodeName)
00128 {
00129 SO_KIT_CONSTRUCTOR(SoJointSlider);
00130 isBuiltIn = TRUE;
00131
00132 SO_KIT_ADD_FIELD(soAxis,(0.0f,0.0f,0.0f));
00133 SO_KIT_ADD_FIELD(soForce, (0.0f));
00134
00135 SO_KIT_ADD_FIELD(LoStop,(-dInfinity));
00136 SO_KIT_ADD_FIELD(HiStop,(dInfinity));
00137 SO_KIT_ADD_FIELD(Velocity,(0.0));
00138 SO_KIT_ADD_FIELD(MaxForce,(0.0));
00139 SO_KIT_ADD_FIELD(FudgeFactor,(1.0));
00140 SO_KIT_ADD_FIELD(Bounce,(0.0));
00141 SO_KIT_ADD_FIELD(CFM,(INIT_CFM));
00142 SO_KIT_ADD_FIELD(StopERP,(INIT_ERP));
00143 SO_KIT_ADD_FIELD(StopCFM,(INIT_CFM));
00144
00145 SO_KIT_INIT_INSTANCE();
00146
00147 updateOdeParametersTrigger.appendConnection(&LoStop);
00148 updateOdeParametersTrigger.appendConnection(&HiStop);
00149 updateOdeParametersTrigger.appendConnection(&Velocity);
00150 updateOdeParametersTrigger.appendConnection(&MaxForce);
00151 updateOdeParametersTrigger.appendConnection(&FudgeFactor);
00152 updateOdeParametersTrigger.appendConnection(&Bounce);
00153 updateOdeParametersTrigger.appendConnection(&CFM);
00154 updateOdeParametersTrigger.appendConnection(&StopERP);
00155 updateOdeParametersTrigger.appendConnection(&StopCFM);
00156 }
00157
00158
00163 void SoJointSlider::setForce(dReal force1 )
00164 {
00165 dJointAddSliderForce(this->soJointId, force1);
00166 }
00167
00168
00174 void SoJointSlider::createOdeJoint(const dWorldID soWorldId)
00175 {
00176
00177 initVelocity = Velocity.getValue();
00178 initMaxForce = MaxForce.getValue();
00179 initForce = soForce.getValue();
00180
00181 soJointId = dJointCreateSlider(soWorldId, soJointGroupId);
00182 }
00183
00184
00191 void SoJointSlider::updateOdeJointProperties(const SbMatrix& modelMatrix)
00192 {
00193 Velocity.setValue(initVelocity);
00194 MaxForce.setValue(initMaxForce);
00195 soForce.setValue(initForce);
00196
00197
00198
00199 SbVec3f axisbase = soAxis.getValue();
00200 SbVec3f raxbase;
00201
00202 SbMatrix mm = modelMatrix;
00203 mm.multDirMatrix(axisbase,raxbase);
00204
00205 dJointSetSliderAxis(this->soJointId, raxbase[0], raxbase[1], raxbase[2]);
00206
00207
00208 dJointAddSliderForce(this->soJointId, initForce);
00209 }
00210
00211
00212 SoNode* SoJointSlider::createVisualisation()
00213 {
00214 SoShapeKit* result = new SoShapeKit;
00215
00216 SoCylinder* axis = new SoCylinder;
00217 axis->radius.setValue(30 / 5.0f);
00218 axis->height.setValue(30 * 6.0f);
00219
00220 SoTransform* axisTransform = new SoTransform;
00221 SoJoint::GenerateCylinderAlignmentRotation(soAxis.getValue(), *axisTransform);
00222
00223 result->setPart("shape", axis);
00224 result->setPart("transform", axisTransform);
00225
00226 return result;
00227 }
00228
00229
00230 void SoJointSlider::setParams()
00231 {
00232 dJointSetSliderParam(soJointId,dParamLoStop,LoStop.getValue());
00233 dJointSetSliderParam(soJointId,dParamHiStop,HiStop.getValue());
00234 dJointSetSliderParam(soJointId,dParamVel,Velocity.getValue());
00235 dJointSetSliderParam(soJointId,dParamFMax,MaxForce.getValue());
00236 dJointSetSliderParam(soJointId,dParamFudgeFactor,FudgeFactor.getValue());
00237 dJointSetSliderParam(soJointId,dParamBounce,Bounce.getValue());
00238 dJointSetSliderParam(soJointId,dParamCFM,CFM.getValue());
00239 dJointSetSliderParam(soJointId,dParamStopERP,StopERP.getValue());
00240 dJointSetSliderParam(soJointId,dParamStopCFM,StopCFM.getValue());
00241 }
00242
00243
00244 SoSFFloat SoJointSlider::getPosition()
00245 {
00246 SoSFFloat ret;
00247 ret.setValue(dJointGetSliderPosition(this->soJointId));
00248 return ret;
00249 }
00250
00251
00252 SoSFFloat SoJointSlider::getPositionRate()
00253 {
00254 SoSFFloat ret;
00255 ret.setValue(dJointGetSliderPositionRate(this->soJointId));
00256 return ret;
00257 }