84 return a.
x * b.
x + a.
y * b.
y + a.
z * b.
z + a.
w * b.
w;
130 return (
struct bj_vec4){ q.x * inv, q.y * inv, q.z * inv, q.w * inv };
148 return (
struct bj_vec4){ -q.x, -q.y, -q.z, q.w };
171 return (
struct bj_vec4){ -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 (
struct bj_vec4){ 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 (
struct 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:233
#define BJ_RESTRICT
BJ_RESTRICT expands to the appropriate restrict qualifier per toolchain.
Definition api.h:199
bj_real z
Definition vec.h:54
bj_real x
Definition vec.h:39
bj_real w
Definition vec.h:55
bj_real z
Definition vec.h:41
bj_real x
Definition vec.h:52
bj_real y
Definition vec.h:40
bj_real y
Definition vec.h:53
static struct bj_vec4 bj_quat_mul(struct bj_vec4 p, struct bj_vec4 q)
Hamilton product p * q.
Definition quat.h:185
static bj_real bj_quat_dot(struct bj_vec4 a, struct bj_vec4 b)
4D dot product between two quaternions.
Definition quat.h:80
static void bj_quat_to_mat4(struct bj_mat4x4 *restrict M, struct bj_vec4 q)
Fill a 4×4 rotation matrix from a quaternion.
Definition quat.h:337
static void bj_mat4_set_identity(struct bj_mat4x4 *restrict M)
Set a 4×4 matrix to identity.
Definition mat.h:664
static struct bj_vec4 bj_quat_normalize(struct bj_vec4 q)
Normalize a quaternion.
Definition quat.h:122
static struct bj_vec4 bj_quat_slerp(struct bj_vec4 a, struct bj_vec4 b, bj_real t)
Spherical linear interpolation between two orientations.
Definition quat.h:211
#define bj_acos
Arc cosine.
Definition math.h:209
#define bj_sin
Sine.
Definition math.h:221
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.
Definition quat.h:320
#define BJ_FZERO
Zero constant in bj_real.
Definition math.h:64
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.
Definition quat.h:270
static struct bj_vec4 bj_quat_conjugate(struct bj_vec4 q)
Conjugate of a quaternion.
Definition quat.h:145
static struct bj_vec3 bj_vec3_cross(struct bj_vec3 l, struct bj_vec3 r)
3D cross product: res = l × r (right-hand rule).
Definition vec.h:446
#define bj_cos
Cosine.
Definition math.h:212
static bj_real bj_quat_norm2(struct bj_vec4 q)
Squared Euclidean norm.
Definition quat.h:95
#define BJ_EPSILON
Machine epsilon for bj_real when float is selected.
Definition math.h:55
static struct bj_vec4 bj_quat_identity(void)
Return the identity quaternion.
Definition quat.h:64
static struct bj_vec3 bj_quat_rotate_vec3(struct bj_vec4 q, struct bj_vec3 v)
Rotate a 3D vector by a quaternion.
Definition quat.h:298
#define BJ_F(x)
Literal suffix helper for bj_real when float is selected.
Definition math.h:53
#define bj_sqrt
Square root.
Definition math.h:222
static struct bj_vec4 bj_quat_inverse(struct bj_vec4 q)
Multiplicative inverse of a quaternion.
Definition quat.h:163
float bj_real
Selected real type for float configuration.
Definition math.h:51
#define BJ_M4(c, r)
Definition mat.h:46
static bj_real bj_quat_norm(struct bj_vec4 q)
Euclidean norm (length).
Definition quat.h:107
static struct bj_vec4 bj_quat_from_mat4(const struct bj_mat4x4 *restrict M)
Build a quaternion from a 4×4 rotation matrix.
Definition quat.h:381
struct bj_mat4x4: 4×4 column-major matrix backed by struct bj_vec4.
Definition mat.h:43
struct bj_vec3: 3D vector of bj_real values.
Definition vec.h:38
struct 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.