diff options
| author | 2017-01-07 12:39:20 -0500 | |
|---|---|---|
| committer | 2017-01-07 12:39:20 -0500 | |
| commit | 7cfe3ef0463ace034b1e5786c9581cfa5f2e810c (patch) | |
| tree | 6b06cb03d276b29070ca29599fc4c5fcf77edb39 /src/common/quaternion.h | |
| parent | Merge pull request #2410 from Subv/sleepthread (diff) | |
| parent | Frontend: make motion sensor interfaced thread-safe (diff) | |
| download | yuzu-7cfe3ef0463ace034b1e5786c9581cfa5f2e810c.tar.gz yuzu-7cfe3ef0463ace034b1e5786c9581cfa5f2e810c.tar.xz yuzu-7cfe3ef0463ace034b1e5786c9581cfa5f2e810c.zip | |
Merge pull request #1951 from wwylele/motion-sensor
Emulate motion sensor in frontend
Diffstat (limited to '')
| -rw-r--r-- | src/common/quaternion.h | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/common/quaternion.h b/src/common/quaternion.h new file mode 100644 index 000000000..84ac82ed3 --- /dev/null +++ b/src/common/quaternion.h | |||
| @@ -0,0 +1,44 @@ | |||
| 1 | // Copyright 2016 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include "common/vector_math.h" | ||
| 8 | |||
| 9 | namespace Math { | ||
| 10 | |||
| 11 | template <typename T> | ||
| 12 | class Quaternion { | ||
| 13 | public: | ||
| 14 | Math::Vec3<T> xyz; | ||
| 15 | T w; | ||
| 16 | |||
| 17 | Quaternion<decltype(-T{})> Inverse() const { | ||
| 18 | return {-xyz, w}; | ||
| 19 | } | ||
| 20 | |||
| 21 | Quaternion<decltype(T{} + T{})> operator+(const Quaternion& other) const { | ||
| 22 | return {xyz + other.xyz, w + other.w}; | ||
| 23 | } | ||
| 24 | |||
| 25 | Quaternion<decltype(T{} - T{})> operator-(const Quaternion& other) const { | ||
| 26 | return {xyz - other.xyz, w - other.w}; | ||
| 27 | } | ||
| 28 | |||
| 29 | Quaternion<decltype(T{} * T{} - T{} * T{})> operator*(const Quaternion& other) const { | ||
| 30 | return {xyz * other.w + other.xyz * w + Cross(xyz, other.xyz), | ||
| 31 | w * other.w - Dot(xyz, other.xyz)}; | ||
| 32 | } | ||
| 33 | }; | ||
| 34 | |||
| 35 | template <typename T> | ||
| 36 | auto QuaternionRotate(const Quaternion<T>& q, const Math::Vec3<T>& v) { | ||
| 37 | return v + 2 * Cross(q.xyz, Cross(q.xyz, v) + v * q.w); | ||
| 38 | } | ||
| 39 | |||
| 40 | inline Quaternion<float> MakeQuaternion(const Math::Vec3<float>& axis, float angle) { | ||
| 41 | return {axis * std::sin(angle / 2), std::cos(angle / 2)}; | ||
| 42 | } | ||
| 43 | |||
| 44 | } // namspace Math | ||