#ifndef __VECTOR4D__ #define __VECTOR4D__ #include "Math.h" namespace LifeMath { #undef INLINE #ifdef _WIN32 #ifdef _MSC_VER #define INLINE __forceinline #endif #else #ifdef __GNUC__ #define INLINE __attribute__((always_inline)) #endif #endif #ifndef INLINE #define INLINE inline #endif // struct Vector4D; // struct Vector4D; template struct Vector4D { public: T X, Y, Z, W; INLINE Vector4D(T x, T y, T z, T w) { this->X = x; this->Y = y; this->Z = z; this->W = w; } INLINE Vector4D(void) { this->X = 0; this->Y = 0; this->Z = 0; this->W = 0; } INLINE Vector4D(T val) { this->X = val; this->Y = val; this->Z = val; this->W = val; } //unary operators INLINE Vector4D operator -() const { return Vector4D(-X, -Y, -Z, -W); } INLINE Vector4D operator +() const { return *this; } INLINE Vector4D& operator=(const Vector4D& other) { X = other.X; Y = other.Y; Z = other.Z; W = other.W; return *this; } //binary operators INLINE Vector4D operator +(const Vector4D &other) const { return Vector4D(X + other.X, Y + other.Y, Z + other.Z, W + other.W); } INLINE Vector4D operator -(const Vector4D &other) const { return Vector4D(X - other.X, Y - other.Y, Z - other.Z, W - other.W); } INLINE Vector4D operator *(T other) const { return Vector4D(X * other, Y * other, Z * other, W * other); } INLINE Vector4D operator /(T other) const { return Vector4D(X / other, Y / other, Z / other, W / other); } INLINE operator T * () { return &X; } INLINE operator const T * () const { return &X; } INLINE bool operator == (const Vector4D& vector) const { return (X == vector.X && Y == vector.Y && Z == vector.Z && W == vector.W); } INLINE bool operator != (const Vector4D& vector) const { return (X != vector.X || Y != vector.Y || Z != vector.Z || W != vector.W); } INLINE Vector4D& operator += (const Vector4D& Vector) { X += Vector.X; Y += Vector.Y; Z += Vector.Z; W += Vector.W; return *this; } INLINE Vector4D& operator -= (const Vector4D& Vector) { X -= Vector.X; Y -= Vector.Y; Z -= Vector.Z; W -= Vector.W; return *this; } INLINE Vector4D& operator *= (T Value) { X *= Value; Y *= Value; Z *= Value; W *= Value; return *this; } INLINE Vector4D& operator /= (T Value) { //assert(Value && "Zero Value"); *this *= (1.0f / Value); return *this; } INLINE Vector4D& operator += (T Value) { X += Value; Y += Value; Z += Value; W += Value; return *this; } INLINE Vector4D& operator -= (T Value) { X -= Value; Y -= Value; Z -= Value; W -= Value; return *this; } INLINE Vector4D& operator /= (const Vector4D& vector) { X /= vector.X; Y /= vector.Y; Z /= vector.Z; W /= vector.W; return *this; } INLINE Vector4D& operator *= (const Vector4D& vector) { X *= vector.X; Y *= vector.Y; Z *= vector.Z; W *= vector.W; return *this; } INLINE T& operator [](int index) { //assert(index < 3 && "Out Of Range"); return *(index + (&X)); } INLINE T operator [] (int index) const { //assert(index < 2 && "Out Of Range"); return * (index + (&X)); } INLINE bool operator > (const Vector4D& v) const { return X > v.X && Y > v.Y && Z > v.Z && W > v.W; } INLINE bool operator < (const Vector4D& v) const { return X < v.X && Y < v.Y && Z < v.Z && W < v.W; } }; typedef Vector4D Vec4f; typedef Vector4D Vec4i; typedef Vector4D float4; } #endif