00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef _PHYSICS_OBBCOLLISIONDETECTOR_
00026 #define _PHYSICS_OBBCOLLISIONDETECTOR_
00027
00028 #include <physics/physics>
00029 #include <base/array>
00030 #include <physics/CollisionDetector>
00031 #include <physics/OBBCollisionModel>
00032 #include <base/Vector3>
00033 #include <base/Matrix3>
00034 #include <gfx/Triangle3>
00035 #include <vector>
00036
00037
00038 namespace physics {
00039
00040
00041 class OBBCollisionDetector : public CollisionDetector
00042 {
00043 public:
00044 OBBCollisionDetector()
00045 : collisionDetectionEnabled(true) {}
00046
00047 virtual String className() const { return String("OBBCollisionDetector"); }
00048
00049 virtual CollisionModel::CollisionModelType getType() const
00050 { return CollisionModel::OBBModel; }
00051
00052
00053 virtual bool collision(ref<const Solid> solid1, ref<const Solid> solid2, CollisionQueryType queryType);
00054
00055
00056 virtual bool collisionEnable(bool enabled)
00057 {
00058 bool oldEnable = collisionDetectionEnabled;
00059 collisionDetectionEnabled=enabled;
00060 return oldEnable;
00061 }
00062
00063
00064 Int numBoxTests;
00065 Int numTriTests;
00066
00067 protected:
00068 bool collisionDetectionEnabled;
00069
00070 base::Vector3 i1,i2,i3;
00071 base::Matrix3 Bf;
00072 base::Matrix3 mR;
00073 base::Vector3 mT;
00074 Real ms;
00075
00076 std::vector<std::pair<gfx::Triangle3,gfx::Triangle3> > contacts;
00077
00078 bool firstContact;
00079
00080 void Collide(const base::Matrix3& R1, const base::Vector3& T1,
00081 ref<const OBBCollisionModel> model1,
00082 const base::Matrix3& R2, const base::Vector3& T2,
00083 ref<const OBBCollisionModel> model2,
00084 CollisionQueryType queryType);
00085 void Collide(const base::Matrix3& R1, const base::Vector3& T1, Real s1,
00086 ref<const OBBCollisionModel> model1,
00087 const base::Matrix3& R2, const base::Vector3& T2, Real s2,
00088 ref<const OBBCollisionModel> model2,
00089 CollisionQueryType queryType);
00090
00091 void collideRecursive(const OBBCollisionModel::OBB& b1,
00092 const OBBCollisionModel::OBB& b2,
00093 const base::Matrix3& R, const base::Vector3& T, double s);
00094
00095 void triContact(const OBBCollisionModel::OBB& b1, const OBBCollisionModel::OBB& b2);
00096 bool triContact(const base::Vector3& P1, const base::Vector3& P2, const gfx::Vector3& P3,
00097 const base::Point3& Q1, const base::Point3& Q2, const gfx::Point3& Q3);
00098 bool project6(const Vector3& ax,
00099 const Vector3& p1, const Vector3& p2, const Vector3& p3,
00100 const Vector3& q1, const Vector3& q2, const Vector3& q3) const;
00101 Int OBBDisjoint(const base::Matrix3& B, const base::Vector3& T,
00102 const base::Vector3& a, const base::Vector3& b);
00103
00104
00105
00106 class OBBCollisionState : public CollisionState
00107 {
00108 public:
00109 OBBCollisionState(ref<const Solid> solid1, ref<const Solid> solid2)
00110 : CollisionState(solid1, solid2) {}
00111 virtual ~OBBCollisionState() {}
00112
00113 virtual String className() const { return String("OBBCollisionState"); }
00114
00115 };
00116
00117 virtual ref<CollisionState> newCollisionState(ref<const Solid> solid1, ref<const Solid> solid2) const
00118 { return ref<CollisionState>(NewNamedObj("OBBSollisionState") OBBCollisionState(solid1,solid2)); }
00119
00120
00121
00122 base::Vector3 p1, p2, p3, q1, q2, q3, e1, e2, e3, f1, f2, f3,
00123 g1, g2, g3, h1, h2, h3, n1, m1, z,
00124 ef11, ef12, ef13, ef21, ef22, ef23, ef31, ef32, ef33;
00125
00126 };
00127
00128
00129 }
00130
00131 #endif