00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef __SIM_Impacts_h__
00015 #define __SIM_Impacts_h__
00016
00017 #include "SIM_API.h"
00018 #include <UT/UT_IntArray.h>
00019 #include <UT/UT_FloatArray.h>
00020 #include <UT/UT_Vector3Array.h>
00021 #include "SIM_DataUtils.h"
00022
00023 class UT_IStream;
00024 class SIM_ObjectArray;
00025
00026
00027
00028
00029
00030 #define SIM_IMPACTS_FRICTION 0x00000001
00031
00032
00033
00034 #define SIM_IMPACTS_REPULSION 0x00000002
00035
00036
00037
00038 #define SIM_IMPACTS_POINTINSIDE 0x00000004
00039
00040
00041 #define SIM_IMPACTS_CLOTHVOLUME 0x00000008
00042
00043
00044 #define SIM_IMPACTS_CLOTHCLOTH 0x00000010
00045
00046
00047 #define SIM_IMPACTS_PARTSTOP 0x00000020
00048
00049
00050 #define SIM_IMPACTS_PARTKILL 0x00000040
00051
00052
00053 #define SIM_IMPACTS_PARTCONTINUE 0x00000080
00054
00055
00056 #define SIM_IMPACTS_PARTSTICK 0x00000100
00057
00058
00059 #define SIM_IMPACTS_PARTBOUNCE 0x00000200
00060
00061
00062 #define SIM_IMPACTS_PARTANY (SIM_IMPACTS_PARTSTOP | \
00063 SIM_IMPACTS_PARTKILL | \
00064 SIM_IMPACTS_PARTCONTINUE | \
00065 SIM_IMPACTS_PARTSTICK | \
00066 SIM_IMPACTS_PARTBOUNCE)
00067
00068
00069
00070 #define SIM_IMPACTS_FEEDBACK 0x00000400
00071
00072
00073
00074
00075 #define SIM_IMPACTS_NOPRIMUV 0x00000800
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085 class SIM_API SIM_Impacts : public SIM_Data
00086 {
00087 public:
00088
00089 int getNumImpacts() const;
00090
00091
00092 const UT_Vector3 &getPosition(int index) const;
00093
00094
00095
00096
00097 const UT_Vector3 &getNormal(int index) const;
00098
00099 fpreal getImpulse(int index) const;
00100
00101 void setImpulse(int index, fpreal impulse);
00102
00103 void removeLastImpact();
00104
00105 int getFlags(int index) const;
00106
00107
00108 int getPointNumber(int index) const;
00109
00110
00111 int getPrimitiveNumber(int index) const;
00112
00113 fpreal getPrimitiveU(int index) const;
00114
00115 fpreal getPrimitiveV(int index) const;
00116
00117 int getOtherObjId(int index) const;
00118
00119
00120 int getOtherObjPointNumber(int index) const;
00121
00122
00123 int getOtherObjPrimitiveNumber(int index) const;
00124
00125
00126 fpreal getOtherObjPrimitiveU(int index) const;
00127
00128
00129 fpreal getOtherObjPrimitiveV(int index) const;
00130
00131 SIM_Time getTime(int index) const;
00132
00133
00134 void addPositionImpact(const UT_Vector3 &pos,
00135 const UT_Vector3 &normal,
00136 fpreal impulse,
00137 int otherobjid,
00138 int otherobjptnum,
00139 int otherobjprimnum,
00140 fpreal otherobjprimu,
00141 fpreal otherobjprimv,
00142 const SIM_Time &time,
00143 int flags = 0);
00144
00145
00146 void addPointImpact(const UT_Vector3 &pos,
00147 const UT_Vector3 &normal,
00148 fpreal impulse,
00149 int ptnum,
00150 int otherobjid,
00151 int otherobjptnum,
00152 int otherobjprimnum,
00153 fpreal otherobjprimu,
00154 fpreal otherobjprimv,
00155 const SIM_Time &time,
00156 int flags = 0);
00157
00158
00159 void addPrimitiveImpact(const UT_Vector3 &pos,
00160 const UT_Vector3 &normal,
00161 fpreal impulse,
00162 int primnum,
00163 fpreal primu,
00164 fpreal primv,
00165 int otherobjid,
00166 int otherobjptnum,
00167 int otherobjprimnum,
00168 fpreal otherobjprimu,
00169 fpreal otherobjprimv,
00170 const SIM_Time &time,
00171 int flags = 0);
00172
00173 void mergeImpacts(const SIM_Impacts &src);
00174
00175
00176
00177
00178 void mergeImpactsInTimeRange(const SIM_Impacts &src,
00179 const SIM_Time &startTime,
00180 const SIM_Time &endTime);
00181
00182
00183
00184
00185
00186
00187
00188 void keepOnlyImpactsForAffectors(
00189 const SIM_ObjectArray &affectors,
00190 int thisobjectid,
00191 int startindex);
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209 static UT_Vector3 getRequiredImpulse(const UT_Vector3 &worldspacepos,
00210 const UT_Vector3 &nml,
00211 const SIM_Object *obja,
00212 int ptnuma,
00213 bool objainfinitemass,
00214 const SIM_Object *objb,
00215 int ptnumb,
00216 bool objbinfinitemass,
00217 fpreal bounce,
00218 fpreal friction,
00219 fpreal dynamicfrictionmultiplier,
00220 bool usesdfvelocitya = false,
00221 bool usepointvelocitya = true,
00222 bool usesdfvelocityb = false,
00223 bool usepointvelocityb = true);
00224
00225 static UT_Vector3 getRequiredImpulse(const UT_DMatrix3 &Ka,
00226 const UT_Vector3 &vela,
00227 const UT_Vector3 &worldspacepos,
00228 const UT_Vector3 &nml,
00229 const SIM_Object *objb,
00230 int ptnumb,
00231 bool objbinfinitemass,
00232 fpreal bounce,
00233 fpreal friction,
00234 fpreal dynamicfrictionmultiplier,
00235 bool usesdfvelocityb = false,
00236 bool usepointvelocityb = true);
00237
00238
00239 static UT_Vector3 getRequiredImpulse(const UT_Vector3 &desiredrelvel,
00240 const UT_DMatrix3 &Ka,
00241 const UT_Vector3 &vela,
00242 const UT_DMatrix3 &Kb,
00243 const UT_Vector3 &velb,
00244 const UT_Vector3 &worldspacepos,
00245 const UT_Vector3 &nml,
00246 fpreal friction,
00247 fpreal dynamicfrictionmultiplier);
00248
00249
00250 static void splitImpulse(const UT_Vector3 &impulse,
00251 const UT_Vector3 &normal,
00252 fpreal &normalImpulseLength,
00253 UT_Vector3 &tangentImpulse);
00254
00255 protected:
00256
00257 explicit SIM_Impacts(const SIM_DataFactory *factory);
00258
00259 virtual ~SIM_Impacts();
00260
00261
00262 virtual void initializeSubclass();
00263
00264 virtual void makeEqualSubclass(const SIM_Data *source);
00265
00266 virtual void saveSubclass(ostream &os) const;
00267
00268 virtual bool loadSubclass(UT_IStream &is);
00269
00270 virtual int64 getMemorySizeSubclass() const;
00271
00272 virtual SIM_Query *createQueryObjectSubclass() const;
00273
00274
00275
00276 void resizeArrays(int numimpacts);
00277
00278
00279
00280 void removeImpact(int index);
00281 private:
00282 UT_Vector3Array myPositions;
00283 UT_Vector3Array myNormals;
00284 UT_FloatArray myImpulses;
00285 UT_IntArray myFlags;
00286 UT_IntArray myPtNums;
00287 UT_IntArray myPrimNums;
00288 UT_FloatArray myPrimUs;
00289 UT_FloatArray myPrimVs;
00290 UT_IntArray myOtherObjIds;
00291 UT_IntArray myOtherObjPtNums;
00292 UT_IntArray myOtherObjPrimNums;
00293 UT_FloatArray myOtherObjPrimUs;
00294 UT_FloatArray myOtherObjPrimVs;
00295 UT_FloatArray myTimes;
00296
00297 DECLARE_STANDARD_GETCASTTOTYPE();
00298 DECLARE_DATAFACTORY(SIM_Impacts,
00299 SIM_Data,
00300 "Impact Information",
00301 getEmptyDopDescription());
00302 };
00303
00304 #endif
00305