From eb438061b1ca0ef020e2ae7e898e99c8bfa179b3 Mon Sep 17 00:00:00 2001 From: skal Date: Sat, 21 Feb 2026 07:17:27 +0100 Subject: feat: Add vec3::rotate function for quaternion rotation. --- src/util/mini_math.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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 inline T lerp(const T& a, const T& b, float t) { -- cgit v1.2.3