True Axis Physics SDK 1.2.0.1 Beta Documentation
www.trueaxis.com

Vec4.h

Go to the documentation of this file.
00001 //---------------------------------------------------------------------------------
00002 // File Name: Vec4.h
00003 // Description:
00006 //
00007 // Copyright (C) 2004 - 2006 True Axis Pty Ltd, Australia. 
00008 // All Rights Reserved.
00009 //
00010 // History:
00011 //---------------------------------------------------------------------------------
00012 
00013 #ifndef TA_VEC4_H
00014 #define TA_VEC4_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 #define TA_VEC4_CALL TA_FAST_CALL
00023 
00024 namespace TA
00025 {
00026 
00028 
00029 
00030 //---------------------------------------------------------------------------------
00031 //---------------------------------------------------------------------------------
00032 TA_ALIGN_16 struct TACOMMON_CLASS Vec4
00033 {   
00034     // No hungarian notation here for ease of use.
00035     float x;
00036     float y;
00037     float z;
00038     float w;
00039 
00040 TA_OBFUSCATION_RESERVED_ON
00041     enum Axis
00042     {
00043         AXIS_X = 0,
00044         AXIS_Y,
00045         AXIS_Z,
00046         AXIS_W,
00047     };
00048 
00050 
00051     Vec4() {};
00052     Vec4(const Vec4& v4Value) { x = v4Value.x; y = v4Value.y; z = v4Value.z;  w = v4Value.w; }
00053     Vec4(float fX, float fY, float fZ, float fW) { x = fX; y = fY; z = fZ; w = fW; }
00054 
00055     void Initialise(float fX, float fY, float fZ, float fW) { x = fX; y = fY; z = fZ; w = fW; }
00057 
00059 
00060     operator float* () { return (float*)&x; }
00061     operator const float* () const { return (float*)&x; }
00063 
00065 
00066     float& operator [] (int nIndex) { return ((float*)&x)[nIndex]; }
00067     const float& operator [] (int nIndex) const { return ((float*)&x)[nIndex]; }
00069 
00071 
00072     Vec4& operator += (const Vec4& v4Value) { x += v4Value.x; y += v4Value.y; z += v4Value.z;  w += v4Value.w; return *this; }
00073     Vec4& operator -= (const Vec4& v4Value) { x -= v4Value.x; y -= v4Value.y; z -= v4Value.z;  w += v4Value.w; return *this; }
00074     Vec4& operator *= (float fValue) { x *= fValue; y *= fValue; z *= fValue; w *= fValue; return *this; }
00075     Vec4& operator /= (float fValue) { float fDiv = 1.0f / fValue; x *= fDiv; y *= fDiv; z *= fDiv; w *= fDiv; return *this; }
00077 
00079 
00080     Vec4 operator + () const { return *this; };
00081     Vec4 operator - () const { Vec4 v4ReturnValue(-x, -y, -z, -w); return v4ReturnValue; };
00083 
00085 
00086     Vec4 operator + (const Vec4& v4Value) const { Vec4 v4ReturnValue(x + v4Value.x, y + v4Value.y, z + v4Value.z, w + v4Value.w); return v4ReturnValue; }
00087     Vec4 operator - (const Vec4& v4Value) const { Vec4 v4ReturnValue(x - v4Value.x, y - v4Value.y, z - v4Value.z, w - v4Value.w); return v4ReturnValue; }
00088     Vec4 operator * (float fValue) const { Vec4 v4ReturnValue(x * fValue, y * fValue, z * fValue, w * fValue); return v4ReturnValue; }
00089     Vec4 operator / (float fValue) const { float fDiv = 1.0f / fValue; Vec4 v4ReturnValue(x * fDiv, y * fDiv, z * fDiv, w * fDiv); return v4ReturnValue; }
00091 
00092     friend Vec4 TA_VEC4_CALL operator * (float fValue, const Vec4& v4Value);
00093 
00095 
00096     bool operator == (const Vec4& v4Value) const { return x == v4Value.x && y == v4Value.y && z == v4Value.z && w == v4Value.w; }
00097     bool operator != (const Vec4& v4Value) const { return x != v4Value.x || y != v4Value.y || z != v4Value.z || w != v4Value.w; }
00099 
00100     // cross product (Does this make scene for a vec 4)
00101     static inline Vec4 TAC_CALL Cross(const Vec4& v4A, const Vec4& v4B)
00102     {
00103         Vec4 v4ReturnValue;
00104         v4ReturnValue.x = v4A.y * v4B.z - v4A.z * v4B.y;
00105         v4ReturnValue.y = v4A.z * v4B.x - v4A.x * v4B.z;
00106         v4ReturnValue.z = v4A.x * v4B.y - v4A.y * v4B.x;
00107         v4ReturnValue.w = 1.0f;
00108         return v4ReturnValue;
00109     }
00110     inline Vec4 Cross(const Vec4& v4Value) const { return Cross(*this, v4Value); }
00111 
00112     // dot product
00113     static inline float TA_VEC4_CALL Dot(const Vec4& v4A, const Vec4& v4B)
00114     {
00115         return v4A.x * v4B.x + v4A.y * v4B.y + v4A.z * v4B.z + v4A.w * v4B.w;
00116     }
00117     inline float Dot(const Vec4& v4Value) const { return Dot(*this, v4Value); }
00118 
00119     static inline float TA_VEC4_CALL GetMagnitude(const Vec4& v4Value) { return v4Value.GetMagnitude(); }
00120     inline float GetMagnitude() const { return Sqrt(x * x + y * y + z * z + w * w); }
00121     static inline float TA_VEC4_CALL GetMagnitudeSqrd(const Vec4& v4Value) { return v4Value.GetMagnitudeSqrd(); }
00122     inline float GetMagnitudeSqrd() const { return x * x + y * y + z * z + w * w; }
00123     static inline Vec4 TA_VEC4_CALL GetNormal(const Vec4& v4Value) { return v4Value.GetNormal(); }
00124     inline Vec4 GetNormal() const { return (*this) * ReciprocalSqrt(GetMagnitudeSqrd()); }
00125     inline void Normalise() { (*this) *= ReciprocalSqrt(GetMagnitudeSqrd()); }
00126     inline void Clear() { x = 0.0f; y = 0.0f; z = 0.0f; w = 0.0f; }
00127     inline bool IsNormalised() const { return IsEqualToOneWithInError(GetMagnitudeSqrd()); }
00128     inline bool IsZero() const { return GetMagnitudeSqrd() == 0.0f; }
00129     inline void GetAxisOrder(int pnAxisOrder[4]) const; // Axis order from biggest to smallest
00130     inline float GetAxis(int nIndex) const { return (*this)[nIndex]; }
00131     static inline const Vec4& TA_VEC4_CALL GetUnitVector(int nIndex);
00132     //inline void IsEqualWithInError()
00133 
00134 TA_OBFUSCATION_RESERVED_OFF
00135 };
00136 
00137 TA_OBFUSCATION_RESERVED_FULL_ON
00138 const Vec4 k_v4Zero(0.0f, 0.0f, 0.0f, 0.0f);
00139 const Vec4 k_v4UnitX(1.0f, 0.0f, 0.0f, 0.0f);
00140 const Vec4 k_v4UnitY(0.0f, 1.0f, 0.0f, 0.0f);
00141 const Vec4 k_v4UnitZ(0.0f, 0.0f, 1.0f, 0.0f);
00142 const Vec4 k_v4UnitW(0.0f, 0.0f, 0.0f, 1.0f);
00143 TA_OBFUSCATION_RESERVED_FULL_OFF
00145 
00146 }
00147 
00148 #include "Vec4.inl"
00149 
00150 #endif // TA_VEC4_H


© Copyright 2004-2006 TRUE AXIS PTY LTD Australia. All rights reserved.