| 1 | #pragma once |
| 2 | |
| 3 | #include <basis/seadTypes.h> |
| 4 | #include <cmath> |
| 5 | #include <limits> |
| 6 | #include <math/seadMathPolicies.h> |
| 7 | #include <math/seadVector.h> |
| 8 | |
| 9 | namespace sead |
| 10 | { |
| 11 | template <typename T> |
| 12 | struct Quat : public Policies<T>::QuatBase |
| 13 | { |
| 14 | private: |
| 15 | typedef Quat<T> Self; |
| 16 | typedef Vector3<T> Vec3; |
| 17 | |
| 18 | public: |
| 19 | Quat() {} |
| 20 | Quat(const Quat& other) = default; |
| 21 | Quat(T w, T x, T y, T z); |
| 22 | |
| 23 | Quat& operator=(const Quat& other) |
| 24 | { |
| 25 | this->x = other.x; |
| 26 | this->y = other.y; |
| 27 | this->z = other.z; |
| 28 | this->w = other.w; |
| 29 | return *this; |
| 30 | } |
| 31 | |
| 32 | friend Quat operator*(const Quat& a, T t) |
| 33 | { |
| 34 | auto result = a; |
| 35 | result *= t; |
| 36 | return result; |
| 37 | } |
| 38 | |
| 39 | friend Quat operator*(const Quat& a, const Quat& b) |
| 40 | { |
| 41 | auto result = a; |
| 42 | result *= b; |
| 43 | return result; |
| 44 | } |
| 45 | |
| 46 | friend Quat operator*(T t, const Quat& a) { return operator*(a, t); } |
| 47 | |
| 48 | Quat& operator*=(const Quat& t); |
| 49 | |
| 50 | Quat& operator*=(T t) |
| 51 | { |
| 52 | this->w *= t; |
| 53 | this->x *= t; |
| 54 | this->y *= t; |
| 55 | this->z *= t; |
| 56 | return *this; |
| 57 | } |
| 58 | |
| 59 | bool operator==(const Quat& rhs) const |
| 60 | { |
| 61 | return this->x == rhs.x && this->y == rhs.y && this->z == rhs.z && this->w == rhs.w; |
| 62 | } |
| 63 | |
| 64 | T length() const; |
| 65 | T normalize(); |
| 66 | T dot(const Self& q); |
| 67 | void inverse(Self* q); |
| 68 | |
| 69 | void makeUnit(); |
| 70 | bool makeVectorRotation(const Vec3& from, const Vec3& to); |
| 71 | void set(const Self& other); |
| 72 | void set(T w, T x, T y, T z); |
| 73 | void setRPY(T roll, T pitch, T yaw); |
| 74 | void calcRPY(Vec3& rpy) const; |
| 75 | |
| 76 | static const Quat unit; |
| 77 | }; |
| 78 | |
| 79 | using Quatf = Quat<f32>; |
| 80 | |
| 81 | template <> |
| 82 | const Quatf Quatf::unit; |
| 83 | |
| 84 | } // namespace sead |
| 85 | |
| 86 | #define SEAD_MATH_QUAT_H_ |
| 87 | #include <math/seadQuat.hpp> |
| 88 | #undef SEAD_MATH_QUAT_H_ |
| 89 | |