00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef __TVECTOR4_H__
00013 #define __TVECTOR4_H__
00014
00015
00016
00017
00018 #include <Definitions.h>
00019
00020 #include <Memory/mmgr.h>
00021 #include <math.h>
00022
00023
00024
00025
00026
00027
00028
00029
00030 template<typename T>
00031 struct TVector4
00032 {
00033
00034
00035
00036 public:
00037 TVector4() {}
00038 TVector4(const T &x, const T &y, const T &z, const T &w) {m_X = x; m_Y = y; m_Z = z; m_W = w;}
00039 TVector4(const TVector4<T> &other) {m_X = other.m_X; m_Y = other.m_Y; m_Z = other.m_Z; m_W = other.m_W;}
00040
00041 const TVector4<T> &operator=(const TVector4<T> &other) {m_X = other.m_X; m_Y = other.m_Y; m_Z = other.m_Z; m_W = other.m_W; return *this;}
00042
00043 const TVector4<T> operator+(const TVector4<T> &other) const {return TVector4<T>(m_X + other.m_X, m_Y + other.m_Y, m_Z + other.m_Z, m_W + other.m_W);}
00044 const TVector4<T> &operator+=(const TVector4<T> &other) {m_X += other.m_X; m_Y += other.m_Y; m_Z += other.m_Z; m_W += other.m_W; return *this;}
00045
00046 const TVector4<T> operator-(const TVector4<T> &other) const {return TVector4<T>(m_X - other.m_X, m_Y - other.m_Y, m_Z - other.m_Z, m_W - other.m_W);}
00047 const TVector4<T> &operator-=(const TVector4<T> &other) {m_X -= other.m_X; m_Y -= other.m_Y; m_Z -= other.m_Z; m_W -= other.m_W; return *this;}
00048
00049 const TVector4<T> operator*(const T &factor) const {return TVector4<T>(m_X * factor, m_Y * factor, m_Z * factor, m_W * factor);}
00050 const TVector4<T> &operator*=(const T &factor) {m_X *= factor; m_Y *= factor; m_Z *= factor; m_W *= factor; return *this;}
00051
00052 const TVector4<T> operator/(const T ") const {return TVector4<T>(m_X / quot, m_Y / quot, m_Z / quot, m_W / quot);}
00053 const TVector4<T> &operator/=(const T ") {m_X /= quot; m_Y /= quot; m_Z /= quot; m_W /= quot; return *this;}
00054
00055 bool operator==(const TVector4<T> &other) {return m_X == other.m_X && m_Y == other.m_Y && m_Z == other.m_Z && m_W == other.m_W;}
00056 bool operator!=(const TVector4<T> &other) {return m_X != other.m_X || m_Y != other.m_Y || m_Z != other.m_Z || m_W != other.m_W;}
00057
00058 T &operator[](const byte &i) {assert(i < 4 && "Error: Invalid index for TVector4::operator[]!");
00059 return *(&m_X + i);}
00060
00061 const T &operator[](const byte &i) const {assert(i < 4 && "Error: Invalid index for TVector4::operator[]!");
00062 return *(&m_X + i);}
00063
00064 void Set(const T &x, const T &y, const T &z, const T &w) {m_X = x; m_Y = y; m_Z = z; m_W = w;}
00065
00066 const float Length() const {return sqrt(m_X * m_X + m_Y * m_Y + m_Z * m_Z + m_W * m_W);}
00067 const float LengthSqr() const {return m_X * m_X + m_Y * m_Y + m_Z * m_Z + m_W * m_W;}
00068
00069 void Normalize() {assert(LengthSqr() && "Error: TVector4::Normalize called for a zero vector!");
00070 float fL = 1 / Length(); m_X *= fL; m_Y *= fL; m_Z *= fL; m_W *= fL;}
00071
00072 const T Dot(const TVector4<T> &other) const {return m_X * other.m_X + m_Y * other.m_Y + m_Z * other.m_Z + m_W * other.m_W;}
00073 const TVector4<T> ElementMultiply(const TVector4<T> &other) const {return TVector4<T>(m_X * other.m_X, m_Y * other.m_Y, m_Z * other.m_Z, m_W * other.m_W);}
00074
00075 void Log(word wTargetLog) const {LOG(wTargetLog, "(%.2f, %.2f, %.2f, %.2f)", m_X, m_Y, m_Z, m_W);}
00076
00077
00078
00079
00080 public:
00081 T m_X, m_Y, m_Z, m_W;
00082 };
00083
00084 typedef TVector4<float> CVector4f;
00085 typedef TVector4<sword> CVector4sw;
00086 typedef TVector4<sdword> CVector4sdw;
00087
00088 #endif