18 #ifndef __H__OCULAR_MATH_VECTOR_4__H__
19 #define __H__OCULAR_MATH_VECTOR_4__H__
21 #include "Equality.hpp"
22 #include "Vector3.hpp"
23 #include "Utilities/Types.hpp"
24 #include "Exceptions/Exception.hpp"
48 Vector4(T
const* values)
56 Vector4(Vector3<T>
const& vec, T pW = static_cast<T>(1.0f))
64 Vector4(T
const &pX, T
const &pY, T
const &pZ, T
const &pW)
74 x =
static_cast<T
>(0.0);
75 y =
static_cast<T
>(0.0);
76 z =
static_cast<T
>(0.0);
77 w =
static_cast<T
>(1.0);
89 T& operator[](
unsigned const& index)
106 THROW_EXCEPTION(
"Out-Of-Bounds Vector Access");
111 T operator[](
unsigned const& index)
const
128 THROW_EXCEPTION(
"Out-Of-Bounds Vector Access");
133 Vector4<T> operator-()
135 return Vector4<T>(-x, -y, -z, -w);
138 Vector4<T>& operator=(Vector4<T>
const &rhs)
148 Vector4<T>& operator=(Vector3<T>
const &rhs)
153 w =
static_cast<T
>(1);
158 Vector4<T>& operator+=(Vector4<T>
const &rhs)
168 Vector4<T>& operator+=(T
const &rhs)
178 Vector4<T>& operator-=(Vector4<T>
const &rhs)
188 Vector4<T>& operator-=(T
const &rhs)
198 Vector4<T>& operator*=(Vector4<T>
const &rhs)
208 Vector4<T>& operator*=(T
const &rhs)
218 Vector4<T>& operator/=(Vector4<T>
const &rhs)
228 Vector4<T>& operator/=(T
const &rhs)
245 Vector2<T> xy()
const
247 return Vector2<T>(x, y);
253 Vector3<T> xyz()
const
255 return Vector3<T>(x, y, z);
263 return std::sqrt((x * x) + (y * y) + (z * z) + (w * w));
283 if(IsEqual<T>(length, static_cast<T>(0)))
285 x =
static_cast<T
>(0);
286 y =
static_cast<T
>(0);
287 z =
static_cast<T
>(0);
288 w =
static_cast<T
>(1);
292 x /=
static_cast<T
>(length);
293 y /=
static_cast<T
>(length);
294 z /=
static_cast<T
>(length);
295 w /=
static_cast<T
>(length);
319 return (x * rhs.x) + (y * rhs.y) + (z * rhs.z) + (w * rhs.w);
334 double angle = std::acos(normalLHS.dot(normalRHS));
338 angle = PI_TWO - angle;
341 return static_cast<T
>(angle);
351 return distance.getMagnitude();
374 T two =
static_cast<T
>(2);
380 ((a.w + b.w) / two));
387 union { T x, r, u, s; };
388 union { T y, g, v, t; };
389 union { T z, b, p; };
390 union { T w, a, q; };
392 static bool OCULAR_INTERNAL_Force;
402 bool operator==(Vector4<T>
const &lhs, Vector4<T>
const &rhs)
404 return IsEqual<T>(lhs.x, rhs.x) && IsEqual<T>(lhs.y, rhs.y) && IsEqual<T>(lhs.z, rhs.z) && IsEqual<T>(lhs.w, rhs.w);
408 bool operator!=(Vector4<T>
const &lhs, Vector4<T>
const &rhs)
410 return !(lhs == rhs);
414 Vector4<T> operator+(Vector4<T>
const &lhs, Vector4<T>
const &rhs)
416 return Vector4<T>(lhs.x + rhs.x, lhs.y + rhs.y, lhs.z + rhs.z, lhs.w + rhs.w);
420 Vector4<T> operator+(Vector4<T>
const &lhs, T
const &rhs)
422 return Vector4<T>(lhs.x + rhs, lhs.y + rhs, lhs.z + rhs, lhs.w + rhs);
426 Vector4<T> operator-(Vector4<T>
const &lhs, Vector4<T>
const &rhs)
428 return Vector4<T>(lhs.x - rhs.x, lhs.y - rhs.y, lhs.z - rhs.z, lhs.w - rhs.w);
432 Vector4<T> operator-(Vector4<T>
const &lhs, T
const &rhs)
434 return Vector4<T>(lhs.x - rhs, lhs.y - rhs, lhs.z - rhs, lhs.w - rhs);
438 Vector4<T> operator*(Vector4<T>
const &lhs, Vector4<T>
const &rhs)
440 return Vector4<T>(lhs.x * rhs.x, lhs.y * rhs.y, lhs.z * rhs.z, lhs.w * rhs.w);
444 Vector4<T> operator*(Vector4<T>
const &lhs, T
const &rhs)
446 return Vector4<T>(lhs.x * rhs, lhs.y * rhs, lhs.z * rhs, lhs.w * rhs);
450 Vector4<T> operator/(Vector4<T>
const &lhs, Vector4<T>
const &rhs)
452 return Vector4<T>(lhs.x / rhs.x, lhs.y / rhs.y, lhs.z / rhs.z, lhs.w / rhs.w);
456 Vector4<T> operator/(Vector4<T>
const &lhs, T
const &rhs)
458 return Vector4<T>(lhs.x / rhs, lhs.y / rhs, lhs.z / rhs, lhs.w / rhs);
461 typedef Vector4<float> Vector4f;
462 typedef Vector4<double> Vector4d;
464 typedef Vector4f Point4f;
465 typedef Vector4d Point4d;
T getMagnitude() const
Definition: Vector4.hpp:261
Definition: Matrix3x3.hpp:39
T dot(Vector4< T > const &rhs) const
Definition: Vector4.hpp:317
Vector4< T > getNormalized() const
Definition: Vector4.hpp:302
T distanceTo(Vector4< T > const &rhs) const
Definition: Vector4.hpp:348
void homogenize()
Definition: Vector4.hpp:357
Note: Once this library is made dynamic, this will no longer be needed.
Definition: Common.hpp:70
void normalize()
Definition: Vector4.hpp:277
T getLength() const
Definition: Vector4.hpp:269
static Vector4< T > Midpoint(Vector4< T > const &a, Vector4< T > const &b)
Definition: Vector4.hpp:372
T angleBetween(Vector4< T > const &rhs) const
Definition: Vector4.hpp:329