summaryrefslogtreecommitdiff
path: root/src/maths
diff options
context:
space:
mode:
authorOmniscient <17525998+omnisci3nce@users.noreply.github.com>2024-04-21 11:45:18 +1000
committerOmniscient <17525998+omnisci3nce@users.noreply.github.com>2024-04-21 11:45:18 +1000
commitedd6e07841b95c76664e31813bf980742cca4528 (patch)
tree6c3f26e94b4f7f9c5efa6271cbeb0f075d3ccc84 /src/maths
parent514d83c9c66330a7f98685aff65a15ff39a562cd (diff)
parent45f035c2174a018444a4e495ec78b4806900d903 (diff)
Merge branch 'master' into cel-41-port-over-a-basic-3d-scene-example
Diffstat (limited to 'src/maths')
-rw-r--r--src/maths/maths.h16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/maths/maths.h b/src/maths/maths.h
index 6834f69..3301634 100644
--- a/src/maths/maths.h
+++ b/src/maths/maths.h
@@ -59,13 +59,25 @@ static inline vec2 vec2_create(f32 x, f32 y) { return (vec2){ x, y }; }
static inline f32 quat_dot(quat a, quat b) { return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w; }
static inline quat quat_normalise(quat a) {
- f32 length = sqrtf(quat_dot(a, a) // same as len squared
- );
+ f32 length = sqrtf(quat_dot(a, a)); // same as len squared
+
return (quat){ a.x / length, a.y / length, a.z / length, a.w / length };
}
static inline quat quat_ident() { return (quat){ .x = 0.0, .y = 0.0, .z = 0.0, .w = 1.0 }; }
+static quat quat_from_axis_angle(vec3 axis, f32 angle, bool normalize) {
+ const f32 half_angle = 0.5f * angle;
+ f32 s = sinf(half_angle);
+ f32 c = cosf(half_angle);
+
+ quat q = (quat){ s * axis.x, s * axis.y, s * axis.z, c };
+ if (normalize) {
+ return quat_normalise(q);
+ }
+ return q;
+}
+
// --- Matrix Implementations
static inline mat4 mat4_ident() {