mirror of
https://github.com/thunderbrewhq/typhoon.git
synced 2025-12-12 02:22:30 +00:00
feat(quaternion): add C4Quaternion
This commit is contained in:
parent
b17b7a18e6
commit
189085960f
4 changed files with 57 additions and 0 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
file(GLOB TEMPEST_SOURCES
|
file(GLOB TEMPEST_SOURCES
|
||||||
"*.cpp"
|
"*.cpp"
|
||||||
"matrix/*.cpp"
|
"matrix/*.cpp"
|
||||||
|
"quaternion/*.cpp"
|
||||||
"rect/*.cpp"
|
"rect/*.cpp"
|
||||||
"vector/*.cpp"
|
"vector/*.cpp"
|
||||||
)
|
)
|
||||||
|
|
|
||||||
6
tempest/Quaternion.hpp
Normal file
6
tempest/Quaternion.hpp
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
#ifndef TEMPEST_QUATERNION_HPP
|
||||||
|
#define TEMPEST_QUATERNION_HPP
|
||||||
|
|
||||||
|
#include "tempest/quaternion/C4Quaternion.hpp"
|
||||||
|
|
||||||
|
#endif
|
||||||
26
tempest/quaternion/C4Quaternion.cpp
Normal file
26
tempest/quaternion/C4Quaternion.cpp
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
#include "tempest/quaternion/C4Quaternion.hpp"
|
||||||
|
|
||||||
|
C4Quaternion C4Quaternion::Nlerp(float ratio, const C4Quaternion& q1, const C4Quaternion& q2) {
|
||||||
|
float x = (q2.x - q1.x) * ratio + q1.x;
|
||||||
|
float y = (q2.y - q1.y) * ratio + q1.y;
|
||||||
|
float z = (q2.z - q1.z) * ratio + q1.z;
|
||||||
|
float w = (q2.w - q1.w) * ratio + q1.w;
|
||||||
|
|
||||||
|
float m = x * x + y * y + z * z + w * w;
|
||||||
|
float v9 = ((m - 0.95906597) * -0.532516) + 1.021435;
|
||||||
|
|
||||||
|
if (m <= 0.91521198) {
|
||||||
|
v9 *= (((v9 * v9 * m) - 0.95906597) * -0.532516) + 1.021435;
|
||||||
|
|
||||||
|
if (m <= 0.6521197) {
|
||||||
|
v9 *= (((v9 * v9 * m) - 0.95906597) * -0.532516) + 1.021435;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
x *= v9;
|
||||||
|
y *= v9;
|
||||||
|
z *= v9;
|
||||||
|
w *= v9;
|
||||||
|
|
||||||
|
return { x, y, z, w };
|
||||||
|
}
|
||||||
24
tempest/quaternion/C4Quaternion.hpp
Normal file
24
tempest/quaternion/C4Quaternion.hpp
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
#ifndef TEMPEST_QUATERNION_C_4QUATERNION_HPP
|
||||||
|
#define TEMPEST_QUATERNION_C_4QUATERNION_HPP
|
||||||
|
|
||||||
|
class C4Quaternion {
|
||||||
|
public:
|
||||||
|
// Static functions
|
||||||
|
static C4Quaternion Nlerp(float ratio, const C4Quaternion& q1, const C4Quaternion& q2);
|
||||||
|
|
||||||
|
// Member variables
|
||||||
|
float x = 0.0f;
|
||||||
|
float y = 0.0f;
|
||||||
|
float z = 0.0f;
|
||||||
|
float w = 1.0f;
|
||||||
|
|
||||||
|
// Member functions
|
||||||
|
C4Quaternion() = default;
|
||||||
|
C4Quaternion(float x, float y, float z, float w)
|
||||||
|
: x(x)
|
||||||
|
, y(y)
|
||||||
|
, z(z)
|
||||||
|
, w(w) {};
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
Loading…
Add table
Add a link
Reference in a new issue