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
00032 #ifndef SALT_PLANE_H
00033 #define SALT_PLANE_H
00034
00035 #include "defines.h"
00036 #include "vector.h"
00037 #include "bounds.h"
00038
00039 namespace salt
00040 {
00041
00043 enum EPlaneSide
00044 {
00045 PLANESIDE_BACK = 0,
00046 PLANESIDE_ONPLANE = 1,
00047 PLANESIDE_FRONT = 2,
00048 PLANESIDE_SPLIT = 3,
00049 PLANESIDE_FORCE_32BIT = 0xffffffff
00050 };
00051
00052
00054 enum EPlane
00055 {
00056 PLANE_XY = 0,
00057 PLANE_XZ = 1,
00058 PLANE_YZ = 2,
00059 PLANE_FORCE_32BIT = 0xffffffff
00060 };
00061
00062
00071 class Plane
00072 {
00073
00074 public:
00076 Vector3f normal;
00077
00079 float d;
00080
00081
00082 public:
00084 f_inline Plane() {}
00085
00087 f_inline Plane(const Vector3f& norm, const Vector3f& pnt) { normal=norm; d=-((norm.x()*pnt.x()) + (norm.y()*pnt.y()) + (norm.z()*pnt.z())); }
00088
00092 f_inline Plane(const Vector3f& norm, const float D) { normal=norm; d=D; }
00093
00095 f_inline Plane(const Vector3f& v1, const Vector3f &v2, const Vector3f &v3) { normal=(v2-v1).Cross(v3-v1).Normalized(); d=-normal.Dot(v1); }
00096
00097
00098
00100 f_inline EPlaneSide GetOrientation(const Vector3f &v, float delta=0.0001f) const { float dist=normal.Dot(v)+d; if (dist<-delta) return PLANESIDE_BACK; if (dist>delta) return PLANESIDE_FRONT; return PLANESIDE_ONPLANE; }
00101
00103 f_inline EPlane GetDominantPlane() const { return (gAbs(normal.y()) > gAbs(normal.x()) ? (gAbs(normal.z()) > gAbs(normal.y()) ? PLANE_XY : PLANE_XZ) : (gAbs(normal.z()) > gAbs(normal.x()) ? PLANE_XY : PLANE_YZ)); }
00104
00106 f_inline float GetDistanceTo(const Vector3f &v) const
00107 { return normal.Dot(v) + d; }
00108
00109
00111 EPlaneSide ClassifyBox(const AABB3& bb) const;
00112
00114 void Normalize();
00115
00117 f_inline void Set(const Vector3f& norm, const Vector3f& pnt)
00118 { normal=norm; d=-((norm.x()*pnt.x()) + (norm.y()*pnt.y()) + (norm.z()*pnt.z())); }
00119
00123 f_inline void Set(const Vector3f& norm, const float D) { normal=norm; d=D; }
00124
00126 f_inline void Set(const Vector3f& v1, const Vector3f &v2, const Vector3f &v3) { normal=(v2-v1).Cross(v3-v1).Normalized(); d=-normal.Dot(v1); }
00127
00129 f_inline const Plane& operator=(const Plane& p)
00130 { normal=p.normal; d=p.d; return *this; }
00131
00132 };
00133
00134 }
00135
00136 #endif //SALT_PLANE_H