00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef CODEGenericBodyH
00023 #define CODEGenericBodyH
00024
00025 #include "ode/ode.h"
00026 #include "chai3d.h"
00027
00028
00029
00037
00038
00039
00040 class cODEWorld;
00041
00043 enum cODEDynamicModelType
00044 {
00045 ODE_MODEL_BOX,
00046 ODE_MODEL_SPHERE,
00047 ODE_MODEL_CYLINDER,
00048 ODE_MODEL_PLANE,
00049 ODE_MODEL_TRIMESH
00050 };
00051
00052
00053
00061
00062 class cODEGenericBody : public cGenericObject
00063 {
00064
00065 public:
00066
00067
00068
00069
00070
00072 cODEGenericBody(cODEWorld* a_world) { initialize(a_world); }
00073
00075 virtual ~cODEGenericBody() {};
00076
00077
00078
00079
00080
00081
00083 void setPosition(cVector3d &a_position);
00084
00086 void setRotation(cMatrix3d &a_rotation);
00087
00089 void updateBodyPosition(void);
00090
00092 void addGlobalForceAtGlobalPos(cVector3d& a_force, cVector3d& a_pos);
00093
00095 void setMass(double a_mass);
00096
00098 double getMass() { return (m_mass); }
00099
00101 void setImageModel(cGenericObject* a_imageModel);
00102
00104 cGenericObject* getImageModel() { return (m_imageModel); }
00105
00107 void enableDynamics();
00108
00110 void disableDynamics();
00111
00113 bool isStatic() { return (m_static); }
00114
00116 virtual void buildDynamicModel() {};
00117
00119 void createDynamicBoundingBox(bool a_staticObject = false);
00120
00122 void createDynamicSphere(const double a_radius,
00123 bool a_staticObject = false,
00124 const cVector3d& a_offsetPos = cVector3d(0.0, 0.0, 0.0),
00125 const cMatrix3d& a_offsetRot = cIdentity3d());
00126
00128 void createDynamicBox(const double a_lengthX, const double a_lengthY, const double a_lengthZ,
00129 bool a_staticObject = false,
00130 const cVector3d& a_offsetPos = cVector3d(0.0, 0.0, 0.0),
00131 const cMatrix3d& a_offsetRot = cIdentity3d());
00132
00134 void createDynamicCapsule(const double a_radius, const double a_length,
00135 bool a_staticObject = false,
00136 const cVector3d& a_offsetPos = cVector3d(0.0, 0.0, 0.0),
00137 const cMatrix3d& a_offsetRot = cIdentity3d());
00138
00140 void createStaticPlane(const cVector3d& a_position,
00141 const cVector3d& a_normal);
00142
00144 void createDynamicMesh(bool a_staticObject = false,
00145 const cVector3d& a_offsetPos = cVector3d(0.0, 0.0, 0.0),
00146 const cMatrix3d& a_offsetRot = cIdentity3d());
00147
00149 void updateGlobalPositions(const bool a_frameOnly);
00150
00152 void render(const int a_renderMode);
00153
00155 void setShowDynamicCollisionModel(const bool a_show) { m_showDynamicCollisionModel = a_show; }
00156
00158 bool getShowDynamicCollisionModel() { return(m_showDynamicCollisionModel); }
00159
00161 cODEWorld* m_ODEWorld;
00162
00164 cGenericObject* m_imageModel;
00165
00166
00167 private:
00168
00169
00170
00171
00172
00174 bool m_static;
00175
00177 dBodyID m_ode_body;
00178
00180 dMass m_ode_mass;
00181
00183 double m_mass;
00184
00186 dGeomID m_ode_geom;
00187
00189 float* m_vertices;
00190
00192 int* m_vertexIndices;
00193
00195 double m_prevTransform[16];
00196
00198 dTriMeshDataID m_ode_triMeshDataID;
00199
00201 bool m_showDynamicCollisionModel;
00202
00204 cColorf m_colorDynamicCollisionModel;
00205
00207 cODEDynamicModelType m_typeDynamicCollisionModel;
00208
00214 double m_paramDynColModel0;
00215 double m_paramDynColModel1;
00216 double m_paramDynColModel2;
00217 cVector3d m_posOffsetDynColModel;
00218 cMatrix3d m_rotOffsetDynColModel;
00219
00221 int buildMeshTable(cMesh* a_mesh, int& a_indexOffset, int& a_verticesCount, int& a_indexCount);
00222
00224 void initialize(cODEWorld* a_world);
00225
00227 virtual bool computeOtherCollisionDetection(cVector3d& a_segmentPointA,
00228 cVector3d& a_segmentPointB,
00229 cCollisionRecorder& a_recorder,
00230 cCollisionSettings& a_settings);
00231 };
00232
00233
00234
00235 #endif
00236