00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef __RBD_State_h__
00015 #define __RBD_State_h__
00016
00017 #include "RBD_API.h"
00018 #include <UT/UT_Matrix3.h>
00019 #include <UT/UT_Vector3Array.h>
00020 #include <SIM/SIM_Motion.h>
00021 #include "RBD_Utils.h"
00022
00023 class GU_SDF;
00024 class SIM_Object;
00025 class SIM_ObjectArray;
00026 class SIM_Constraint;
00027 class RBD_Object;
00028 class SIM_Geometry;
00029 class SIM_Force;
00030 class UT_Matrix;
00031
00032
00033
00034 class RBD_API RBD_State : public SIM_Motion
00035 {
00036 public:
00037
00038 GETSET_DATA_FUNCS_M3(RBD_NAME_ITENSOR, InertialTensor);
00039 GET_DATA_FUNC_M3(RBD_NAME_ITENSORLOCALINV, InertialTensorLocalInv);
00040 GETSET_DATA_FUNCS_B(RBD_NAME_INHERITVELOCITY, InheritVelocity);
00041 GETSET_DATA_FUNCS_B(RBD_NAME_COMPUTECOM, ComputeCOM);
00042 GETSET_DATA_FUNCS_B(RBD_NAME_COMPUTEMASS, ComputeMass);
00043 GETSET_DATA_FUNCS_B(RBD_NAME_COMPUTEINERTIALTENSOR,
00044 ComputeInertialTensor);
00045 GETSET_DATA_FUNCS_I(RBD_NAME_COMPUTEINERTIALTENSORTYPE,
00046 ComputeInertialTensorType);
00047 GET_DATA_FUNC_F(RBD_NAME_DENSITY, Density);
00048 GETSET_DATA_FUNCS_F(RBD_NAME_MASS, Mass);
00049 GETSET_DATA_FUNCS_F(RBD_NAME_INERTIALTENSORSTIFFNESS,
00050 InertialTensorStiffness);
00051
00052 GETSET_DATA_FUNCS_S(RBD_NAME_GLUEOBJECT, GlueObject);
00053 GETSET_DATA_FUNCS_F(RBD_NAME_GLUETHRESHOLD, GlueThreshold);
00054 GETSET_DATA_FUNCS_F(RBD_NAME_GLUEIMPULSE, GlueImpulse);
00055 GETSET_DATA_FUNCS_F(RBD_NAME_GLUEIMPULSEHALFLIFE, GlueImpulseHalfLife);
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066 void updatePhysicalValues(RBD_Object *obj,
00067 const GU_SDF *sdf,
00068 const SIM_Geometry *geo,
00069 bool updatelinearvel);
00070
00071
00072
00073
00074
00075 void getNewPosition(const SIM_Object &object,
00076 const SIM_Time &time,
00077 const SIM_Time ×tep,
00078 UT_Vector3 &newpos,
00079 UT_Quaternion &neworient) const;
00080
00081
00082
00083
00084 void getNewVelocity(RBD_Object *object,
00085 const SIM_Time &time,
00086 const SIM_Time ×tep,
00087 UT_Vector3 &newvel,
00088 UT_Vector3 &newangvel) const;
00089
00090
00091
00092
00093 void getNewVelocity(RBD_Object *object,
00094 const SIM_Time &time,
00095 const SIM_Time ×tep,
00096 const UT_Vector3 &com,
00097 UT_Vector3 &newvel,
00098 UT_Vector3 &newangvel) const;
00099
00100
00101
00102
00103
00104
00105
00106 static void projectRigidMotion(
00107 UT_Vector3 &vel,
00108 UT_Vector3 &angvel,
00109 const UT_Vector3 &com,
00110 const UT_Vector3Array &posarray,
00111 const UT_Vector3Array &velarray);
00112
00113
00114
00115 const UT_Vector3 getNewVelocity(fpreal impulse,
00116 const UT_Vector3 &normal) const;
00117 const UT_Vector3 getNewAngularVelocity(fpreal impulse,
00118 const UT_Vector3 &pos,
00119 const UT_Vector3 &normal) const;
00120
00121
00122
00123
00124
00125
00126 void constrainPosition(SIM_Object &object,
00127 const SIM_Time &time,
00128 const SIM_Time ×tep,
00129 UT_Vector3 &pos,
00130 UT_Quaternion &orient) const;
00131
00132
00133
00134
00135
00136 void constrainAccordingToPositions(
00137 const UT_Vector3Array &hard_objpos,
00138 const UT_Vector3Array &hard_goalpos,
00139 const UT_Matrix3 &hard_filter,
00140 UT_Vector3 &pos,
00141 UT_Quaternion &orient) const;
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151 void constrainVelocity(SIM_Object &object,
00152 const SIM_ObjectArray &solvingobjects,
00153 const SIM_Time &time,
00154 const SIM_Time ×tep,
00155 UT_Vector3 &vel,
00156 UT_Vector3 &angvel) const;
00157
00158
00159
00160
00161
00162
00163 UT_Vector3 solveForImpulse(const UT_Vector3 &pos,
00164 const UT_Vector3 &relvel) const;
00165
00166
00167
00168
00169
00170 void changePosition(RBD_Object *obj,
00171 const UT_Vector3 &pos,
00172 const UT_Quaternion &orient);
00173 void changeVelocity(RBD_Object *obj,
00174 const UT_Vector3 &vel,
00175 const UT_Vector3 &angvel);
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186 void changePivot(const UT_Vector3 &pivot,
00187 bool updatetensor,
00188 bool updatelinearvel = true);
00189
00190
00191
00192 void accumulateGlueImpulse(fpreal impulse);
00193
00194
00195
00196 void decayGlueImpulse(SIM_Time timestep);
00197
00198 protected:
00199 explicit RBD_State(const SIM_DataFactory *factory);
00200 virtual ~RBD_State();
00201
00202
00203
00204 virtual void optionChangedSubclass(const char *name);
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215 enum constrainType { CON_NONE, CON_SINGLEPOINT, CON_AXIS, CON_FULL };
00216
00217 constrainType findConstraintType(const UT_Vector3Array &geo,
00218 const UT_Vector3Array &anchor,
00219 UT_Vector3 &objpos,
00220 UT_Vector3 &goalpos,
00221 UT_Vector3 &objaxis,
00222 UT_Vector3 &goalaxis,
00223 UT_Quaternion &orient) const;
00224
00225 private:
00226 void updateInertialTensor();
00227 static const SIM_DopDescription *getStateDopDescription();
00228
00229
00230
00231 void calculateForceForces(const RBD_Object *obj,
00232 const UT_Vector3 &com,
00233 UT_Vector3 &sumforces,
00234 UT_Vector3 &sumtorques,
00235 UT_Matrix &sumDfDx,
00236 UT_Matrix &sumDfDv) const;
00237
00238
00239
00240 void calculateConstraintForces(SIM_Object &object,
00241 const UT_Vector3 &com,
00242 const SIM_Time &time,
00243 const SIM_Time ×tep,
00244 UT_Vector3 &sumforces,
00245 UT_Vector3 &sumtorques,
00246 UT_Matrix &sumDfDx,
00247 UT_Matrix &sumDfDv) const;
00248
00249 void calculateImpactForces(RBD_Object *object,
00250 const UT_Vector3 &com,
00251 const SIM_Time &time,
00252 const SIM_Time ×tep,
00253 const char *impactsdataname,
00254 UT_Vector3 &sumforces,
00255 UT_Vector3 &sumtorques) const;
00256
00257
00258
00259 fpreal computeMassFromSDF(const GU_SDF *sdf);
00260 fpreal computeMassFromGeometry(const SIM_Geometry *geo);
00261
00262 void computeCenterOfMassFromSDF(UT_Vector3 &com,
00263 const GU_SDF *sdf);
00264 void computeCenterOfMassFromGeometry(UT_Vector3 &com,
00265 const SIM_Geometry *geo);
00266
00267 void computeInertialTensorFromSDF(UT_DMatrix3 &tensor,
00268 const UT_Vector3 &com,
00269 const GU_SDF *sdf);
00270 void computeInertialTensorFromGeometry(UT_DMatrix3 &tensor,
00271 const UT_Vector3 &com,
00272 const SIM_Geometry *geo);
00273 fpreal computePrimMass(const GU_Detail *gdp,
00274 const GEO_Primitive *prim) const;
00275 UT_Vector3 computePrimBaryCenter(const GU_Detail *gdp,
00276 const GEO_Primitive *prim) const;
00277
00278
00279
00280 void sampleForce(const RBD_Object *obj,
00281 const UT_Vector3 &com,
00282 const SIM_Force *forcedata,
00283 UT_Vector3 &sumforce,
00284 UT_Vector3 &sumtorque,
00285 UT_Matrix &sumDfDx,
00286 UT_Matrix &sumDfDv) const;
00287
00288
00289 void sampleVolumeForce(const RBD_Object *obj,
00290 const UT_Vector3 &com,
00291 const SIM_Force *forcedata,
00292 UT_Vector3 &sumforce,
00293 UT_Vector3 &sumtorque,
00294 UT_Matrix &sumDfDx,
00295 UT_Matrix &sumDfDv) const;
00296
00297 void sampleAreaForce(const RBD_Object *obj,
00298 const UT_Vector3 &com,
00299 const SIM_Force *forcedata,
00300 UT_Vector3 &sumforce,
00301 UT_Vector3 &sumtorque,
00302 UT_Matrix &sumDfDx,
00303 UT_Matrix &sumDfDv) const;
00304
00305 void samplePointForce(const RBD_Object *obj,
00306 const UT_Vector3 &com,
00307 const SIM_Force *forcedata,
00308 UT_Vector3 &sumforce,
00309 UT_Vector3 &sumtorque,
00310 UT_Matrix &sumDfDx,
00311 UT_Matrix &sumDfDv) const;
00312
00313 DECLARE_STANDARD_GETCASTTOTYPE();
00314 DECLARE_DATAFACTORY(RBD_State,
00315 SIM_Motion,
00316 "RBD State",
00317 getStateDopDescription());
00318 };
00319
00320 #endif
00321