18 #ifndef __H__OCULAR_MATH_VECTOR_3__H__
19 #define __H__OCULAR_MATH_VECTOR_3__H__
21 #include "Vector2.hpp"
23 #include "Equality.hpp"
24 #include "Utilities/Types.hpp"
25 #include "Exceptions/Exception.hpp"
51 Vector3(T
const* values)
58 Vector3(Quaternion
const& quat)
60 x =
static_cast<T
>(quat.getPitch());
61 y =
static_cast<T
>(quat.getYaw());
62 z =
static_cast<T
>(quat.getRoll());
65 Vector3(Euler
const& euler)
67 x =
static_cast<T
>(euler.getPitch());
68 y =
static_cast<T
>(euler.getYaw());
69 z =
static_cast<T
>(euler.getRoll());
72 Vector3(Vector2<T>
const& vec)
79 Vector3(T
const x, T
const y, T
const z)
88 this->x =
static_cast<T
>(0);
89 this->y =
static_cast<T
>(0);
90 this->z =
static_cast<T
>(0);
102 T& operator[](
unsigned const& index)
116 THROW_EXCEPTION(
"Out-Of-Bounds Vector Access");
121 T operator[](
unsigned const& index)
const
135 THROW_EXCEPTION(
"Out-Of-Bounds Vector Access");
140 Vector3<T> operator-()
142 return Vector3<T>(-x, -y, -z);
145 Vector3<T>& operator=(Vector3<T>
const& rhs)
154 Vector3<T>& operator+=(Vector3<T>
const& rhs)
163 Vector3<T>& operator+=(T
const rhs)
172 Vector3<T>& operator-=(Vector3<T>
const& rhs)
181 Vector3<T>& operator-=(T
const rhs)
190 Vector3<T>& operator*=(Vector3<T>
const& rhs)
199 Vector3<T>& operator*=(T
const rhs)
208 Vector3<T>& operator/=(Vector3<T>
const& rhs)
217 Vector3<T>& operator/=(T
const rhs)
233 Vector2<T> xy()
const
235 return Vector2<T>(x, y);
243 return std::sqrt((x * x) + (y * y) + (z * z));
266 if(IsEqual<T>(length, static_cast<T>(0)))
268 x =
static_cast<T
>(0);
269 y =
static_cast<T
>(0);
270 z =
static_cast<T
>(0);
274 x /=
static_cast<T
>(length);
275 y /=
static_cast<T
>(length);
276 z /=
static_cast<T
>(length);
302 (z * rhs.x) - (x * rhs.z),
303 (x * rhs.y) - (y * rhs.x));
315 return (x * rhs.x) + (y * rhs.y) + (z * rhs.z);
330 double angle = std::acos(normalLHS.dot(normalRHS));
334 angle = PI_TWO - angle;
347 return distance.getMagnitude();
363 T zero =
static_cast<T
>(0);
364 T one =
static_cast<T
>(1);
367 fraction = Clamp<T>(fraction, zero, one);
368 return (from * (one - fraction)) + (to * fraction);
388 fraction = Clamp<double>(fraction, 0.0, 1.0);
389 double omega = from.angleBetween(to);
391 double lhs = std::sin((1.0 - fraction) * omega) / std::sin(omega);
392 double rhs = std::sin(fraction * omega) / std::sin(omega);
394 return (from * lhs) + (to * rhs);
406 T two =
static_cast<T
>(2);
410 ((a.z + b.z) / two));
419 static Vector3<T> Identity() {
return Vector3<T>(
static_cast<T
>( 0.0f), static_cast<T>( 0.0f),
static_cast<T
>( 0.0f)); }
420 static Vector3<T> Up() {
return Vector3<T>(
static_cast<T
>( 0.0f), static_cast<T>( 1.0f),
static_cast<T
>( 0.0f)); }
421 static Vector3<T> Down() {
return Vector3<T>(
static_cast<T
>( 0.0f), static_cast<T>(-1.0f),
static_cast<T
>( 0.0f)); }
422 static Vector3<T> Left() {
return Vector3<T>(
static_cast<T
>(-1.0f), static_cast<T>( 0.0f),
static_cast<T
>( 0.0f)); }
423 static Vector3<T> Right() {
return Vector3<T>(
static_cast<T
>( 1.0f), static_cast<T>( 0.0f),
static_cast<T
>( 0.0f)); }
424 static Vector3<T> Forward() {
return Vector3<T>(
static_cast<T
>( 0.0f), static_cast<T>( 0.0f),
static_cast<T
>(-1.0f)); }
425 static Vector3<T> Backward() {
return Vector3<T>(
static_cast<T
>( 0.0f), static_cast<T>( 0.0f),
static_cast<T
>( 1.0f)); }
431 union{ T x, r, u, s; };
432 union{ T y, g, v, t; };
435 static bool OCULAR_INTERNAL_Force;
445 bool operator==(Vector3<T>
const& lhs, Vector3<T>
const& rhs)
447 return IsEqual<T>(lhs.x, rhs.x) && IsEqual<T>(lhs.y, rhs.y) && IsEqual<T>(lhs.z, rhs.z);
451 bool operator!=(Vector3<T>
const& lhs, Vector3<T>
const& rhs)
453 return !(lhs == rhs);
457 bool operator>(Vector3<T>
const& lhs, Vector3<T>
const& rhs)
459 return ((lhs.x > rhs.x) && (lhs.y > rhs.y) && (lhs.z > rhs.z));
463 bool operator<(Vector3<T>
const& lhs, Vector3<T>
const& rhs)
465 return ((lhs.x < rhs.x) && (lhs.y < rhs.y) && (lhs.z < rhs.z));
469 Vector3<T> operator+(Vector3<T>
const& lhs, Vector3<T>
const& rhs)
471 return Vector3<T>(lhs.x + rhs.x, lhs.y + rhs.y, lhs.z + rhs.z);
475 Vector3<T> operator+(Vector3<T>
const& lhs, T
const& rhs)
477 return Vector3<T>(lhs.x + rhs, lhs.y + rhs, lhs.z + rhs);
481 Vector3<T> operator-(Vector3<T>
const& lhs, Vector3<T>
const& rhs)
483 return Vector3<T>(lhs.x - rhs.x, lhs.y - rhs.y, lhs.z - rhs.z);
487 Vector3<T> operator-(Vector3<T>
const& lhs, T
const& rhs)
489 return Vector3<T>(lhs.x - rhs, lhs.y - rhs, lhs.z - rhs);
493 Vector3<T> operator*(Vector3<T>
const& lhs, Vector3<T>
const& rhs)
495 return Vector3<T>(lhs.x * rhs.x, lhs.y * rhs.y, lhs.z * rhs.z);
499 Vector3<T> operator*(Vector3<T>
const& lhs, T
const& rhs)
501 return Vector3<T>(lhs.x * rhs, lhs.y * rhs, lhs.z * rhs);
505 Vector3<T> operator/(Vector3<T>
const& lhs, Vector3<T>
const& rhs)
507 return Vector3<T>(lhs.x / rhs.x, lhs.y / rhs.y, lhs.z / rhs.z);
511 Vector3<T> operator/(Vector3<T>
const& lhs, T
const& rhs)
513 return Vector3<T>(lhs.x / rhs, lhs.y / rhs, lhs.z / rhs);
519 typedef Vector3<float> Vector3f;
520 typedef Vector3<double> Vector3d;
522 typedef Vector3f Point3f;
523 typedef Vector3d Point3d;
Note: Once this library is made dynamic, this will no longer be needed.
Definition: Common.hpp:70
static Vector3< T > Lerp(Vector3< T > const from, Vector3< T > const to, T fraction)
Definition: Vector3.hpp:361
double angleBetween(Vector3< T > const &rhs) const
Definition: Vector3.hpp:325
Vector3< T > cross(Vector3< T > const &rhs) const
Definition: Vector3.hpp:299
Vector3< T > getNormalized() const
Definition: Vector3.hpp:283
static Vector3< T > Slerp(Vector3< T > const &from, Vector3< T > const &to, double fraction)
Definition: Vector3.hpp:384
void normalize()
Definition: Vector3.hpp:260
T distanceTo(Vector3< T > const &rhs) const
Definition: Vector3.hpp:344
T getMagnitude() const
Definition: Vector3.hpp:241
T dot(Vector3< T > const &rhs) const
Definition: Vector3.hpp:313
T getLength() const
Definition: Vector3.hpp:249
static Vector3< T > Midpoint(Vector3< T > const &a, Vector3< T > const &b)
Definition: Vector3.hpp:404