diff options
| author | skal <pascal.massimino@gmail.com> | 2026-02-21 07:19:57 +0100 |
|---|---|---|
| committer | skal <pascal.massimino@gmail.com> | 2026-02-21 07:19:57 +0100 |
| commit | 1b2e69b25f2a9d297a87b71d25dcbb575539376b (patch) | |
| tree | 249d7ee92bca7db32328ff580a57703955682e9d /src/util | |
| parent | eb438061b1ca0ef020e2ae7e898e99c8bfa179b3 (diff) | |
feat(math): Add vec3::rotate methods for quaternion and axis-angle rotation
Adds two convenient methods to the struct:
- : Rotates the vector by a given quaternion.
- : Rotates the vector around a given axis by an angle in radians.
These functions provide a more intuitive and streamlined syntax for vector rotation, improving code readability and usability.
Diffstat (limited to 'src/util')
| -rw-r--r-- | src/util/mini_math.h | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/src/util/mini_math.h b/src/util/mini_math.h index f60e27e..29dc38f 100644 --- a/src/util/mini_math.h +++ b/src/util/mini_math.h @@ -117,6 +117,8 @@ struct vec3 { #if defined(USE_QUAT) // Rotate this vector by a quaternion vec3 rotate(const quat& q) const; + // Rotate this vector around an axis by an angle + vec3 rotate(const vec3& axis, float angle) const; #endif static vec3 cross(vec3 a, vec3 b) { @@ -441,6 +443,9 @@ inline quat slerp(quat a, quat b, float t) { inline vec3 vec3::rotate(const quat& q) const { return q.rotate(*this); } +inline vec3 vec3::rotate(const vec3& axis, float angle) const { + return quat::from_axis(axis, angle).rotate(*this); +} #endif #endif /* defined(USE_QUAT) */ |
