| 1 | #pragma once |
| 2 | |
| 3 | #include <math/seadQuatCalcCommon.h> |
| 4 | #ifndef SEAD_MATH_QUAT_H_ |
| 5 | #include <math/seadQuat.h> |
| 6 | #endif |
| 7 | |
| 8 | namespace sead |
| 9 | { |
| 10 | template <typename T> |
| 11 | inline Quat<T>::Quat(T w_, T x_, T y_, T z_) |
| 12 | { |
| 13 | QuatCalcCommon<T>::set(*this, w_, x_, y_, z_); |
| 14 | } |
| 15 | |
| 16 | template <typename T> |
| 17 | inline Quat<T>& Quat<T>::operator*=(const Quat<T>& t) |
| 18 | { |
| 19 | QuatCalcCommon<T>::setMul(*this, *this, t); |
| 20 | return *this; |
| 21 | } |
| 22 | |
| 23 | template <typename T> |
| 24 | inline T Quat<T>::length() const |
| 25 | { |
| 26 | return QuatCalcCommon<T>::length(*this); |
| 27 | } |
| 28 | |
| 29 | template <typename T> |
| 30 | inline T Quat<T>::normalize() |
| 31 | { |
| 32 | return QuatCalcCommon<T>::normalize(*this); |
| 33 | } |
| 34 | |
| 35 | template <typename T> |
| 36 | inline T Quat<T>::dot(const Self& q) |
| 37 | { |
| 38 | return QuatCalcCommon<T>::dot(*this, q); |
| 39 | } |
| 40 | |
| 41 | // reference? |
| 42 | // conjugate(q) / dot(q)? |
| 43 | template <typename T> |
| 44 | inline void Quat<T>::inverse(Self* q) |
| 45 | { |
| 46 | T prod = dot(q: *this); |
| 47 | if (prod > std::numeric_limits<T>::epsilon()) |
| 48 | { |
| 49 | T inv = T(1) / prod; |
| 50 | q->w = inv * this->w; |
| 51 | q->x = inv * -this->x; |
| 52 | q->y = inv * -this->y; |
| 53 | q->z = inv * -this->z; |
| 54 | } |
| 55 | else |
| 56 | { |
| 57 | q->w = this->w; |
| 58 | q->x = -this->x; |
| 59 | q->y = -this->y; |
| 60 | q->z = -this->z; |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | template <typename T> |
| 65 | inline void Quat<T>::makeUnit() |
| 66 | { |
| 67 | QuatCalcCommon<T>::makeUnit(*this); |
| 68 | } |
| 69 | |
| 70 | template <typename T> |
| 71 | inline bool Quat<T>::makeVectorRotation(const Vec3& from, const Vec3& to) |
| 72 | { |
| 73 | return QuatCalcCommon<T>::makeVectorRotation(*this, from, to); |
| 74 | } |
| 75 | |
| 76 | template <typename T> |
| 77 | inline void Quat<T>::set(const Self& other) |
| 78 | { |
| 79 | QuatCalcCommon<T>::set(*this, other); |
| 80 | } |
| 81 | |
| 82 | template <typename T> |
| 83 | inline void Quat<T>::set(T w_, T x_, T y_, T z_) |
| 84 | { |
| 85 | QuatCalcCommon<T>::set(*this, w_, x_, y_, z_); |
| 86 | } |
| 87 | |
| 88 | template <typename T> |
| 89 | inline void Quat<T>::setRPY(T roll, T pitch, T yaw) |
| 90 | { |
| 91 | QuatCalcCommon<T>::setRPY(*this, roll, pitch, yaw); |
| 92 | } |
| 93 | |
| 94 | template <typename T> |
| 95 | inline void Quat<T>::calcRPY(Vec3& vec) const |
| 96 | { |
| 97 | QuatCalcCommon<T>::calcRPY(vec, *this); |
| 98 | } |
| 99 | |
| 100 | } // namespace sead |
| 101 | |