00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef _point4_h
00018 #define _point4_h
00019
00020 #include <spl/types.h>
00021 #include <spl/Debug.h>
00022 #include <spl/math/Math.h>
00023 #include <spl/Memory.h>
00024
00030 template<typename T, typename FLOATTYPE> class Vector3;
00031 template<typename T, typename FLOATTYPE> class Vector4;
00032
00034 template<typename T, typename FLOATTYPE>
00035 class Point3 : public IMemoryValidate
00036 {
00037 protected:
00038 T m_x, m_y, m_z;
00039
00040 public:
00041 Point3()
00042 : m_x(0), m_y(0), m_z(0)
00043 {
00044 }
00045
00046 Point3(T x)
00047 : m_x(x), m_y(0), m_z(0)
00048 {
00049 }
00050
00051 Point3(T x, T y)
00052 : m_x(x), m_y(y), m_z(0)
00053 {
00054 }
00055
00056 Point3(T x, T y, T z)
00057 : m_x(x), m_y(y), m_z(z)
00058 {
00059 }
00060
00061 Point3(const Point3<T, FLOATTYPE>& pt)
00062 : m_x(pt.m_x), m_y(pt.m_y), m_z(pt.m_z)
00063 {
00064 }
00065
00066 inline Point3<T, FLOATTYPE>& operator=(const Point3<T, FLOATTYPE>& pt)
00067 {
00068 m_x = pt.m_x;
00069 m_y = pt.m_y;
00070 m_z = pt.m_z;
00071
00072 return *this;
00073 }
00074
00075 inline T X() { return m_x; }
00076 inline T Y() { return m_y; }
00077 inline T Z() { return m_z; }
00078
00079
00080 Vector3<T,FLOATTYPE> operator -(Point3<T,FLOATTYPE>& pt)
00081 {
00082 return Vector3<T,FLOATTYPE>(m_x - pt.m_x, m_y - pt.m_y, m_z - pt.m_z);
00083 }
00084
00085 Point3<T,FLOATTYPE> operator +(Vector3<T,FLOATTYPE>& v)
00086 {
00087 return Point3<T,FLOATTYPE>(m_x + pt.m_x, m_y + pt.m_y, m_z + pt.m_z);
00088 }
00089
00090 Point3<T,FLOATTYPE> operator -(Vector3<T,FLOATTYPE>& v)
00091 {
00092 return Point3<T,FLOATTYPE>(m_x - v.m_x, m_y - v.m_y, m_z - v.m_z);
00093 }
00094
00095 Point3<T,FLOATTYPE>& operator +=(Vector3<T,FLOATTYPE>& v)
00096 {
00097 m_x += v.m_x;
00098 m_y += v.m_y;
00099 m_z += v.m_z;
00100 return *this;
00101 }
00102
00103 Point3<T,FLOATTYPE>& operator -=(Vector3<T,FLOATTYPE>& v)
00104 {
00105 m_x -= v.m_x;
00106 m_y -= v.m_y;
00107 m_z -= v.m_z;
00108 return *this;
00109 }
00110
00111 inline bool IsEqual(Point3<T,FLOATTYPE> *pt)
00112 {
00113 return m_x == pt->m_x && m_y == pt->m_y && m_z == pt->m_z;
00114 }
00115
00116 bool operator ==(Point3<T,FLOATTYPE>& pt)
00117 {
00118 return IsEqual(pt)
00119 }
00120
00121 bool operator !=(Point3<T,FLOATTYPE>& pt)
00122 {
00123 return !IsEqual(pt);
00124 }
00125
00127 static FLOATTYPE Distance( Point3<T,FLOATTYPE> *p, Point3<T,FLOATTYPE> *q )
00128 {
00129 FLOATTYPE dx = p->m_x - q->m_x;
00130 FLOATTYPE dy = p->m_y - q->m_y;
00131 FLOATTYPE dz = p->m_z - q->m_z;
00132 return FastMath::Sqrt(dx*dx + dy*dy + dz*dz);
00133 }
00134
00136 FLOATTYPE IsLeft( Point3<T,FLOATTYPE> *p1, Point3<T,FLOATTYPE> *p2)
00137 {
00138 return ((p1->m_x - m_x) * (p2->m_y - m_y) - (p2->m_x - m_x) * (p1->m_y - m_y));
00139 }
00140
00141 virtual void ValidateMem() const
00142 {
00143 }
00144
00145 virtual void CheckMem() const
00146 {
00147 }
00148 };
00149
00151 template<typename T, typename FLOATTYPE>
00152 class Point4 : public IMemoryValidate
00153 {
00154 protected:
00155 T m_x, m_y, m_z, m_w;
00156
00157 public:
00158 Point4()
00159 : m_x(0), m_y(0), m_z(0), m_w(0)
00160 {
00161 }
00162
00163 Point4(T x)
00164 : m_x(x), m_y(0), m_z(0), m_w(0)
00165 {
00166 }
00167
00168 Point4(T x, T y)
00169 : m_x(x), m_y(y), m_z(0), m_w(0)
00170 {
00171 }
00172
00173 Point4(T x, T y, T z)
00174 : m_x(x), m_y(y), m_z(z), m_w(0)
00175 {
00176 }
00177
00178 Point4(T x, T y, T z, T w)
00179 : m_x(x), m_y(y), m_z(z), m_w(w)
00180 {
00181 }
00182
00183 Point4(const Point4<T, FLOATTYPE>& pt)
00184 : m_x(pt.m_x), m_y(pt.m_y), m_z(pt.m_z), m_w(pt.m_w)
00185 {
00186 }
00187
00188 inline Point4<T, FLOATTYPE>& operator =(const Point4<T, FLOATTYPE>& pt)
00189 {
00190 m_x = pt.m_x;
00191 m_y = pt.m_y;
00192 m_z = pt.m_z;
00193 m_w = pt.m_w;
00194
00195 return *this;
00196 }
00197
00198 inline T X() { return m_x; }
00199 inline T Y() { return m_y; }
00200 inline T Z() { return m_z; }
00201 inline T W() { return m_w; }
00202
00203
00204 Vector4<T,FLOATTYPE> operator -(Point4<T,FLOATTYPE>& pt)
00205 {
00206 return Vector4<T,FLOATTYPE>(m_x - pt.m_x, m_y - pt.m_y, m_z - pt.m_z, m_w - pt.m_w);
00207 }
00208
00209 Point4<T,FLOATTYPE> operator +(Vector4<T,FLOATTYPE>& v)
00210 {
00211 return Point4<T,FLOATTYPE>(m_x + pt.m_x, m_y + pt.m_y, m_z + pt.m_z, m_w + pt.m_w);
00212 }
00213
00214 Point4<T,FLOATTYPE> operator -(Vector4<T,FLOATTYPE>& v)
00215 {
00216 return Point4<T,FLOATTYPE>(m_x - v.m_x, m_y - v.m_y, m_z - v.m_z, m_w - v.m_w);
00217 }
00218
00219 Point4<T,FLOATTYPE>& operator +=(Vector4<T,FLOATTYPE>& v)
00220 {
00221 m_x += v.m_x;
00222 m_y += v.m_y;
00223 m_z += v.m_z;
00224 m_w += v.m_w;
00225 return *this;
00226 }
00227
00228 Point4<T,FLOATTYPE>& operator -=(Vector4<T,FLOATTYPE>& v)
00229 {
00230 m_x -= v.m_x;
00231 m_y -= v.m_y;
00232 m_z -= v.m_z;
00233 m_w -= v.m_w;
00234 return *this;
00235 }
00236
00237 inline bool IsEqual(Point4<T,FLOATTYPE> *pt)
00238 {
00239 return m_x == pt->m_x && m_y == pt->m_y && m_z == pt->m_z && m_w == pt->m_w;
00240 }
00241
00242 bool operator ==(Point4<T,FLOATTYPE>& pt)
00243 {
00244 return IsEqual(pt)
00245 }
00246
00247 bool operator !=(Point4<T,FLOATTYPE>& pt)
00248 {
00249 return !IsEqual(pt);
00250 }
00251
00253 static FLOATTYPE Distance( Point4<T,FLOATTYPE> *p, Point4<T,FLOATTYPE> *q )
00254 {
00255 FLOATTYPE dx = p->m_x - q->m_x;
00256 FLOATTYPE dy = p->m_y - q->m_y;
00257 FLOATTYPE dz = p->m_z - q->m_z;
00258 return FastMath::Sqrt(dx*dx + dy*dy + dz*dz);
00259 }
00260
00262 FLOATTYPE IsLeft( Point4<T,FLOATTYPE> *p1, Point4<T,FLOATTYPE> *p2)
00263 {
00264 return ((p1->m_x - m_x) * (p2->m_y - m_y) - (p2->m_x - m_x) * (p1->m_y - m_y));
00265 }
00266
00267 virtual void ValidateMem() const
00268 {
00269 }
00270
00271 virtual void CheckMem() const
00272 {
00273 }
00274 };
00275
00276 #include <spl/math/Vector.h>
00277
00280 #endif