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
00026
00027
00028
00029
00030
00031
00036 class PG_API pgCdt
00037 {
00038 public:
00042 class PG_API AABB
00043 {
00044 friend class pgCdt;
00045
00046 public:
00047 pgDefineException(ExceptionInvalidArgument);
00048
00049 const pgVec& getMin() const;
00050 const pgVec& getMax() const;
00051 void setBound(const pgVec& min, const pgVec& max);
00052
00053 private:
00054 pgVec m_min;
00055 pgVec m_max;
00056 };
00057
00061 class PG_API Sph
00062 {
00063 friend class pgCdt;
00064
00065 public:
00066 pgDefineException(ExceptionInvalidArgument);
00067
00068 Sph();
00069
00070 const AABB& getAABB() const;
00071
00072 const pgVec& getPos() const;
00073 void setPos(const pgVec& pos);
00074
00075 r32 getRadius() const;
00076 void setRadius(r32 radius);
00077
00078 private:
00079 void updateAABB();
00080
00081 AABB m_aabb;
00082 pgVec m_pos;
00083 r32 m_radius;
00084 };
00085
00089 class PG_API Box
00090 {
00091 friend class pgCdt;
00092
00093 public:
00094 pgDefineException(ExceptionInvalidArgument);
00095
00096 Box();
00097
00098 const AABB& getAABB() const;
00099
00100 const pgMat& getWorld() const;
00101 void setWorld(const pgMat& world);
00102
00103 r32 getWidth() const;
00104 r32 getHeight() const;
00105 r32 getDepth() const;
00106 const pgVec& getHalfSize() const;
00107 void setSize(r32 width, r32 height, r32 depth);
00108
00109 private:
00110 void updateAABB();
00111
00112 AABB m_aabb;
00113 pgMat m_world;
00114 pgVec m_half_size;
00115 };
00116
00120 class PG_API Tri
00121 {
00122 friend class pgCdt;
00123
00124 public:
00125 Tri();
00126
00127 const AABB& getAABB() const;
00128
00129 const pgVec& getPos1() const;
00130 const pgVec& getPos2() const;
00131 const pgVec& getPos3() const;
00132 void setPos(const pgVec& pos1, const pgVec& pos2, const pgVec& pos3);
00133
00134 private:
00135 void updateAABB();
00136
00137 AABB m_aabb;
00138 pgVec m_pos1;
00139 pgVec m_pos2;
00140 pgVec m_pos3;
00141 };
00142
00146 class PG_API Ray
00147 {
00148 friend class pgCdt;
00149
00150 public:
00151 Ray();
00152
00153 const AABB& getAABB() const;
00154
00155 const pgVec& getFrom() const;
00156 const pgVec& getTo() const;
00157 void setPos(const pgVec& from, const pgVec& to);
00158
00159 private:
00160 void updateAABB();
00161
00162 AABB m_aabb;
00163 pgVec m_from;
00164 pgVec m_to;
00165 };
00166
00170 struct CdtInfo
00171 {
00172 pgVec pos;
00173 pgVec back_dir;
00174 r32 back_dist;
00175 };
00176
00177 static bool checkTouch(const AABB& aabb1, const AABB& aabb2);
00178
00179 static bool collide(CdtInfo* cdt_info, const Sph& sph1, const Sph& sph2);
00180 static bool collide(CdtInfo* cdt_info, const Sph& sph, const Box& box);
00181 static bool collide(CdtInfo* cdt_info, const Sph& sph, const Tri& tri);
00182
00183 static bool collide(CdtInfo* cdt_info, const Box& box1, const Box& box2);
00184 static bool collide(CdtInfo* cdt_info, const Box& box, const Sph& sph);
00185 static bool collide(CdtInfo* cdt_info, const Box& box, const Tri& tri);
00186
00187 static bool intersect(pgVec* pos, const Ray& ray, const Sph& sph);
00188 static bool intersect(pgVec* pos, const Ray& ray, const Box& box);
00189 static bool intersect(pgVec* pos, const Ray& ray, const Tri& tri);
00190
00191 private:
00192 static bool intersectLocalBox(r32* min_dist, r32* max_dist, const pgVec& local_ray_pos, const pgVec& local_ray_dir, const pgVec& box_half_size);
00193 static bool intersectTri(r32* dist, const pgVec& ray_pos, const pgVec& ray_dir, const Tri& tri);
00194 };