00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef CCollisionSpheresH
00024 #define CCollisionSpheresH
00025
00026 #include "math/CMaths.h"
00027 #include "collisions/CGenericCollision.h"
00028 #include "collisions/CCollisionSpheresGeometry.h"
00029 #include "graphics/CVertex.h"
00030 #include "graphics/CTriangle.h"
00031 #include "graphics/CDraw3D.h"
00032 #include "graphics/CColor.h"
00033 #include "scenegraph/CMesh.h"
00034 #include <assert.h>
00035 #include <list>
00036 #include <queue>
00037 #include <vector>
00038
00039
00047
00048
00049
00051 typedef vector<cCollisionSpheresGenericShape*> Plist;
00052
00054 class cCollisionSpheresSphere;
00055
00057 class cCollisionSpheresLeaf;
00058
00059
00060
00070
00071 class cCollisionSpheres : public cGenericCollision
00072 {
00073 public:
00074
00075
00076
00077
00078
00080 cCollisionSpheres(vector<cTriangle> *a_triangles, bool a_useNeighbors);
00081
00083 virtual ~cCollisionSpheres();
00084
00085
00086
00087
00088
00089
00091 void initialize(double a_radius = 0);
00092
00094 void render();
00095
00097 bool computeCollision(cVector3d& a_segmentPointA,
00098 cVector3d& a_segmentPointB,
00099 cCollisionRecorder& a_recorder,
00100 cCollisionSettings& a_settings);
00101
00102
00103
00104
00105
00106
00108 cCollisionSpheresSphere *m_root;
00109
00111 vector<cTriangle> *m_trigs;
00112
00114 cTriangle *m_lastCollision;
00115
00117 bool m_useNeighbors;
00118
00120 cCollisionSpheresLeaf *m_firstLeaf;
00121
00123 cTriangle* secret;
00124 };
00125
00126
00127
00136
00137 class cCollisionSpheresSphere
00138 {
00139
00140
00141
00142
00144 friend class cCollisionSpheresNode;
00145
00147 friend class cCollisionSpheresLeaf;
00148
00149
00150 public:
00151
00152
00153
00154
00155
00157 cCollisionSpheresSphere(cCollisionSpheresSphere *a_parent);
00158
00160 cCollisionSpheresSphere() : m_center(0,0,0), m_parent(0), m_depth(0) { };
00161
00163 virtual ~cCollisionSpheresSphere() {};
00164
00165
00166
00167
00168
00169
00171 inline const cVector3d &getCenter() { return m_center; }
00172
00174 inline double getRadius() { return m_radius; }
00175
00177 virtual int isLeaf() = 0;
00178
00180 virtual void draw(int a_depth = -1) = 0;
00181
00183 static bool computeCollision(cCollisionSpheresSphere *a_sa,
00184 cCollisionSpheresSphere *a_sb,
00185 cCollisionRecorder& a_recorder,
00186 cCollisionSettings& a_settings);
00187
00188 protected:
00189
00190
00191
00192
00193
00195 cCollisionSpheresSphere *m_parent;
00196
00198 cVector3d m_center;
00199
00201 double m_radius;
00202
00204 int m_depth;
00205
00207 int m_num;
00208 };
00209
00210
00211
00221
00222 class cCollisionSpheresNode : public cCollisionSpheresSphere
00223 {
00224 public:
00225
00226
00227
00228
00229
00231 cCollisionSpheresNode(Plist &a_primList,
00232 cCollisionSpheresSphere *a_parent = NULL);
00233
00235 cCollisionSpheresNode(std::vector<cTriangle> *a_tris,
00236 cCollisionSpheresSphere *a_parent = NULL,
00237 double a_extendedRadius = 0);
00238
00240 cCollisionSpheresNode() : cCollisionSpheresSphere(), m_left(0), m_right(0) { };
00241
00243 virtual ~cCollisionSpheresNode() {};
00244
00245
00246
00247
00248
00249
00251 void ConstructChildren(Plist &a_primList);
00252
00254 int isLeaf() { return 0; }
00255
00257 void draw(int a_depth);
00258
00260 static bool computeCollision(cCollisionSpheresNode *a_sa,
00261 cCollisionSpheresSphere *a_sb,
00262 cCollisionRecorder& a_recorder,
00263 cCollisionSettings& a_settings);
00264
00266 static void swapptr(void **a_a, void **a_b);
00267
00268
00269
00270
00271
00272
00274 cCollisionSpheresSphere *m_left;
00275
00277 cCollisionSpheresSphere *m_right;
00278 };
00279
00280
00281
00291
00292 class cCollisionSpheresLeaf : public cCollisionSpheresSphere
00293 {
00294 public:
00295
00296
00297
00298
00299
00301 cCollisionSpheresLeaf(cCollisionSpheresGenericShape *a_prim,
00302 cCollisionSpheresSphere *a_parent = NULL);
00303
00305 cCollisionSpheresLeaf(cTriangle *a_tri,
00306 cCollisionSpheresSphere *a_parent = NULL,
00307 double a_extendedRadius = 0);
00308
00310 cCollisionSpheresLeaf() : cCollisionSpheresSphere() { m_prim = 0; }
00311
00313 virtual ~cCollisionSpheresLeaf() { if (m_prim) delete m_prim; }
00314
00315
00316
00317
00318
00319
00321 int isLeaf() { return 1; }
00322
00324 void draw(int a_depth);
00325
00327 static bool computeCollision(cCollisionSpheresLeaf *a_sa,
00328 cCollisionSpheresLeaf *a_sb,
00329 cCollisionRecorder& a_recorder,
00330 cCollisionSettings& a_settings);
00331
00332
00333
00334
00335
00336
00338 cCollisionSpheresGenericShape *m_prim;
00339 };
00340
00341
00342 #endif
00343
00344
00345