#ifndef __VECTOR3D__ #define __VECTOR3D__ #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 template struct Vector3D { public: T X, Y, Z; INLINE Vector3D(T x, T y, T z) { this->X = x; this->Y = y; this->Z = z; } INLINE Vector3D(void) { this->X = 0.0f; this->Y = 0.0f; this->Z = 0.0f; } INLINE Vector3D(T val) { this->X = val; this->Y = val; this->Z = val; } INLINE Vector3D& operator=(const Vector3D& other) { X = other.X; Y = other.Y; Z = other.Z; return *this; } //unary operators INLINE Vector3D operator -() const { return Vector3D(-X, -Y, -Z); } INLINE Vector3D operator +() const { return *this; } //binary operators INLINE Vector3D operator +(const Vector3D &other) const { return Vector3D(X + other.X, Y + other.Y, Z + other.Z); } INLINE Vector3D operator -(const Vector3D &other) const { return Vector3D(X - other.X, Y - other.Y, Z - other.Z); } INLINE Vector3D operator *(T other) const { return Vector3D(X * other, Y * other, Z * other); } INLINE Vector3D operator /(T other) const { return Vector3D(X / other, Y / other, Z / other); } INLINE operator T * () { return &X; } INLINE operator const T * () const { return &X; } INLINE bool operator == (const Vector3D& vector) const { return (X == vector.X && Y == vector.Y && Z == vector.Z); } INLINE bool operator != (const Vector3D& vector) const { return (X != vector.X || Y != vector.Y || Z != vector.Z); } INLINE Vector3D& operator += (const Vector3D& Vector) { X += Vector.X; Y += Vector.Y; Z += Vector.Z; return *this; } INLINE Vector3D& operator -= (const Vector3D& Vector) { X -= Vector.X; Y -= Vector.Y; Z -= Vector.Z; return *this; } INLINE Vector3D& operator *= (T Value) { X *= Value; Y *= Value; Z *= Value; return *this; } INLINE Vector3D& operator /= (T Value) { //assert(Value && "Zero Value"); *this *= (1.0f / Value); return *this; } INLINE Vector3D& operator += (T Value) { X += Value; Y += Value; Z += Value; return *this; } INLINE Vector3D& operator -= (T Value) { X -= Value; Y -= Value; Z -= Value; return *this; } INLINE Vector3D& operator /= (const Vector3D& vector) { X /= vector.X; Y /= vector.Y; Z /= vector.Z; return *this; } INLINE Vector3D& operator *= (const Vector3D& vector) { X *= vector.X; Y *= vector.Y; Z *= vector.Z; 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 Vector3D& v) const { return X > v.X && Y > v.Y && Z > v.Z; } INLINE bool operator < (const Vector3D& v) const { return X < v.X && Y < v.Y && Z < v.Z; } }; typedef Vector3D Vec3f; typedef Vector3D Vec3i; typedef Vector3D float3; } #endif