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.

Typedefs

typedef struct bj_vec4_t bj_quat

Functions

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

Detailed Description

Quaternion manipulation API (by-value, bj_vec4_t-based).

Quaternion manipulation API.

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 bj_quat as an alias of the 4D vector struct type bj_vec4_t 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 bj_mat4, 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.