77 return a.
x * b.
x + a.
y * b.
y + a.
z * b.
z + a.
w * b.
w;
123 return (
struct bj_vec4){ q.x * inv, q.y * inv, q.z * inv, q.w * inv };
141 return (
struct bj_vec4){ -q.x, -q.y, -q.z, q.w };
164 return (
struct bj_vec4){ -q.x * inv, -q.y * inv, -q.z * inv, q.w * inv };
183 p.w*q.x + p.x*q.w + p.y*q.z - p.z*q.y,
184 p.w*q.y - p.x*q.z + p.y*q.w + p.z*q.x,
185 p.w*q.z + p.x*q.y - p.y*q.x + p.z*q.w,
186 p.w*q.w - p.x*q.x - p.y*q.y - p.z*q.z
212 cos_omega = -cos_omega;
220 if (cos_omega >
BJ_F(1.0)) cos_omega =
BJ_F(1.0);
221 if (cos_omega < -
BJ_F(1.0)) cos_omega = -
BJ_F(1.0);
225 a.x + t*(bb.
x - a.x),
226 a.y + t*(bb.
y - a.y),
227 a.z + t*(bb.
z - a.z),
237 a.x + t*(bb.
x - a.x),
238 a.y + t*(bb.
y - a.y),
239 a.z + t*(bb.
z - a.z),
247 wa * a.x + wb * bb.
x,
248 wa * a.y + wb * bb.
y,
249 wa * a.z + wb * bb.
z,
267 const bj_real alen2 = axis.x*axis.x + axis.y*axis.y + axis.z*axis.z;
273 axis.
x * invlen, axis.y * invlen, axis.z * invlen
278 return (
struct bj_vec4){ n.
x * s, n.
y * s, n.
z * s, c };
297 t.
x += t.
x; t.
y += t.
y; t.
z += t.
z;
299 v.
x + q.w * t.
x + (u.
y * t.
z - u.
z * t.
y),
300 v.y + q.w * t.
y + (u.
z * t.
x - u.
x * t.
z),
301 v.z + q.w * t.
z + (u.
x * t.
y - u.
y * t.
x)
318 return (
struct bj_vec4){ .x = r3.
x, .y = r3.
y, .z = r3.
z, .w = v.w };
382 const bj_real trace = m00 + m11 + m22;
392 if (m00 > m11 && m00 > m22) {
399 }
else if (m11 > m22) {
General-purpose definitions for Banjo API.
#define BJ_INLINE
BJ_INLINE expands to an inline specifier appropriate for the toolchain.
#define BJ_RESTRICT
BJ_RESTRICT expands to the appropriate restrict qualifier per toolchain.
bj_real w
W component (scalar part for quaternions).
static struct bj_vec4 bj_quat_mul(struct bj_vec4 p, struct bj_vec4 q)
Hamilton product p * q.
static bj_real bj_quat_dot(struct bj_vec4 a, struct bj_vec4 b)
4D dot product between two quaternions.
static void bj_quat_to_mat4(struct bj_mat4x4 *restrict M, struct bj_vec4 q)
Fill a 4×4 rotation matrix from a quaternion.
static void bj_mat4_set_identity(struct bj_mat4x4 *restrict M)
Set a 4×4 matrix to identity.
static struct bj_vec4 bj_quat_normalize(struct bj_vec4 q)
Normalise a quaternion.
static struct bj_vec4 bj_quat_slerp(struct bj_vec4 a, struct bj_vec4 b, bj_real t)
Spherical linear interpolation between two orientations.
#define bj_acos
Arc cosine.
static struct bj_vec4 bj_quat_rotate_vec4(struct bj_vec4 q, struct bj_vec4 v)
Rotate a 4D vector by a quaternion, preserving w.
#define BJ_FZERO
Zero constant in bj_real.
static struct bj_vec4 bj_quat_from_axis_angle(struct bj_vec3 axis, bj_real angle_rad)
Build a quaternion from a rotation axis and angle.
static struct bj_vec4 bj_quat_conjugate(struct bj_vec4 q)
Conjugate of a quaternion.
static struct bj_vec3 bj_vec3_cross(struct bj_vec3 l, struct bj_vec3 r)
3D cross product: l × r (right-hand rule).
static bj_real bj_quat_norm2(struct bj_vec4 q)
Squared Euclidean norm.
#define BJ_EPSILON
Machine epsilon for bj_real when float is selected.
static struct bj_vec4 bj_quat_identity(void)
Return the identity quaternion.
static struct bj_vec3 bj_quat_rotate_vec3(struct bj_vec4 q, struct bj_vec3 v)
Rotate a 3D vector by a quaternion.
#define BJ_F(x)
Literal suffix helper for bj_real when float is selected.
#define bj_sqrt
Square root.
static struct bj_vec4 bj_quat_inverse(struct bj_vec4 q)
Multiplicative inverse of a quaternion.
float bj_real
Selected real type for float configuration.
#define BJ_M4(c, r)
Index a 4×4 matrix element at column c, row r. 0 <= c,r < 4.
static bj_real bj_quat_norm(struct bj_vec4 q)
Euclidean norm (length).
static struct bj_vec4 bj_quat_from_mat4(const struct bj_mat4x4 *restrict M)
Build a quaternion from a 4×4 rotation matrix.
3D vector of bj_real components.
4D vector of bj_real components.
Matrix types and operations for 2D and 3D transforms.
C99 math shim with bj_real precision type and scalar utilities.
Fixed-size vector types (2D, 3D, 4D) and inline operations.