00001
00002
00003
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef TA_VEC2_H
00014 #define TA_VEC2_H
00015
00016 #ifndef TA_MATHS_H
00017 #include "Maths.h"
00018 #endif // TA_MATHS_H
00019
00020 TA_OBFUSCATION_SKIP_PASS_2
00021
00022 namespace TA
00023 {
00024
00026
00027
00028
00029
00030
00031 struct TACOMMON_CLASS Vec2
00032 {
00033 TA_OBFUSCATION_RESERVED_ON
00034
00035
00036 float x;
00037 float y;
00038
00039 enum Axis
00040 {
00041 AXIS_X = 0,
00042 AXIS_Y,
00043 };
00044
00046
00047 Vec2() {};
00048
00049 Vec2(const Vec2& v2Value) { x = v2Value.x; y = v2Value.y; }
00050 Vec2(float fX, float fY) { x = fX; y = fY; }
00051
00052 void Initialise(float fX, float fY) { x = fX; y = fY; }
00054
00056
00057 operator float* () { return (float*)&x; }
00058 operator const float* () const { return (float*)&x; }
00060
00062
00063 float& operator [] (int nIndex) { return ((float*)&x)[nIndex]; }
00064 const float& operator [] (int nIndex) const { return ((float*)&x)[nIndex]; }
00066
00068
00069 Vec2& operator += (const Vec2& v2Value) { x += v2Value.x; y += v2Value.y; return *this; }
00070 Vec2& operator -= (const Vec2& v2Value) { x -= v2Value.x; y -= v2Value.y; return *this; }
00071 Vec2& operator *= (float fValue) { x *= fValue; y *= fValue; return *this; }
00072 Vec2& operator /= (float fValue) { float fDiv = 1.0f / fValue; x *= fDiv; y *= fDiv; return *this; }
00074
00076
00077 Vec2 operator + () const { return *this; };
00078 Vec2 operator - () const { Vec2 v2ReturnValue(-x, -y); return v2ReturnValue; };
00079
00081
00082 Vec2 operator + (const Vec2& v2Value) const { Vec2 v2ReturnValue(x + v2Value.x, y + v2Value.y); return v2ReturnValue; }
00083 Vec2 operator - (const Vec2& v2Value) const { Vec2 v2ReturnValue(x - v2Value.x, y - v2Value.y); return v2ReturnValue; }
00084 Vec2 operator * (float fValue) const { Vec2 v2ReturnValue(x * fValue, y * fValue); return v2ReturnValue; }
00085 Vec2 operator / (float fValue) const { float fDiv = 1.0f / fValue; Vec2 v2ReturnValue(x * fDiv, y * fDiv); return v2ReturnValue; }
00087
00088 friend Vec2 operator * (float fValue, const Vec2& v2Value);
00089
00091
00092 bool operator == (const Vec2& v2Value) const { return x == v2Value.x && y == v2Value.y; }
00093 bool operator != (const Vec2& v2Value) const { return x != v2Value.x || y != v2Value.y; }
00095
00096
00097 static inline float TAC_CALL Dot(const Vec2& v2A, const Vec2& v2B)
00098 {
00099 return v2A.x * v2B.x + v2A.y * v2B.y;
00100 }
00101 inline float Dot(const Vec2& v2Value) const { return Dot(*this, v2Value); }
00102
00103 static inline float TAC_CALL GetMagnitude(const Vec2& v2Value) { return v2Value.GetMagnitude(); }
00104 inline float GetMagnitude() const { return Sqrt(x * x + y * y); }
00105 static inline float TAC_CALL GetMagnitudeSqrd(const Vec2& v2Value) { return v2Value.GetMagnitudeSqrd(); }
00106 inline float GetMagnitudeSqrd() const { return x * x + y * y; }
00107 static inline Vec2 TAC_CALL GetNormal(const Vec2& v2Value) { return v2Value.GetNormal(); }
00108 inline Vec2 GetNormal() const { return (*this) * ReciprocalSqrt(GetMagnitudeSqrd()); }
00109 inline void Normalise() { (*this) *= ReciprocalSqrt(GetMagnitudeSqrd()); }
00110 inline void Clear() { x = 0.0f; y = 0.0f; }
00111 inline bool IsNormalised() const { return IsEqualToOneWithInError(GetMagnitudeSqrd()); }
00112 inline bool IsZero() const { return GetMagnitudeSqrd() == 0.0f; }
00113 inline void GetAxisOrder(int pnAxisOrder[2]) const;
00114 inline float GetAxis(int nIndex) const { return (*this)[nIndex]; }
00115 static inline const Vec2& TAC_CALL GetUnitVector(int nIndex);
00116
00117
00118 TA_OBFUSCATION_RESERVED_OFF
00119 };
00120
00121 TA_OBFUSCATION_RESERVED_FULL_ON
00122 const Vec2 k_v2Zero(0.0f, 0.0f);
00123 const Vec2 k_v2UnitX(1.0f, 0.0f);
00124 const Vec2 k_v2UnitY(0.0f, 1.0f);
00125 TA_OBFUSCATION_RESERVED_FULL_OFF
00126
00128
00129 }
00130 #include "Vec2.inl"
00131
00132 #endif // TA_VEC2_H
© Copyright 2004-2006 TRUE AXIS PTY LTD Australia. All rights reserved.