00001
00002
00003
00004
00006
00007 #ifndef __NEWBODY_H__
00008 #define __NEWBODY_H__
00009
00010 #define SMALL_ANGVEL TO_ANGVEL(Real(0.000001))
00011
00012 #define REMOVE_JITTER TRUE
00013
00014 #define CLOSE_BODY_COLL TO_LENGTH(Real(300.0f))
00015 #define CLOSE_BODY_COLL_DOT (0.1f)
00016
00017 #define BODY_COLL_CONVEX 0x0
00018 #define BODY_COLL_SPHERE 0x1
00019 #define BODY_COLL_POLY 0x2
00020
00021 #define MAX_SPARKS_PER_BODY 10
00022 #define MAX_SMOKES_PER_BODY 2
00023
00024 #define MAX_SCRAPE_TIME Real(0.05f)
00025
00026 #define MIN_KNOCK_VEL TO_VEL(Real(300))
00027
00028 struct BodyCollInfoStruct;
00029
00030 typedef struct NewBodyStruct {
00031 PARTICLE Centre;
00032
00033 MAT BodyInertia;
00034 MAT BodyInvInertia;
00035
00036 MAT WorldInvInertia;
00037
00038 VEC AngVel;
00039 VEC AngAcc;
00040 VEC AngImpulse;
00041
00042 REAL DefaultAngRes;
00043 REAL AngResMod;
00044 REAL AngResistance;
00045
00046 COLLSKIN CollSkin;
00047
00048
00049 VEC LastAngVel;
00050 bool IsJittering;
00051 int JitterCount;
00052 int JitterCountMax;
00053 int JitterFrames;
00054 int JitterFramesMax;
00055
00056
00057 COLLINFO_BODY *BodyCollHead;
00058 int NBodyColls;
00059
00060 int NWorldContacts;
00061 int NOtherContacts;
00062 REAL NoContactTime;
00063
00064 bool AllowSparks;
00065 long ScrapeMaterial;
00066 REAL LastScrapeTime;
00067
00068 bool Banged;
00069 REAL BangMag;
00070 PLANE BangPlane;
00071
00072 } NEWBODY;
00073
00074
00076
00077
00078
00079
00080
00081 #define ApplyBodyAngImpulse(body, angImpulse) \
00082 { \
00083 VecPlusEqVec(&(body)->AngImpulse, (angImpulse)); \
00084 }
00085
00086
00087 #define CalcAngImpulse(impulse, pos, angImp) \
00088 { \
00089 VecCrossVec((pos), (impulse), (angImp)); \
00090 }
00091
00092 #define SetBodyConvex(body) ((body)->CollSkin.CollType = BODY_COLL_CONVEX)
00093 #define IsBodyConvex(body) ((body)->CollSkin.CollType == BODY_COLL_CONVEX)
00094 #define SetBodySphere(body) ((body)->CollSkin.CollType = BODY_COLL_SPHERE)
00095 #define IsBodySphere(body) ((body)->CollSkin.CollType == BODY_COLL_SPHERE)
00096 #define SetBodyPoly(body) ((body)->CollSkin.CollType = BODY_COLL_POLY)
00097 #define IsBodyPoly(body) ((body)->CollSkin.CollType == BODY_COLL_POLY)
00098
00099
00100 #define BodyAllowsSparks(body) ((body)->AllowSparks)
00101
00103
00104
00105
00106
00107 extern void ApplyBodyImpulse(NEWBODY *body, VEC *impulse, VEC *impulsePos);
00108 extern void UpdateBody(NEWBODY *body, REAL dt);
00109 extern void BodyPointVel(NEWBODY *body, VEC *dR, VEC *vel);
00110
00111 extern void InitBodyDefault(NEWBODY *body);
00112 extern void SetBodyPos(NEWBODY *body, VEC *pos, MAT *mat);
00113 extern void SetBodyInertia(NEWBODY *body, MAT *inertia);
00114 extern void BuildCuboidInertia(REAL mass, REAL xDim, REAL yDim, REAL zDim, VEC *mat);
00115 extern void MoveInertiaAxis(MAT *inIn, REAL mass, REAL dx, REAL dy, REAL dz, MAT *inOut);
00116 extern void GetFrameInertia(MAT *bodyInvInertia, MAT *transform, MAT *worldInvInertia);
00117 extern REAL BodyKE(NEWBODY *body);
00118
00119 extern void BuildOneBodyColMat(NEWBODY *body, VEC *colPos, VEC *colPos2, MAT *colMat);
00120 extern void BuildTwoBodyColMat(NEWBODY *body1, NEWBODY *body2, VEC *colPos1, VEC *relPos1, VEC *colPos2, VEC *relPos2, MAT *colMat);
00121
00122 extern REAL OneBodyZeroFrictionImpulse(NEWBODY *body,
00123 VEC *pos,
00124 VEC *normal,
00125 REAL deltaVel);
00126 extern void TwoBodyZeroFrictionImpulse(NEWBODY *body1, NEWBODY *body2,
00127 VEC *pos1, VEC *pos2,
00128 VEC *normal,
00129 REAL deltaVel,
00130 VEC *impulse);
00131
00132 extern void SetBodyBBoxes(NEWBODY *body);
00133
00134 extern void DetectBodyWorldColls(NEWBODY *body);
00135 extern int DetectBodyBodyColls(NEWBODY *body1, NEWBODY *body2);
00136 extern void DetectBodyPolyColls(NEWBODY *body, NEWCOLLPOLY *collPoly);
00137 extern int DetectConvexHullPolyColls(NEWBODY *body, NEWCOLLPOLY *collPoly);
00138 extern int DetectHullHullColls(NEWBODY *body1, NEWBODY *body2);
00139 extern void DetectSpherePolyColls(NEWBODY *body, NEWCOLLPOLY *collPoly);
00140 extern int DetectSphereSphereColls(NEWBODY *body1, NEWBODY *body2);
00141 extern int DetectSphereHullColls(NEWBODY *body1, NEWBODY *body2);
00142 extern void PreProcessBodyColls(NEWBODY *body);
00143 extern void ProcessBodyColls3(NEWBODY *body);
00144 extern void PostProcessBodyColls(NEWBODY *body);
00145 extern void AddBodyFriction(NEWBODY *body, VEC *impulse, COLLINFO_BODY *collInfo);
00146 extern void BodyTurboBoost(NEWBODY *body);
00147
00148 extern void SetupMassiveBody();
00149
00150 extern void RemoveBodyColl(NEWBODY *body, COLLINFO_BODY *collInfo);
00151 extern COLLINFO_BODY *AddBodyColl(NEWBODY *body, COLLINFO_BODY *newHead);
00152
00153
00155
00156
00157
00158
00159 extern REAL BDY_Tolerance;
00160 extern NEWBODY BDY_MassiveBody;
00161
00162 #endif