diff options
| author | skal <pascal.massimino@gmail.com> | 2026-02-21 07:17:27 +0100 |
|---|---|---|
| committer | skal <pascal.massimino@gmail.com> | 2026-02-21 07:17:27 +0100 |
| commit | eb438061b1ca0ef020e2ae7e898e99c8bfa179b3 (patch) | |
| tree | 8a2aa45604873d76771953b7977c8f802e9f5eca /src/util | |
| parent | 32614f73cc78b6c2aa0d1381cb62b583f4fde6fc (diff) | |
feat: Add vec3::rotate function for quaternion rotation.
Diffstat (limited to 'src/util')
| -rw-r--r-- | src/util/mini_math.h | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/util/mini_math.h b/src/util/mini_math.h index f847cc1..f60e27e 100644 --- a/src/util/mini_math.h +++ b/src/util/mini_math.h @@ -97,6 +97,10 @@ struct vec2 { }; #endif /* defined(USE_VEC2) */ +#if defined(USE_QUAT) +struct quat; +#endif + #if defined(USE_VEC3) struct vec3 { union { @@ -110,6 +114,11 @@ struct vec3 { } VEC_OPERATORS(vec3, 3) // Operators only touch x,y,z (indices 0,1,2) +#if defined(USE_QUAT) + // Rotate this vector by a quaternion + vec3 rotate(const quat& q) const; +#endif + static vec3 cross(vec3 a, vec3 b) { return {a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x}; @@ -427,6 +436,12 @@ inline quat slerp(quat a, quat b, float t) { s1 = std::sin(th) / s0, s2 = std::sin(th0 - th) / s0; return a * s2 + b * s1; } + +#if defined(USE_VEC3) +inline vec3 vec3::rotate(const quat& q) const { + return q.rotate(*this); +} +#endif #endif /* defined(USE_QUAT) */ template <typename T> inline T lerp(const T& a, const T& b, float t) { |
