#ifndef __QUATERNION__ #define __QUATERNION__ #include "Math.h" #include 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 Quaternion { public: float X,Y,Z,W; INLINE Quaternion() { X = Y = Z = W = 0.0f; } INLINE Quaternion operator -() const { return Quaternion(-X, -Y, -Z, -W); } INLINE bool operator == (const Quaternion& right) const { return (X == right.X && Y == right.Y && Z == right.Z && W == right.W); } INLINE bool operator != (const Quaternion& right) const { return (X != right.X || Y != right.Y || Z != right.Z || W != right.W); } INLINE Quaternion(float x, float y, float z, float w) { X = x; Y = y; Z = z; W = w; } INLINE Quaternion& operator =(const Quaternion& other) { X = other.X; Y = other.Y; Z = other.Z; W = other.W; return *this; } INLINE Quaternion operator *(float other) const { return Quaternion(X * other, Y * other, Z * other, W * other); } INLINE Quaternion operator +(const Quaternion& other) const { return Quaternion(X + other.X, Y + other.Y, Z + other.Z, W + other.W); } INLINE Quaternion operator *(const Quaternion& other) const { Quaternion quaternion; float x = this->X; float y = this->Y; float z = this->Z; float w = this->W; float num4 = other.X; float num3 = other.Y; float num2 = other.Z; float num = other.W; float num12 = (y * num2) - (z * num3); float num11 = (z * num4) - (x * num2); float num10 = (x * num3) - (y * num4); float num9 = ((x * num4) + (y * num3)) + (z * num2); quaternion.X = ((x * num) + (num4 * w)) + num12; quaternion.Y = ((y * num) + (num3 * w)) + num11; quaternion.Z = ((z * num) + (num2 * w)) + num10; quaternion.W = (w * num) - num9; return quaternion; } }; } #endif