00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00025 #ifndef CYCLONE_COLLISION_FINE_H
00026 #define CYCLONE_COLLISION_FINE_H
00027
00028 #include "contacts.h"
00029
00030 namespace cyclone {
00031
00032
00033 class IntersectionTests;
00034 class CollisionDetector;
00035
00039 class CollisionPrimitive
00040 {
00041 public:
00047 friend IntersectionTests;
00048 friend CollisionDetector;
00049
00053 RigidBody * body;
00054
00058 Matrix4 offset;
00059
00063 void calculateInternals();
00064
00069 Vector3 getAxis(unsigned index) const
00070 {
00071 return transform.getAxisVector(index);
00072 }
00073
00080 const Matrix4& getTransform() const
00081 {
00082 return transform;
00083 }
00084
00085
00086 protected:
00092 Matrix4 transform;
00093 };
00094
00099 class CollisionSphere : public CollisionPrimitive
00100 {
00101 public:
00105 real radius;
00106 };
00107
00113 class CollisionPlane
00114 {
00115 public:
00119 Vector3 direction;
00120
00124 real offset;
00125 };
00126
00131 class CollisionBox : public CollisionPrimitive
00132 {
00133 public:
00137 Vector3 halfSize;
00138 };
00139
00145 class IntersectionTests
00146 {
00147 public:
00148
00149 static bool sphereAndHalfSpace(
00150 const CollisionSphere &sphere,
00151 const CollisionPlane &plane);
00152
00153 static bool sphereAndSphere(
00154 const CollisionSphere &one,
00155 const CollisionSphere &two);
00156
00157 static bool boxAndBox(
00158 const CollisionBox &one,
00159 const CollisionBox &two);
00160
00173 static bool boxAndHalfSpace(
00174 const CollisionBox &box,
00175 const CollisionPlane &plane);
00176 };
00177
00178
00180
00184 struct CollisionData
00185 {
00187
00193 Contact *contactArray;
00194
00196
00197 Contact *contacts;
00198
00200 int contactsLeft;
00202
00204 unsigned contactCount;
00205
00207 real friction;
00208
00210 real restitution;
00211
00216 real tolerance;
00217
00222 bool hasMoreContacts()
00223 {
00224 return contactsLeft > 0;
00225 }
00226
00230 void reset(unsigned maxContacts)
00231 {
00232 contactsLeft = maxContacts;
00233 contactCount = 0;
00234 contacts = contactArray;
00235 }
00236
00241 void addContacts(unsigned count)
00242 {
00243
00244 contactsLeft -= count;
00245 contactCount += count;
00246
00247
00248 contacts += count;
00249 }
00251 };
00253
00262 class CollisionDetector
00263 {
00264 public:
00265
00266 static unsigned sphereAndHalfSpace(
00267 const CollisionSphere &sphere,
00268 const CollisionPlane &plane,
00269 CollisionData *data
00270 );
00271
00272 static unsigned sphereAndTruePlane(
00273 const CollisionSphere &sphere,
00274 const CollisionPlane &plane,
00275 CollisionData *data
00276 );
00277
00278 static unsigned sphereAndSphere(
00279 const CollisionSphere &one,
00280 const CollisionSphere &two,
00281 CollisionData *data
00282 );
00283
00289 static unsigned boxAndHalfSpace(
00290 const CollisionBox &box,
00291 const CollisionPlane &plane,
00292 CollisionData *data
00293 );
00294
00295 static unsigned boxAndBox(
00296 const CollisionBox &one,
00297 const CollisionBox &two,
00298 CollisionData *data
00299 );
00300
00301 static unsigned boxAndPoint(
00302 const CollisionBox &box,
00303 const Vector3 &point,
00304 CollisionData *data
00305 );
00306
00307 static unsigned boxAndSphere(
00308 const CollisionBox &box,
00309 const CollisionSphere &sphere,
00310 CollisionData *data
00311 );
00312 };
00313
00314
00315
00316 }
00317
00318 #endif // CYCLONE_COLLISION_FINE_H