Banjo API 0.0.1
C99 game development API
Loading...
Searching...
No Matches
quat.h File Reference
#include <banjo/api.h>
#include <banjo/math.h>
#include <banjo/vec.h>
#include <banjo/mat.h>
Include dependency graph for quat.h:

Go to the source code of this file.

Functions

static struct bj_vec4 bj_quat_identity (void)
static bj_real bj_quat_dot (struct bj_vec4 a, struct bj_vec4 b)
static bj_real bj_quat_norm2 (struct bj_vec4 q)
static bj_real bj_quat_norm (struct bj_vec4 q)
static struct bj_vec4 bj_quat_normalize (struct bj_vec4 q)
static struct bj_vec4 bj_quat_conjugate (struct bj_vec4 q)
static struct bj_vec4 bj_quat_inverse (struct bj_vec4 q)
static struct bj_vec4 bj_quat_mul (struct bj_vec4 p, struct bj_vec4 q)
static struct bj_vec4 bj_quat_slerp (struct bj_vec4 a, struct bj_vec4 b, bj_real t)
static struct bj_vec4 bj_quat_from_axis_angle (struct bj_vec3 axis, bj_real angle_rad)
static struct bj_vec3 bj_quat_rotate_vec3 (struct bj_vec4 q, struct bj_vec3 v)
static struct bj_vec4 bj_quat_rotate_vec4 (struct bj_vec4 q, struct bj_vec4 v)
static void bj_quat_to_mat4 (struct bj_mat4x4 *restrict M, struct bj_vec4 q)
static struct bj_vec4 bj_quat_from_mat4 (const struct bj_mat4x4 *restrict M)

Detailed Description

Quaternion manipulation API (by-value, struct bj_vec4-based).

Quaternions are stored in {x,y,z,w} layout where the vector part is (x,y,z) and the scalar part is w.

This header defines struct bj_vec4 as an alias of the 4D vector struct type struct bj_vec4 and exposes a by-value API: all quaternion arguments and return values use pass-by-value semantics for clarity and inlining friendliness.

Unless stated otherwise, angles are in radians, matrices are column-major as in struct bj_mat4x4, and inputs are not implicitly normalized except where explicitly noted.

Provided operations:

  • construction: identity, from axis-angle, from 4×4 rotation matrix
  • algebra: dot, norm, normalize, conjugate, inverse, Hamilton product, slerp
  • application: rotate 3D/4D vectors
  • conversion: to 4×4 rotation matrix

Numerical notes:

  • BJ_EPSILON is used to guard zero-length normalization and inversion.
  • bj_quat_slerp clamps inputs near ±1 and falls back to nlerp if needed.