00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00029 #ifndef _DYNJOINT_H_
00030
00031 #include <vector>
00032 #include <map>
00033 #include "matvec3D.h"
00034
00035 class Joint;
00036 class DynamicBody;
00037 class Body;
00038 class Matrix;
00039
00041
00069 class DynJoint {
00070 public:
00071 enum DynamicJointT{FIXED, REVOLUTE, UNIVERSAL, BALL, PRISMATIC};
00072 protected:
00073
00075 DynamicBody *prevLink;
00076
00078 DynamicBody *nextLink;
00079
00081 transf prevFrame;
00082
00084 transf nextFrame;
00085
00086 public:
00087
00092 DynJoint(DynamicBody *pLink,DynamicBody *nLink,const transf &pFrame,
00093 const transf &nFrame):
00094 prevLink(pLink),nextLink(nLink),prevFrame(pFrame),nextFrame(nFrame) {}
00095
00099 virtual void buildConstraints(double *Nu,double *eps,int numBodies,
00100 std::map<Body*,int> &islandIndices,int &ncn);
00101
00103 virtual void getConstraints(char *c) = 0;
00104
00106 virtual void updateValues() = 0;
00107
00109 virtual transf getNextTrans() = 0;
00110
00112 virtual transf getPrevTrans() = 0;
00113
00115 virtual int getNumConstraints()=0;
00116
00118 DynamicBody *getPrevLink() const {return prevLink;}
00119
00121 DynamicBody *getNextLink() const {return nextLink;}
00122
00124 virtual DynamicJointT getType() = 0;
00125
00127 void jacobian(transf toTarget, Matrix *J, bool worldCoords);
00128 };
00129
00131
00136 class FixedDynJoint : public DynJoint {
00137 public:
00142 FixedDynJoint(DynamicBody *pLink,DynamicBody *nLink,
00143 const transf &pFrame=transf::IDENTITY,
00144 const transf &nFrame=transf::IDENTITY) :
00145 DynJoint(pLink,nLink,pFrame,nFrame) {}
00146
00147 virtual int getNumConstraints() {return 6;}
00148
00150 virtual void getConstraints(char *c) {
00151 c[0] = c[1] = c[2] = c[3] = c[4] = c[5] = 1;
00152 }
00153
00154 virtual void buildConstraints(double *Nu,double *eps,int numBodies,
00155 std::map<Body*,int> &islandIndices,int &ncn);
00156
00157 virtual void updateValues();
00158
00159 virtual transf getNextTrans(){return transf::IDENTITY;}
00160
00161 virtual transf getPrevTrans(){return prevFrame;}
00162
00163 virtual DynamicJointT getType(){return FIXED;}
00164 };
00165
00167
00170 class RevoluteDynJoint : public DynJoint {
00171 protected:
00173 Joint *joint;
00174
00175 public:
00176
00182 RevoluteDynJoint(Joint *j,DynamicBody *pLink,DynamicBody *nLink,
00183 const transf &pFrame=transf::IDENTITY,
00184 const transf &nFrame=transf::IDENTITY) :
00185 DynJoint(pLink,nLink,pFrame,nFrame),joint(j) {}
00186
00187 virtual int getNumConstraints() {return 5;}
00188
00190 virtual void getConstraints(char *c) {
00191 c[0] = c[1] = c[2] = c[3] = c[4] = 1;
00192 c[5] = 0;
00193 }
00194 virtual transf getNextTrans();
00195
00196 virtual transf getPrevTrans();
00197
00198 virtual void updateValues();
00199
00200 virtual DynamicJointT getType(){return REVOLUTE;}
00201 };
00202
00203
00205
00211 class UniversalDynJoint : public DynJoint {
00212
00214 Joint *joint1;
00215
00217 Joint *joint2;
00218
00219 public:
00220
00226 UniversalDynJoint(Joint *j1,Joint *j2,DynamicBody *pLink,DynamicBody *nLink,
00227 const transf &pFrame=transf::IDENTITY,
00228 const transf &nFrame=transf::IDENTITY) :
00229 DynJoint(pLink,nLink,pFrame,nFrame),joint1(j1),joint2(j2) {}
00230
00231 virtual int getNumConstraints() {return 4;}
00232
00234 virtual void getConstraints(char *c) {
00235 c[0] = c[1] = c[2] = c[3] = 1;
00236 c[4] = c[5] = 0;
00237 }
00238
00239 virtual void updateValues();
00240
00241 virtual transf getNextTrans();
00242
00243 virtual transf getPrevTrans();
00244
00245 virtual DynamicJointT getType(){return UNIVERSAL;}
00246 };
00247
00249
00254 class BallDynJoint : public DynJoint {
00256 Joint *joint1;
00257
00259 Joint *joint2;
00260
00262 Joint *joint3;
00263
00264 public:
00270 BallDynJoint(Joint *j1,Joint *j2,Joint *j3,DynamicBody *pLink,DynamicBody *nLink,
00271 const transf &pFrame=transf::IDENTITY,
00272 const transf &nFrame=transf::IDENTITY) :
00273 DynJoint(pLink,nLink,pFrame,nFrame),joint1(j1),joint2(j2),joint3(j3) {}
00274
00275 virtual int getNumConstraints() {return 3;}
00276
00278 virtual void getConstraints(char *c) {
00279 c[0] = c[1] = c[2] = 1;
00280 c[3] = c[4] = c[5] = 0;
00281 }
00282
00283 virtual void updateValues();
00284
00285 virtual transf getNextTrans();
00286
00287 virtual transf getPrevTrans();
00288
00289 virtual DynamicJointT getType(){return BALL;}
00290 };
00291
00292 #define _DYNJOINT_H_
00293 #endif