00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #if !defined(COLLISION_H)
00024 #define COLLISION_H
00025
00026 #include "Maths.h"
00027
00028
00029
00030
00033 class BoundingBox
00034 {
00035 public:
00038 Vector3 min;
00041 Vector3 max;
00042
00043 BoundingBox();
00044 BoundingBox(const Vector3 &min_, const Vector3 &max_);
00045 ~BoundingBox();
00046
00049 Vector3 getCenter() const;
00052 float getRadius() const;
00055 float getSize() const;
00056
00059 bool isPointInBox(const Vector3 & oPoint);
00060 };
00061
00062
00063
00066 class BoundingSphere
00067 {
00068 public:
00071 Vector3 center;
00074 float radius;
00075
00076 BoundingSphere();
00077 BoundingSphere(const Vector3 ¢er_, float radius_);
00078 ~BoundingSphere();
00079
00082 bool hasCollided(const BoundingSphere &other) const;
00083 };
00084
00085
00086
00092 class BoundingVolume
00093 {
00094 public:
00095 BoundingBox box;
00096 BoundingSphere sphere;
00097
00098 BoundingVolume();
00099 ~BoundingVolume();
00100 };
00101
00102
00103
00111 class Plane
00112 {
00113 public:
00114 Vector3 n;
00115 float d;
00116
00117 static float dot(const Plane &p, const Vector3 &pt);
00118
00119 Plane();
00120 Plane(float a_, float b_, float c_, float d_);
00121 Plane(const Vector3 &pt, const Vector3 &normal);
00122 Plane(const Vector3 &pt1, const Vector3 &pt2, const Vector3 &pt3);
00123 ~Plane();
00124
00125 bool operator==(const Plane &rhs) const;
00126 bool operator!=(const Plane &rhs) const;
00127
00131 void fromPointNormal(const Vector3 &pt, const Vector3 &normal);
00132
00136 void fromPoints(const Vector3 &pt1, const Vector3 &pt2, const Vector3 &pt3);
00137 const Vector3 &normal() const;
00138 Vector3 &normal();
00139 void normalize();
00140 void set(float a_, float b_, float c_, float d_);
00141 };
00142
00143
00144
00155 class Frustum
00156 {
00157 public:
00158 enum
00159 {
00160 FRUSTUM_PLANE_LEFT = 0,
00161 FRUSTUM_PLANE_RIGHT = 1,
00162 FRUSTUM_PLANE_BOTTOM = 2,
00163 FRUSTUM_PLANE_TOP = 3,
00164 FRUSTUM_PLANE_NEAR = 4,
00165 FRUSTUM_PLANE_FAR = 5
00166 };
00167
00168 Plane planes[6];
00169
00170 void extractPlanes(const Matrix4 &viewMatrix4, const Matrix4 &projMatrix4);
00171
00172 bool boxInFrustum(const BoundingBox &box) const;
00173 bool pointInFrustum(const Vector3 &point) const;
00174 bool sphereInFrustum(const BoundingSphere &sphere) const;
00175 bool volumeInFrustum(const BoundingVolume &volume) const;
00176 };
00177
00178
00179
00186 class Ray
00187 {
00188 public:
00189 Vector3 origin;
00190 Vector3 direction;
00191
00192 Ray();
00193 Ray(const Vector3 &origin_, const Vector3 &direction_);
00194 ~Ray();
00195
00196 bool hasIntersected(const BoundingSphere &sphere) const;
00197 bool hasIntersected(const BoundingBox &box) const;
00198 bool hasIntersected(const BoundingVolume &volume) const;
00199 bool hasIntersected(const Plane &plane) const;
00200
00205 bool hasIntersected(const Plane &plane, float &t, Vector3 &intersection) const;
00206 };
00207
00208
00209
00210 #endif