diff options
Diffstat (limited to 'src/util/mini_math.h')
| -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) { |
