84 return a.
x * b.
x + a.
y * b.
y + a.
z * b.
z + a.
w * b.
w;
130 return (
bj_quat){ q.
x * inv, q.
y * inv, q.
z * inv, q.
w * inv };
171 return (
bj_quat){ -q.
x * inv, -q.
y * inv, -q.
z * inv, q.
w * inv };
190 p.
w*q.
x + p.
x*q.
w + p.
y*q.
z - p.
z*q.
y,
191 p.
w*q.
y - p.
x*q.
z + p.
y*q.
w + p.
z*q.
x,
192 p.
w*q.
z + p.
x*q.
y - p.
y*q.
x + p.
z*q.
w,
193 p.
w*q.
w - p.
x*q.
x - p.
y*q.
y - p.
z*q.
z
219 cos_omega = -cos_omega;
227 if (cos_omega >
BJ_F(1.0)) cos_omega =
BJ_F(1.0);
228 if (cos_omega < -
BJ_F(1.0)) cos_omega = -
BJ_F(1.0);
232 a.
x + t*(bb.
x - a.
x),
233 a.
y + t*(bb.
y - a.
y),
234 a.
z + t*(bb.
z - a.
z),
244 a.
x + t*(bb.
x - a.
x),
245 a.
y + t*(bb.
y - a.
y),
246 a.
z + t*(bb.
z - a.
z),
254 wa * a.
x + wb * bb.
x,
255 wa * a.
y + wb * bb.
y,
256 wa * a.
z + wb * bb.
z,
274 const bj_real alen2 = axis.
x*axis.
x + axis.
y*axis.
y + axis.
z*axis.
z;
280 axis.
x * invlen, axis.
y * invlen, axis.
z * invlen
285 return (
bj_quat){ n.
x * s, n.
y * s, n.
z * s, c };
304 t.
x += t.
x; t.
y += t.
y; t.
z += t.
z;
306 v.
x + q.
w * t.
x + (u.
y * t.
z - u.
z * t.
y),
307 v.
y + q.
w * t.
y + (u.
z * t.
x - u.
x * t.
z),
308 v.
z + q.
w * t.
z + (u.
x * t.
y - u.
y * t.
x)
325 return (
bj_vec4){ .x = r3.
x, .y = r3.
y, .z = r3.
z, .w = v.
w };
389 const bj_real trace = m00 + m11 + m22;
399 if (m00 > m11 && m00 > m22) {
406 }
else if (m11 > m22) {
General-purpose definitions for Banjo API.
#define BJ_INLINE
BJ_INLINE expands to an inline specifier appropriate for the toolchain.
Definition api.h:217
#define BJ_RESTRICT
BJ_RESTRICT expands to the appropriate restrict qualifier per toolchain.
Definition api.h:183
bj_real y
Definition vec.h:40
bj_real z
Definition vec.h:54
bj_real x
Definition vec.h:52
bj_real y
Definition vec.h:53
bj_real x
Definition vec.h:39
bj_real z
Definition vec.h:41
bj_real w
Definition vec.h:55
struct bj_vec3_t bj_vec3
Definition vec.h:43
static bj_real bj_quat_norm2(bj_quat q)
Squared Euclidean norm.
Definition quat.h:95
static bj_vec4 bj_quat_rotate_vec4(bj_quat q, bj_vec4 v)
Rotate a 4D vector by a quaternion, preserving w.
Definition quat.h:320
struct bj_mat4x4_t bj_mat4
Definition mat.h:45
static bj_quat bj_quat_mul(bj_quat p, bj_quat q)
Hamilton product p * q.
Definition quat.h:185
struct bj_vec4_t bj_vec4
Definition vec.h:57
#define bj_acos
Arc cosine.
Definition math.h:209
#define bj_sin
Sine.
Definition math.h:221
struct bj_vec4_t bj_quat
Quaternion type alias based on the 4D vector struct.
Definition quat.h:52
static bj_vec3 bj_quat_rotate_vec3(bj_quat q, bj_vec3 v)
Rotate a 3D vector by a quaternion.
Definition quat.h:298
static bj_quat bj_quat_slerp(bj_quat a, bj_quat b, bj_real t)
Spherical linear interpolation between two orientations.
Definition quat.h:211
static bj_quat bj_quat_normalize(bj_quat q)
Normalize a quaternion.
Definition quat.h:122
static bj_quat bj_quat_inverse(bj_quat q)
Multiplicative inverse of a quaternion.
Definition quat.h:163
#define BJ_FZERO
Zero constant in bj_real.
Definition math.h:64
static bj_quat bj_quat_identity(void)
Return the identity quaternion.
Definition quat.h:64
static bj_vec3 bj_vec3_cross(bj_vec3 l, bj_vec3 r)
3D cross product: res = l × r (right-hand rule).
Definition vec.h:453
#define bj_cos
Cosine.
Definition math.h:212
static bj_real bj_quat_norm(bj_quat q)
Euclidean norm (length).
Definition quat.h:107
static bj_quat bj_quat_from_mat4(const bj_mat4 *restrict M)
Build a quaternion from a 4×4 rotation matrix.
Definition quat.h:381
#define BJ_EPSILON
Machine epsilon for bj_real when float is selected.
Definition math.h:55
static bj_real bj_quat_dot(bj_quat a, bj_quat b)
4D dot product between two quaternions.
Definition quat.h:80
static void bj_mat4_set_identity(bj_mat4 *restrict M)
Set a 4×4 matrix to identity.
Definition mat.h:664
#define BJ_F(x)
Literal suffix helper for bj_real when float is selected.
Definition math.h:53
static void bj_quat_to_mat4(bj_mat4 *restrict M, bj_quat q)
Fill a 4×4 rotation matrix from a quaternion.
Definition quat.h:337
#define bj_sqrt
Square root.
Definition math.h:222
float bj_real
Selected real type for float configuration.
Definition math.h:51
static bj_quat bj_quat_conjugate(bj_quat q)
Conjugate of a quaternion.
Definition quat.h:145
#define BJ_M4(c, r)
Definition mat.h:46
static bj_quat bj_quat_from_axis_angle(bj_vec3 axis, bj_real angle_rad)
Build a quaternion from a rotation axis and angle.
Definition quat.h:270
bj_vec4: 4D vector of bj_real values.
Definition vec.h:51
C99 math shim with bj_real precision type and scalar utilities.
C99 math shim with bj_real precision type and scalar utilities.