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 <GU/GU_SDF.h>
00036 #include "RBD_SharedAffectorList.h"
00037
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 gatherBuilderRequests(UT_RefArray<GU_SDFDelayedBuilder> &buildrequests);
00202
00203
00204 void initForCollisions();
00205
00206
00207 fpreal getPropertyAtPosition(
00208 const SIM_Property &property,
00209 const UT_Vector3 &pos) const;
00210
00211
00212
00213 void rebuildAffectorList(const RBD_Solver *solver,
00214 SIM_Engine &engine,
00215 const SIM_Time &time,
00216 const SIM_Time ×tep,
00217 RBD_SharedAffectorListArray &affectorlists,
00218 UT_HashTable &affectorhash);
00219
00220
00221 void getStashedTransform(UT_DMatrix4 &xform) const;
00222
00223 void findOverlapIdx(const RBD_Solver *solver,
00224 UT_IntArray &overlap)
00225 { if( mySharedAffectorList )
00226 mySharedAffectorList->findOverlapIdx(solver,
00227 this,
00228 overlap);
00229 else
00230 overlap.entries(0); }
00231 void setAffectorTreeDirty()
00232 { if( mySharedAffectorList )
00233 mySharedAffectorList->setObjectTreeDirty(); }
00234
00235 int getNumAffectors() const
00236 { return mySharedAffectorList
00237 ? mySharedAffectorList->entries()
00238 : 0; }
00239 RBD_Object *getAffector(int j) const
00240 { return (*mySharedAffectorList)(j); }
00241 const SIM_Collider *getCollider(int j) const
00242 { return mySharedAffectorList->
00243 getCollider(j, myObject); }
00244 SIM_Collider::SIM_ImpactApplyType getImpactApplyType(int j) const
00245 { return mySharedAffectorList->getImpactApplyType(j); }
00246
00247
00248
00249
00250 int getArrayIndex() const
00251 { return myArrayIndex; }
00252 void setArrayIndex(int index)
00253 { myArrayIndex = index; }
00254
00255 bool hasNailConstraints() const
00256 { return myHasConstraints; }
00257
00258 UT_PtrArray<SIM_ColliderCacheData *> &getCollideCache() { return myCollideCache; }
00259 void clearCollideCache();
00260
00261
00262 mutable bool myPinProcessFlag;
00263 RBD_ObjectArray myPinObjects;
00264
00265
00266
00267
00268 UT_Vector3Array myPinAnchorPos;
00269 UT_Vector3Array myPinAnchorGoalPos;
00270
00271 protected:
00272
00273
00274
00275
00276 void accumulateConstraints(const RBD_Solver *solver,
00277 RBD_Object *piece,
00278 UT_Vector3Array &hard_objpos,
00279 UT_Vector3Array &hard_goalpos,
00280 UT_Matrix3 &hard_spatialfilter,
00281 UT_Matrix3 &hard_rotationalfilter,
00282 const SIM_Time &time,
00283 const SIM_Time &endtime);
00284
00285 private:
00286
00287
00288
00289
00290
00291 void findClosestPropertyAtPosition(fpreal &newvalue,
00292 const SIM_Property &property,
00293 const UT_Vector3 &pos,
00294 bool &found, fpreal &closestdist) const;
00295
00296 SIM_Object *myObject;
00297 RBD_State *myState;
00298 SIM_Impacts *myImpacts;
00299 RBD_SharedAffectorList *mySharedAffectorList;
00300 int myArrayIndex;
00301
00302 const SIM_Geometry *myGeometry;
00303 const SIM_SDF *mySDF;
00304
00305
00306
00307 mutable GB_AttributeRef myPropertyOffset[SIM_PROPERTY_COUNT];
00308 mutable bool myPropertyLookedUp[SIM_PROPERTY_COUNT];
00309 mutable const RBD_SphereTree *mySphereTree;
00310
00311
00312 fpreal myRadius;
00313
00314
00315 bool myBBoxValid;
00316 UT_BoundingBox myBBox;
00317
00318
00319 UT_Vector3 myStashPos;
00320 UT_Quaternion myStashOrient;
00321 UT_Vector3 myStashVel;
00322 UT_Vector3 myStashAngVel;
00323
00324
00325 bool myIsGlued;
00326
00327 bool myHasConstraints;
00328
00329
00330 UT_Matrix3 myCacheTensor;
00331 UT_Vector3 myCachePivot;
00332 UT_Vector3 myMomentArm;
00333 UT_Matrix3 mySpatialFilter;
00334 UT_Matrix3 myRotationalFilter;
00335
00336
00337
00338 RBD_Object *myGlueParent;
00339 RBD_ObjectArray myGlueSubObjects;
00340
00341 UT_PtrArray<SIM_ColliderCacheData *> myCollideCache;
00342
00343 bool myHasInitFromGeometry;
00344 };
00345
00346 #endif