00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef __RBD_Object_H__
00023 #define __RBD_Object_H__
00024
00025 #include "RBD_API.h"
00026 #include <UT/UT_Vector3.h>
00027 #include <UT/UT_BoundingBox.h>
00028 #include <UT/UT_Quaternion.h>
00029 #include <UT/UT_PtrArray.h>
00030 #include <UT/UT_Vector3Array.h>
00031 #include <SIM/SIM_ObjectArray.h>
00032 #include <SIM/SIM_Solver.h>
00033 #include <SIM/SIM_Collider.h>
00034 #include <SIM/SIM_ObjectSolveInfo.h>
00035 #include "RBD_SharedAffectorList.h"
00036
00037 class UT_Vector3Array;
00038 class UT_HashTable;
00039 class SIM_Object;
00040 class SIM_Geometry;
00041 class SIM_Engine;
00042 class SIM_Time;
00043 class SIM_SDF;
00044 class SIM_Impacts;
00045 class SIM_ConAnchorSpatial;
00046 class RBD_Object;
00047 class RBD_Solver;
00048 class RBD_State;
00049 class RBD_SphereTree;
00050 class RBD_SpherePointTree;
00051 class RBD_SphereEdgeTree;
00052
00053 typedef UT_PtrArray<RBD_Object *> RBD_ObjectArray;
00054
00055 class RBD_API RBD_Object : public SIM_ObjectSolveInfo
00056 {
00057 public:
00058 RBD_Object(const SIM_Solver *solver, SIM_Object *obj);
00059 virtual ~RBD_Object();
00060
00061
00062
00063 SIM_Object *getObject() const { return myObject; }
00064 RBD_State *getState() const { return myState; }
00065 SIM_Impacts *getImpacts();
00066 const SIM_SDF *getSDF() const { return mySDF; }
00067 const SIM_Geometry *getGeometry() const { return myGeometry; }
00068
00069 const RBD_SphereTree*getSphereTree() const;
00070
00071
00072
00073 fpreal getRadius() const { return myRadius; }
00074
00075
00076
00077 bool isInfiniteExtent() const;
00078
00079
00080
00081
00082 void getBBox(UT_BoundingBox &bbox) const;
00083
00084
00085
00086 void accumulatePointVelocity(UT_Vector3Array &pos,
00087 UT_Vector3Array &vel) const;
00088
00089
00090 void stashState();
00091
00092
00093
00094 void reloadImpacts(
00095 SIM_Collider::SIM_ImpactApplyType impactaplytype);
00096
00097
00098
00099
00100 void preserveImpacts(SIM_Engine *engine);
00101
00102
00103 void restoreStatePos();
00104
00105 void restoreStateVel();
00106
00107 void restoreState();
00108
00109
00110 void getGlueSubObjects(RBD_ObjectArray &objlist) const;
00111
00112
00113
00114 int getNumGlueSubObjects() const;
00115 RBD_Object *getNthGlueSubObject(int i) const;
00116
00117
00118 RBD_Object *getGlueParent() const { return myGlueParent; }
00119
00120
00121 bool hasGlueSubObjects() const;
00122
00123
00124 void addGlueSubObject(RBD_Object *obj);
00125
00126
00127 void removeGlueSubObject(RBD_Object *obj);
00128
00129
00130 bool hasAsGlueChild(RBD_Object *obj);
00131
00132
00133 bool isGlued() const { return myIsGlued; }
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144 void buildImpulseModel(UT_DMatrix3 &k,
00145 const UT_Vector3 &f,
00146 const UT_Vector3 &p) const;
00147
00148
00149
00150
00151 void buildImpulseModelForA(UT_DMatrix3 &k,
00152 const UT_Vector3 &f,
00153 const UT_Vector3 &p,
00154 RBD_Object *A) const;
00155
00156
00157
00158
00159
00160 void buildConstraints(const RBD_Solver *solver,
00161 const SIM_Time &time,
00162 const SIM_Time &endtime);
00163
00164
00165
00166 void removeConstraints();
00167
00168
00169
00170
00171 void applyImpulse(const UT_Vector3 &pos,
00172 fpreal impulse,
00173 const UT_Vector3 &normal);
00174
00175 void applyImpacts(const SIM_Impacts *impacts,
00176 const SIM_Time &time,
00177 const SIM_Time ×tep);
00178
00179
00180 void integratePosition(const SIM_Time &time,
00181 const SIM_Time ×tep);
00182
00183
00184 void integrateVelocity(const SIM_Time &time,
00185 const SIM_Time ×tep);
00186
00187
00188
00189 void initSDF();
00190
00191
00192 void initFromGeometry();
00193
00194
00195 void initRadius();
00196
00197
00198 void initBBox(bool useSDF);
00199
00200
00201 void initForCollisions();
00202
00203
00204 fpreal getPropertyAtPosition(
00205 const SIM_Property &property,
00206 const UT_Vector3 &pos) const;
00207
00208
00209
00210 void rebuildAffectorList(const RBD_Solver *solver,
00211 SIM_Engine &engine,
00212 const SIM_Time &time,
00213 const SIM_Time ×tep,
00214 RBD_SharedAffectorListArray &affectorlists,
00215 UT_HashTable &affectorhash);
00216
00217
00218 void getStashedTransform(UT_DMatrix4 &xform) const;
00219
00220 void findOverlapIdx(const RBD_Solver *solver,
00221 UT_IntArray &overlap)
00222 { if( mySharedAffectorList )
00223 mySharedAffectorList->findOverlapIdx(solver,
00224 this,
00225 overlap);
00226 else
00227 overlap.entries(0); }
00228 void setAffectorTreeDirty()
00229 { if( mySharedAffectorList )
00230 mySharedAffectorList->setObjectTreeDirty(); }
00231
00232 int getNumAffectors() const
00233 { return mySharedAffectorList
00234 ? mySharedAffectorList->entries()
00235 : 0; }
00236 RBD_Object *getAffector(int j) const
00237 { return (*mySharedAffectorList)(j); }
00238 const SIM_Collider *getCollider(int j) const
00239 { return mySharedAffectorList->
00240 getCollider(j, myObject); }
00241 SIM_Collider::SIM_ImpactApplyType getImpactApplyType(int j) const
00242 { return mySharedAffectorList->getImpactApplyType(j); }
00243
00244
00245
00246
00247 int getArrayIndex() const
00248 { return myArrayIndex; }
00249 void setArrayIndex(int index)
00250 { myArrayIndex = index; }
00251
00252 bool hasNailConstraints() const
00253 { return myHasConstraints; }
00254
00255
00256 mutable bool myPinProcessFlag;
00257 RBD_ObjectArray myPinObjects;
00258
00259
00260
00261
00262 UT_Vector3Array myPinAnchorPos;
00263 UT_Vector3Array myPinAnchorGoalPos;
00264
00265 protected:
00266
00267
00268
00269
00270 void accumulateConstraints(const RBD_Solver *solver,
00271 RBD_Object *piece,
00272 UT_Vector3Array &hard_objpos,
00273 UT_Vector3Array &hard_goalpos,
00274 UT_Matrix3 &hard_spatialfilter,
00275 UT_Matrix3 &hard_rotationalfilter,
00276 const SIM_Time &time,
00277 const SIM_Time &endtime);
00278
00279 private:
00280
00281
00282
00283
00284
00285 void findClosestPropertyAtPosition(fpreal &newvalue,
00286 const SIM_Property &property,
00287 const UT_Vector3 &pos,
00288 bool &found, fpreal &closestdist) const;
00289
00290 SIM_Object *myObject;
00291 RBD_State *myState;
00292 SIM_Impacts *myImpacts;
00293 RBD_SharedAffectorList *mySharedAffectorList;
00294 int myArrayIndex;
00295
00296 const SIM_Geometry *myGeometry;
00297 const SIM_SDF *mySDF;
00298
00299
00300
00301 mutable int myPropertyOffset[SIM_PROPERTY_COUNT];
00302 mutable const RBD_SphereTree *mySphereTree;
00303
00304
00305 fpreal myRadius;
00306
00307
00308 bool myBBoxValid;
00309 UT_BoundingBox myBBox;
00310
00311
00312 UT_Vector3 myStashPos;
00313 UT_Quaternion myStashOrient;
00314 UT_Vector3 myStashVel;
00315 UT_Vector3 myStashAngVel;
00316
00317
00318 bool myIsGlued;
00319
00320 bool myHasConstraints;
00321
00322
00323 UT_Matrix3 myCacheTensor;
00324 UT_Vector3 myCachePivot;
00325 UT_Vector3 myMomentArm;
00326 UT_Matrix3 mySpatialFilter;
00327 UT_Matrix3 myRotationalFilter;
00328
00329
00330
00331 RBD_Object *myGlueParent;
00332 RBD_ObjectArray myGlueSubObjects;
00333
00334 bool myHasInitFromGeometry;
00335 };
00336
00337 #endif