Banjo API 1.0.0-rc.2
Low-level 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, sharing struct bj_vec4 storage).

Quaternions and 4D vectors have the same shape (four bj_real components) so Banjo reuses bj_vec4 as the storage for both rather than introducing a parallel struct. A quaternion q has its vector part in q.x, q.y, q.z and its scalar part in q.w. The bj_quat_* functions in this header treat that layout as a quaternion and apply rotation algebra; the bj_vec4_* functions in vec.h treat the same bytes as a 4D vector and apply linear algebra. (The public typedef bj_quat in <banjo/api.h> is an alias for the same struct bj_vec4, available when BJ_NO_TYPEDEF isn't defined.)

The API is pass-by-value: every quaternion argument and return is a struct bj_vec4 taken or returned by copy, which suits the 4-component size and lets the compiler inline aggressively.

Conventions:

  • Angles are in radians.
  • Matrices are column-major (bj_mat4x4).
  • Inputs are not implicitly normalised unless a function says so.
  • BJ_EPSILON guards zero-length normalisation and inversion.
  • bj_quat_slerp clamps near ±1 and falls back to nlerp on nearly-parallel inputs.

What's provided:

  • Construction: identity, from axis-angle, from 4×4 rotation matrix.
  • Algebra: dot, norm, normalise, conjugate, inverse, Hamilton product, slerp.
  • Application: rotate 3D/4D vectors.
  • Conversion: to 4×4 rotation matrix.
See also
vec.h for 4D vector operations on the same storage, mat.h for the matrix counterpart of every rotation.

Definition in file quat.h.