00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef __TAABox3_H__
00011 #define __TAABox3_H__
00012
00013
00014
00015
00016 #include <Definitions.h>
00017
00018 #include <Memory/mmgr.h>
00019 #include "TVector3.h"
00020 #include "TBox3.h"
00021
00022
00023
00024
00025
00026
00027
00028
00029 template<typename T>
00030 class TAABox3
00031 {
00032
00033
00034
00035 public:
00036 TAABox3() {}
00037 TAABox3(const T &minX, const T &minY, const T &minZ,
00038 const T &maxX, const T &maxY, const T &maxZ) : m_MinX(minX), m_MinY(minY), m_MinZ(minZ),
00039 m_MaxX(maxX), m_MaxY(maxY), m_MaxZ(maxZ) {}
00040 TAABox3<T>(const TAABox3<T> &other) : m_MinX(other.m_MinX), m_MinY(other.m_MinY), m_MinZ(other.m_MinZ),
00041 m_MaxX(other.m_MaxX), m_MaxY(other.m_MaxY), m_MaxZ(other.m_MaxZ) {}
00042 const TAABox3<T> &operator =(const TAABox3<T> &other) {m_MinX = other.m_MinX; m_MinY = other.m_MinY; m_MinZ = other.m_MinZ;
00043 m_MaxX = other.m_MaxX; m_MaxY = other.m_MaxY; m_MaxZ = other.m_MaxZ; return *this;}
00044
00045 const TAABox3<T> operator+(const TVector3<T> &vec) const {return TAABox3<T>(m_MinX + vec.m_X, m_MinY + vec.m_Y, m_MinZ + vec.m_Z,
00046 m_MaxX + vec.m_X, m_MaxY + vec.m_Y, m_MaxZ + vec.m_Z);}
00047 const TAABox3<T> &operator+=(const TVector3<T> &vec) {m_MinX += vec.m_X; m_MaxX += vec.m_X; m_MinY += vec.m_Y; m_MaxY += vec.m_Y;
00048 m_MinZ += vec.m_Z; m_MaxZ += vec.m_Z; return *this;}
00049
00050 const TAABox3<T> operator*(const TVector3<T> &vec) const {return TAABox3<T>(m_MinX * vec.m_X, m_MinY * vec.m_Y, m_MinZ * vec.m_Z,
00051 m_MaxX * vec.m_X, m_MaxY * vec.m_Y, m_MaxZ * vec.m_Z);}
00052 const TAABox3<T> &operator*=(const TVector3<T> &vec) {m_MinX *= vec.m_X; m_MaxX *= vec.m_X; m_MinY *= vec.m_Y; m_MaxY *= vec.m_Y;
00053 m_MinZ *= vec.m_Z; m_MaxZ *= vec.m_Z; return *this;}
00054 const CBox3f GetRotatedBox(const CVector3f &vRotation) const;
00055
00056 void SetSafePointWidth(const T &x, const T &y, const T &z,
00057 const T &xWidth, const T &yWidth, const T &zWidth);
00058 void SetSafePointPoint(const T &x1, const T &y1, const T &z1,
00059 const T &x2, const T &y2, const T &z2);
00060
00061 T SizeX() const {return m_MaxX - m_MinX;}
00062 T SizeY() const {return m_MaxY - m_MinY;}
00063 T SizeZ() const {return m_MaxZ - m_MinZ;}
00064 const TVector3<T> Size() const {return TVector3<T>(m_MaxX - m_MinX, m_MaxY - m_MinY, m_MaxZ - m_MinZ);}
00065 const TVector3<T> Center() const {return TVector3<T>((m_MaxX + m_MinX) / 2.0f, (m_MaxY + m_MinY) / 2.0f, (m_MaxZ + m_MinZ) / 2.0f);}
00066
00067
00068
00069
00070
00071
00072
00073 protected:
00074
00075
00076
00077
00078 private:
00079
00080
00081
00082
00083 public:
00084 T m_MinX, m_MinY, m_MinZ,
00085 m_MaxX, m_MaxY, m_MaxZ;
00086 };
00087
00088
00089 template<typename T>
00090 const CBox3f TAABox3<T>::GetRotatedBox(const CVector3f &vRotation) const
00091 {
00092 CMatrix44 mat;
00093 mat.RotationZXY(vRotation);
00094
00095 return CBox3f(mat * CVector3f(m_MinX, m_MinY, m_MinZ), mat * CVector3f(m_MaxX - m_MinX, 0.0f, 0.0f),
00096 mat * CVector3f(0.0f, m_MaxY - m_MinY, 0.0f), mat * CVector3f(0.0f, 0.0f, m_MaxZ - m_MinZ));
00097 }
00098
00099 template<typename T>
00100 void TAABox3<T>::SetSafePointWidth(const T &x, const T &y, const T &z,
00101 const T &xWidth, const T &yWidth, const T &zWidth)
00102 {
00103 if(xWidth >= 0)
00104 {
00105 m_MinX = x;
00106 m_MaxX = x + xWidth;
00107 }
00108 else
00109 {
00110 m_MaxX = x;
00111 m_MinX = x + xWidth;
00112 }
00113
00114 if(yWidth >= 0)
00115 {
00116 m_MinY = y;
00117 m_MaxY = y + yWidth;
00118 }
00119 else
00120 {
00121 m_MaxY = y;
00122 m_MinY = y + yWidth;
00123 }
00124
00125 if(zWidth >= 0)
00126 {
00127 m_MinZ = z;
00128 m_MaxZ = z + zWidth;
00129 }
00130 else
00131 {
00132 m_MaxZ = z;
00133 m_MinZ = z + zWidth;
00134 }
00135 }
00136
00137 template<typename T>
00138 void TAABox3<T>::SetSafePointPoint(const T &x1, const T &y1, const T &z1,
00139 const T &x2, const T &y2, const T &z2)
00140 {
00141 if(x2 >= x1)
00142 {
00143 m_MinX = x1;
00144 m_MaxX = x2;
00145 }
00146 else
00147 {
00148 m_MaxX = x1;
00149 m_MinX = x2;
00150 }
00151
00152 if(y2 >= y1)
00153 {
00154 m_MinY = y1;
00155 m_MaxY = y2;
00156 }
00157 else
00158 {
00159 m_MaxY = y1;
00160 m_MinY = y2;
00161 }
00162
00163 if(z2 >= z1)
00164 {
00165 m_MinZ = z1;
00166 m_MaxZ = z2;
00167 }
00168 else
00169 {
00170 m_MaxZ = z1;
00171 m_MinZ = z2;
00172 }
00173 }
00174
00175 typedef TAABox3<float> CAABox3f;
00176
00177 #endif