12#ifndef TT_INCLUDE__VECTOR4_H
13#define TT_INCLUDE__VECTOR4_H
24 TT_INLINE Vector4() {};
25 TT_INLINE Vector4(
const Vector4& v) { X = v.X; Y = v.Y; Z = v.Z; W = v.W; };
26 TT_INLINE Vector4(
float x,
float y,
float z,
float w) { X = x; Y = y; Z = z; W = w; };
27 TT_INLINE
explicit Vector4(
const float v[4]) { TT_ASSERT(v != NULL); X = v[0]; Y = v[1]; Z = v[2]; W = v[3]; };
34 TT_INLINE Vector4& operator=(
const Vector4& v) { X = v.X; Y = v.Y; Z = v.Z; W = v.W;
return *
this; };
35 TT_INLINE
void Set(
float x,
float y,
float z,
float w) { X = x; Y = y; Z = z; W = w; };
38 TT_INLINE
float& operator[](
int i) {
return (&X)[i]; };
39 TT_INLINE
const float& operator[](
int i)
const {
return (&X)[i]; };
40 TT_INLINE
void Normalize(
void)
42 float len2 = WWMATH_FLOAT_TINY + Length2();
43 float oolen = WWMath::Inv_Sqrt(len2);
49 TT_INLINE
float Length(
void)
const
51 return WWMath::Sqrt(Length2());
53 TT_INLINE
float Length2(
void)
const
55 return X*X + Y*Y + Z*Z + W*W;
59 TT_INLINE Vector4 operator-()
const {
return(Vector4(-X,-Y,-Z,-W)); } ;
60 TT_INLINE Vector4 operator+()
const {
return *
this; };
62 TT_INLINE Vector4& operator+=(
const Vector4& v) { X += v.X; Y += v.Y; Z += v.Z; W += v.W;
return *
this; };
63 TT_INLINE Vector4& operator-=(
const Vector4& v) { X -= v.X; Y -= v.Y; Z -= v.Z; W -= v.W;
return *
this; };
64 TT_INLINE Vector4& operator*=(
float f) { X *= f; Y *= f; Z *= f; W *= f;
return *
this; };
65 TT_INLINE Vector4& operator/=(
float f) { f = 1.0f / f; X /= f; Y /= f; Z /= f; W /= f;
return *
this; };
68 friend Vector4 operator+(
const Vector4& a,
const Vector4& b);
69 friend Vector4 operator-(
const Vector4& a,
const Vector4& b);
72 friend Vector4 operator*(
const Vector4 &a,
float b);
73 friend Vector4 operator*(
float a,
const Vector4 &b);
74 friend Vector4 operator/(
const Vector4 &a,
float b);
77 friend bool operator== (
const Vector4 &a,
const Vector4 &b);
78 friend bool operator!= (
const Vector4 &a,
const Vector4 &b);
80 friend float operator * (
const Vector4 &a,
const Vector4 &b);
81 TT_INLINE
static float Dot_Product(
const Vector4 &a,
const Vector4 &b)
85 TT_INLINE
static Vector4 Lerp(
const Vector4 & a,
const Vector4 & b,
float alpha)
87 return Vector4((a.X + (b.X - a.X)*alpha),(a.Y + (b.Y - a.Y)*alpha),(a.Z + (b.Z - a.Z)*alpha),(a.W + (b.W - a.W)*alpha));
89 TT_INLINE
static void Lerp(
const Vector4 & a,
const Vector4 & b,
float alpha,Vector4 * set_result)
91 set_result->X = (a.X + (b.X - a.X)*alpha);
92 set_result->Y = (a.Y + (b.Y - a.Y)*alpha);
93 set_result->Z = (a.Z + (b.Z - a.Z)*alpha);
94 set_result->W = (a.W + (b.W - a.W)*alpha);
98TT_INLINE Vector4 operator+(
const Vector4& a,
const Vector4& b)
100 return Vector4(a.X + b.X, a.Y + b.Y, a.Z + b.Z, a.W + b.W);
103TT_INLINE Vector4 operator-(
const Vector4& a,
const Vector4& b)
105 return Vector4(a.X - b.X, a.Y - b.Y, a.Z - b.Z, a.W - b.W);
108TT_INLINE Vector4 operator*(
const Vector4 &a,
float b)
110 return Vector4(a.X * b, a.Y * b, a.Z * b, a.W * b);
113TT_INLINE Vector4 operator*(
float a,
const Vector4 &b)
118TT_INLINE Vector4 operator/(
const Vector4 &a,
float k)
120 return Vector4(a.X * 1.0f / k, a.Y * 1.0f / k, a.Z * 1.0f / k, a.W * 1.0f / k);
123TT_INLINE
bool operator==(
const Vector4 &a,
const Vector4 &b)
125 return (a.X == b.X) && (a.Y == b.Y) && (a.Z == b.Z) && (a.W == b.W);
128TT_INLINE
bool operator!=(
const Vector4 &a,
const Vector4 &b)
130 return (a.X != b.X) || (a.Y != b.Y) || (a.Z != b.Z) || (a.W != b.W);
133TT_INLINE
float operator * (
const Vector4 &a,
const Vector4 &b)
135 return a[0]*b[0] + a[1]*b[1] + a[2]*b[2] + a[3]*b[3];
138TT_INLINE Vector4 Normalize(
const Vector4 & vec)
140 float len2 = WWMATH_FLOAT_TINY + vec.Length2();
141 return vec * WWMath::Inv_Sqrt(len2);
144TT_INLINE
void Swap(Vector4 & a,Vector4 & b)
151TT_INLINE Vector4 Lerp(
const Vector4 & a,
const Vector4 & b,
float alpha)
153 return Vector4((a.X + (b.X - a.X) * alpha),(a.Y + (b.Y - a.Y) * alpha),(a.Z + (b.Z - a.Z) * alpha),(a.W + (b.W - a.W) * alpha));