diff options
author | aap <aap@papnet.eu> | 2019-06-11 08:59:28 +0200 |
---|---|---|
committer | aap <aap@papnet.eu> | 2019-06-11 08:59:28 +0200 |
commit | e7ed4d009636804d5dbe05aae9e7ab23b80fdd37 (patch) | |
tree | 4c95f6e07923b5ed0a7046afeb42a1ea2b8693bf /src/math/Quaternion.h | |
parent | Merge branch 'master' of github.com:GTAmodding/re3 (diff) | |
download | re3-e7ed4d009636804d5dbe05aae9e7ab23b80fdd37.tar re3-e7ed4d009636804d5dbe05aae9e7ab23b80fdd37.tar.gz re3-e7ed4d009636804d5dbe05aae9e7ab23b80fdd37.tar.bz2 re3-e7ed4d009636804d5dbe05aae9e7ab23b80fdd37.tar.lz re3-e7ed4d009636804d5dbe05aae9e7ab23b80fdd37.tar.xz re3-e7ed4d009636804d5dbe05aae9e7ab23b80fdd37.tar.zst re3-e7ed4d009636804d5dbe05aae9e7ab23b80fdd37.zip |
Diffstat (limited to '')
-rw-r--r-- | src/math/Quaternion.h | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/src/math/Quaternion.h b/src/math/Quaternion.h new file mode 100644 index 00000000..702fc72f --- /dev/null +++ b/src/math/Quaternion.h @@ -0,0 +1,83 @@ +#pragma once + +// TODO: actually implement this +class CQuaternion +{ +public: + float x, y, z, w; + CQuaternion(void) {} + CQuaternion(float x, float y, float z, float w) : x(x), y(y), z(z), w(w) {} + + float Magnitude(void) const { return sqrt(x*x + y*y + z*z + w*w); } + float MagnitudeSqr(void) const { return x*x + y*y + z*z + w*w; } + + const CQuaternion &operator+=(CQuaternion const &right) { + x += right.x; + y += right.y; + z += right.z; + w += right.w; + return *this; + } + + const CQuaternion &operator-=(CQuaternion const &right) { + x -= right.x; + y -= right.y; + z -= right.z; + w -= right.w; + return *this; + } + + const CQuaternion &operator*=(float right) { + x *= right; + y *= right; + z *= right; + w *= right; + return *this; + } + + const CQuaternion &operator/=(float right) { + x /= right; + y /= right; + z /= right; + w /= right; + return *this; + } + + CQuaternion operator-() const { + return CQuaternion(-x, -y, -z, -w); + } + + void Slerp(const CQuaternion &q1, const CQuaternion &q2, float theta, float invSin, float t); + void Get(RwMatrix *matrix); +}; + +inline float +DotProduct(const CQuaternion &q1, const CQuaternion &q2) +{ + return q1.x*q2.x + q1.y*q2.y + q1.z*q2.z + q1.w*q2.w; +} + +inline CQuaternion operator+(const CQuaternion &left, const CQuaternion &right) +{ + return CQuaternion(left.x + right.x, left.y + right.y, left.z + right.z, left.w + right.w); +} + +inline CQuaternion operator-(const CQuaternion &left, const CQuaternion &right) +{ + return CQuaternion(left.x - right.x, left.y - right.y, left.z - right.z, left.w - right.w); +} + +inline CQuaternion operator*(const CQuaternion &left, float right) +{ + return CQuaternion(left.x * right, left.y * right, left.z * right, left.w * right); +} + +inline CQuaternion operator*(float left, const CQuaternion &right) +{ + return CQuaternion(left * right.x, left * right.y, left * right.z, left * right.w); +} + +inline CQuaternion operator/(const CQuaternion &left, float right) +{ + return CQuaternion(left.x / right, left.y / right, left.z / right, left.w / right); +} |