00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef CCollisionSpheresGeometryH
00024 #define CCollisionSpheresGeometryH
00025
00026 #include "math/CMaths.h"
00027 #include "graphics/CTriangle.h"
00028 #include <assert.h>
00029 #include <list>
00030 #include <map>
00031 #include <math.h>
00032
00033 using std::map;
00034 using std::less;
00035 using std::list;
00036
00037 class cCollisionSpheresPoint;
00038 class cCollisionSpheresEdge;
00039 class cCollisionSpheresLeaf;
00040
00042 typedef map<cCollisionSpheresPoint *, cCollisionSpheresEdge *,
00043 less<cCollisionSpheresPoint *> > PtEmap;
00044
00045
00046
00054
00055
00056
00064
00065 class cCollisionSpheresPoint
00066 {
00067 public:
00068
00069
00070
00071
00072
00074 cCollisionSpheresPoint(double a_x = 0,
00075 double a_y = 0,
00076 double a_z = 0)
00077 { m_pos.x = a_x; m_pos.y = a_y; m_pos.z = a_z; }
00078
00079
00080
00081
00082
00083
00085 cVector3d m_pos;
00086
00088 PtEmap m_edgeMap;
00089 };
00090
00091
00092
00100
00101 class cCollisionSpheresEdge
00102 {
00103 public:
00104
00105
00106
00107
00108
00110 cCollisionSpheresEdge() { }
00111
00113 cCollisionSpheresEdge(cCollisionSpheresPoint *a_a,
00114 cCollisionSpheresPoint *a_b)
00115 { initialize(a_a,a_b); }
00116
00118 virtual ~cCollisionSpheresEdge() {}
00119
00120
00121
00122
00123
00124
00126 void initialize(cCollisionSpheresPoint *a_a, cCollisionSpheresPoint *a_b);
00127
00129 inline const cVector3d &getCenter() const {return m_center;}
00130
00132 inline double getRadius() const
00133 { if (m_D <= 0.0) return 0.0; return sqrt(m_D)/2; }
00134
00135
00136 private:
00137
00138
00139
00140
00141
00143 cCollisionSpheresPoint *m_end[2];
00144
00146 cVector3d m_center;
00147
00149 cVector3d m_d;
00150
00152 double m_D;
00153 };
00154
00155
00156
00166
00167 class cCollisionSpheresGenericShape
00168 {
00169 public:
00170
00171
00172
00173
00174
00176 cCollisionSpheresGenericShape() : m_sphere(NULL) { }
00177
00179 virtual ~cCollisionSpheresGenericShape() {}
00180
00181
00182
00183
00184
00185
00187 virtual const cVector3d &getCenter() const = 0;
00188
00190 virtual double getRadius() const = 0;
00191
00193 virtual bool computeCollision(cCollisionSpheresGenericShape *a_other,
00194 cCollisionRecorder& a_recorder,
00195 cCollisionSettings& a_settings) = 0;
00196
00198 virtual cCollisionSpheresLeaf* getSphere() { return m_sphere; }
00199
00201 virtual void setSphere(cCollisionSpheresLeaf* a_sphere)
00202 { m_sphere = a_sphere; }
00203
00205 bool operator<(cCollisionSpheresGenericShape* a_other)
00206 { return (getCenter().get(m_split) < a_other->getCenter().get(m_split)); }
00207
00208
00209
00210
00211
00212
00214 static int m_split;
00215
00216
00217 private:
00218
00219
00220
00221
00222
00224 cCollisionSpheresLeaf *m_sphere;
00225 };
00226
00227
00228
00239
00240 class cCollisionSpheresTri : public cCollisionSpheresGenericShape
00241 {
00242 public:
00243
00244
00245
00246
00247
00249 cCollisionSpheresTri(cVector3d a,
00250 cVector3d b,
00251 cVector3d c,
00252 double a_extendedRadius);
00253
00255 virtual ~cCollisionSpheresTri() {};
00256
00257
00258
00259
00260
00261
00263 bool computeCollision(cCollisionSpheresGenericShape *a_other,
00264 cCollisionRecorder& a_recorder,
00265 cCollisionSettings& a_settings);
00266
00268 inline const cVector3d &getCenter() const { return m_center; }
00269
00271 inline double getRadius() const { return m_radius; }
00272
00274 cTriangle* getOriginal() { return m_original; }
00275
00277 void setOriginal(cTriangle* a_original) { m_original = a_original; }
00278
00279
00280 protected:
00281
00282
00283
00284
00285
00287 cCollisionSpheresPoint m_corner[3];
00288
00290 cCollisionSpheresEdge m_side[3];
00291
00293 cVector3d m_center;
00294
00296 double m_radius;
00297
00299 cTriangle* m_original;
00300 };
00301
00302
00303
00312
00313 class cCollisionSpheresLine : public cCollisionSpheresGenericShape
00314 {
00315 public:
00316
00317
00318
00319
00320
00322 cCollisionSpheresLine(cVector3d& a_segmentPointA,
00323 cVector3d& a_segmentPointB);
00324
00326 virtual ~cCollisionSpheresLine() {}
00327
00328
00329
00330
00331
00332
00334 inline const cVector3d &getCenter() const { return m_center; }
00335
00337 inline double getRadius() const { return m_radius; }
00338
00340 bool computeCollision(cCollisionSpheresGenericShape *a_other,
00341 cCollisionRecorder& a_recorder,
00342 cCollisionSettings& a_settings);
00343
00345 cVector3d getSegmentPointA() { return m_segmentPointA; }
00346
00348 cVector3d getSegmentPointB() { return m_segmentPointB; }
00349
00350
00351 protected:
00352
00353
00354
00355
00356
00358 cVector3d m_center;
00359
00361 double m_radius;
00362
00364 cVector3d m_segmentPointA;
00365
00367 cVector3d m_segmentPointB;
00368 };
00369
00370
00371 #endif
00372