|
Banjo API 0.0.1
C99 game development API
|

Topics | |
| Geometry 2D | |
Data Structures | |
| struct | bj_mat3x3_t |
| struct | bj_mat3x2_t |
| struct | bj_mat4x4_t |
| struct | bj_mat4x3_t |
| struct | bj_rect_t |
| struct | bj_vec2_t |
| struct | bj_vec3_t |
| struct | bj_vec4_t |
Macros | |
| #define | BJ_M3(c, r) |
| #define | BJ_M32(c, r) |
| #define | BJ_M4(c, r) |
| #define | BJ_M43(c, r) |
| #define | BJ_VEC2_ZERO ((bj_vec2){BJ_FZERO, BJ_FZERO}) |
| #define | BJ_VEC3_ZERO ((bj_vec3){BJ_FZERO, BJ_FZERO, BJ_FZERO}) |
| #define | BJ_VEC4_ZERO ((bj_vec4){BJ_FZERO, BJ_FZERO, BJ_FZERO, BJ_FZERO}) |
Typedefs | |
| typedef struct bj_mat3x3_t | bj_mat3x3 |
| typedef struct bj_mat3x3_t | bj_mat3 |
| typedef struct bj_mat3x2_t | bj_mat3x2 |
| typedef struct bj_mat4x4_t | bj_mat4x4 |
| typedef struct bj_mat4x4_t | bj_mat4 |
| typedef struct bj_mat4x3_t | bj_mat4x3 |
| typedef struct bj_vec4_t | bj_quat |
| typedef struct bj_rect_t | bj_rect |
| typedef struct bj_vec2_t | bj_vec2 |
| typedef struct bj_vec3_t | bj_vec3 |
| typedef struct bj_vec4_t | bj_vec4 |
Real type selection and helpers | |
| typedef float | bj_real |
| #define | BJ_F(x) |
| #define | BJ_EPSILON (FLT_EPSILON) |
| #define | BJ_FI(x) |
| #define | BJ_FZERO (BJ_F(0.0)) |
Scalar utilities | |
Generic scalar helpers. All arguments and results are bj_real. | |
| static bj_real | bj_clamp (bj_real x, bj_real lo, bj_real hi) |
| static bj_real | bj_step (bj_real edge, bj_real x) |
| static bj_real | bj_smoothstep (bj_real e0, bj_real e1, bj_real x) |
| static bj_real | bj_fract (bj_real x) |
| static bj_real | bj_mod (bj_real x, bj_real y) |
Absolute-epsilon comparisons | |
Comparisons using BJ_EPSILON as an absolute tolerance. | |
| static int | bj_real_eq (bj_real a, bj_real b) |
| static int | bj_real_neq (bj_real a, bj_real b) |
| static int | bj_real_lt (bj_real a, bj_real b) |
| static int | bj_real_gt (bj_real a, bj_real b) |
| static int | bj_real_lte (bj_real a, bj_real b) |
| static int | bj_real_gte (bj_real a, bj_real b) |
| static int | bj_real_cmp (bj_real a, bj_real b) |
Relative-epsilon comparisons | |
Comparisons using a scale-dependent tolerance. | |
| static bj_real | bj_real_relative_scale (bj_real a, bj_real b) |
| static int | bj_real_eq_rel (bj_real a, bj_real b) |
| static int | bj_real_neq_rel (bj_real a, bj_real b) |
| static int | bj_real_lt_rel (bj_real a, bj_real b) |
| static int | bj_real_gt_rel (bj_real a, bj_real b) |
| static int | bj_real_lte_rel (bj_real a, bj_real b) |
| static int | bj_real_gte_rel (bj_real a, bj_real b) |
| static int | bj_real_cmp_rel (bj_real a, bj_real b) |
Zero tests and helpers | |
Utilities for zero checks and safe normalization. | |
| static int | bj_real_is_zero (bj_real x) |
| static int | bj_real_is_zero_scaled (bj_real x, bj_real scale) |
| static bj_real | bj_real_snap_zero (bj_real x) |
| static bj_real | bj_real_snorm_safe (bj_real x, bj_real len) |
Circle constants | |
| #define | BJ_PI_F (3.14159265358979323846f) |
| #define | BJ_TAU_F (6.28318530717958647692f) |
| #define | BJ_PI_D (3.14159265358979323846264338327950288) |
| #define | BJ_TAU_D (6.28318530717958647692528676655900576) |
| #define | BJ_PI_L (3.141592653589793238462643383279502884L) |
| #define | BJ_TAU_L (6.283185307179586476925286766559005768L) |
| #define | BJ_PI (BJ_F(3.141592653589793238462643383279502884)) |
| #define | BJ_TAU (BJ_F(6.283185307179586476925286766559005768)) |
Typed wrappers (float) | |
Thin aliases to <math.h> float functions. | |
| #define | bj_absf fabsf |
| #define | bj_acosf acosf |
| #define | bj_atan2f atan2f |
| #define | bj_copysignf copysignf |
| #define | bj_cosf cosf |
| #define | bj_expf expf |
| #define | bj_floorf floorf |
| #define | bj_fmodf fmodf |
| #define | bj_logf logf |
| #define | bj_maxf fmaxf |
| #define | bj_minf fminf |
| #define | bj_powf powf |
| #define | bj_roundf roundf |
| #define | bj_sinf sinf |
| #define | bj_sqrtf sqrtf |
| #define | bj_tanf tanf |
Typed wrappers (double) | |
Thin aliases to <math.h> double functions. | |
| #define | bj_absd fabs |
| #define | bj_acosd acos |
| #define | bj_atan2d atan2 |
| #define | bj_copysignd copysign |
| #define | bj_cosd cos |
| #define | bj_expd exp |
| #define | bj_floord floor |
| #define | bj_fmodd fmod |
| #define | bj_logd log |
| #define | bj_maxd fmax |
| #define | bj_mind fmin |
| #define | bj_powd pow |
| #define | bj_roundd round |
| #define | bj_sind sin |
| #define | bj_sqrtd sqrt |
| #define | bj_tand tan |
Typed wrappers (long double) | |
Thin aliases to <math.h> long double functions. | |
| #define | bj_absl fabsl |
| #define | bj_acosl acosl |
| #define | bj_atan2l atan2l |
| #define | bj_copysignl copysignl |
| #define | bj_cosl cosl |
| #define | bj_expl expl |
| #define | bj_floorl floorl |
| #define | bj_fmodl fmodl |
| #define | bj_logl logl |
| #define | bj_maxl fmaxl |
| #define | bj_minl fminl |
| #define | bj_powl powl |
| #define | bj_roundl roundl |
| #define | bj_sinl sinl |
| #define | bj_sqrtl sqrtl |
| #define | bj_tanl tanl |
Precision-dispatch to match bj_real | |
Map generic bj_* names to the active precision. | |
| #define | bj_abs bj_absf |
| #define | bj_acos bj_acosf |
| #define | bj_atan2 bj_atan2f |
| #define | bj_copysign bj_copysignf |
| #define | bj_cos bj_cosf |
| #define | bj_exp bj_expf |
| #define | bj_floor bj_floorf |
| #define | bj_fmod bj_fmodf |
| #define | bj_log bj_logf |
| #define | bj_max bj_maxf |
| #define | bj_min bj_minf |
| #define | bj_pow bj_powf |
| #define | bj_round bj_roundf |
| #define | bj_sin bj_sinf |
| #define | bj_sqrt bj_sqrtf |
| #define | bj_tan bj_tanf |
Math utilities (precision abstraction, constants, scalar functions).
This header provides:
All functions are thin wrappers around <math.h> with consistent naming and precision handling. They are dimensionless utilities: values are treated as pure scalars without physical units.
| struct bj_mat3x3_t |
| Data Fields | ||
|---|---|---|
| bj_real | m[9] | |
| struct bj_mat3x2_t |
| struct bj_mat4x4_t |
| struct bj_mat4x3_t |
| struct bj_rect_t |
| struct bj_vec2_t |
| struct bj_vec3_t |
| struct bj_vec4_t |
| #define bj_abs bj_absf |
Absolute value.
| #define bj_absd fabs |
Absolute value (double)
| #define bj_absf fabsf |
Absolute value (float)
| #define bj_absl fabsl |
Absolute value (long double)
| #define bj_acos bj_acosf |
Arc cosine.
| #define bj_acosd acos |
Arc cosine (double)
| #define bj_acosf acosf |
Arc cosine (float)
| #define bj_acosl acosl |
Arc cosine (long double)
| #define bj_atan2 bj_atan2f |
Arc tangent.
| #define bj_atan2d atan2 |
Arc tangent (float)
| #define bj_atan2f atan2f |
Arc tangent (float)
| #define bj_atan2l atan2l |
Arc tangent (float)
| #define bj_copysign bj_copysignf |
Copy sign.
| #define bj_copysignd copysign |
Copy sign (double)
| #define bj_copysignf copysignf |
Copy sign (float)
| #define bj_copysignl copysignl |
Copy sign (long double)
| #define bj_cos bj_cosf |
Cosine.
| #define bj_cosd cos |
Cosine (double)
| #define bj_cosf cosf |
Cosine (float)
| #define bj_cosl cosl |
Cosine (long double)
| #define BJ_EPSILON (FLT_EPSILON) |
Machine epsilon for bj_real when float is selected.
| #define bj_exp bj_expf |
Exponential.
| #define bj_expd exp |
Exponential (double)
| #define bj_expf expf |
Exponential (float)
| #define bj_expl expl |
Exponential (long double)
| #define BJ_F | ( | x | ) |
Literal suffix helper for bj_real when float is selected.
| #define BJ_FI | ( | x | ) |
| #define bj_floor bj_floorf |
Floor.
| #define bj_floord floor |
Floor (double)
| #define bj_floorf floorf |
Floor (float)
| #define bj_floorl floorl |
Floor (long double)
| #define bj_fmod bj_fmodf |
Floating modulus.
| #define bj_fmodd fmod |
Floating modulus (double)
| #define bj_fmodf fmodf |
Floating modulus (float)
| #define bj_fmodl fmodl |
Floating modulus (long double)
| #define bj_log bj_logf |
Natural logarithm.
| #define bj_logd log |
Natural log (double)
| #define bj_logf logf |
Natural log (float)
| #define bj_logl logl |
Natural log (long double)
| #define BJ_M3 | ( | c, | |
| r ) |
| #define BJ_M32 | ( | c, | |
| r ) |
| #define BJ_M4 | ( | c, | |
| r ) |
| #define BJ_M43 | ( | c, | |
| r ) |
| #define bj_max bj_maxf |
Maximum of two floats.
| #define bj_maxd fmax |
Maximum of two doubles.
| #define bj_maxf fmaxf |
Maximum of two floats.
| #define bj_maxl fmaxl |
Maximum of two long doubles.
| #define bj_min bj_minf |
Minimum of two floats.
| #define bj_mind fmin |
Minimum of two doubles.
| #define bj_minf fminf |
Minimum of two floats.
| #define bj_minl fminl |
Minimum of two long doubles.
| #define BJ_PI_D (3.14159265358979323846264338327950288) |
Double-precision PI.
| #define BJ_PI_F (3.14159265358979323846f) |
Single-precision PI.
| #define BJ_PI_L (3.141592653589793238462643383279502884L) |
Long-double PI.
| #define bj_pow bj_powf |
Power.
| #define bj_powd pow |
Power (double)
| #define bj_powf powf |
Power (float)
| #define bj_powl powl |
Power (long double)
| #define bj_round bj_roundf |
Round to nearest integer.
| #define bj_roundd round |
Round to nearest (double)
| #define bj_roundf roundf |
Round to nearest (float)
| #define bj_roundl roundl |
Round to nearest (long double)
| #define bj_sin bj_sinf |
Sine.
| #define bj_sind sin |
Sine (double)
| #define bj_sinf sinf |
Sine (float)
| #define bj_sinl sinl |
Sine (long double)
| #define bj_sqrt bj_sqrtf |
Square root.
| #define bj_sqrtd sqrt |
Square root (double)
| #define bj_sqrtf sqrtf |
Square root (float)
| #define bj_sqrtl sqrtl |
Square root (long double)
| #define bj_tan bj_tanf |
Tangent.
| #define bj_tand tan |
Tangent (double)
| #define bj_tanf tanf |
Tangent (float)
| #define bj_tanl tanl |
Tangent (long double)
| #define BJ_TAU (BJ_F(6.283185307179586476925286766559005768)) |
TAU in the selected bj_real precision.
| #define BJ_TAU_D (6.28318530717958647692528676655900576) |
Double-precision TAU (2 * PI).
| #define BJ_TAU_F (6.28318530717958647692f) |
Single-precision TAU (2 * PI).
| #define BJ_TAU_L (6.283185307179586476925286766559005768L) |
Long-double TAU (2 * PI).
| typedef struct bj_mat3x3_t bj_mat3 |
| typedef struct bj_mat3x2_t bj_mat3x2 |
| typedef struct bj_mat3x3_t bj_mat3x3 |
| typedef struct bj_mat4x4_t bj_mat4 |
| typedef struct bj_mat4x3_t bj_mat4x3 |
| typedef struct bj_mat4x4_t bj_mat4x4 |
| typedef float bj_real |
Selected real type for float configuration.
Clamp x to the closed interval [lo, hi].
| x | Input value |
| lo | Lower bound |
| hi | Upper bound |
Fractional part of x.
| x | Input value |
|
inlinestatic |
Component-wise addition: out = A + B.
| out | Output 3×3 matrix. |
| A | Input 3×3 matrix. |
| B | Input 3×3 matrix. |
Extract a matrix column as a vector.
| M | Input 3×3 matrix. |
| c | index (0-based). |
Copy a matrix.
| dst | Output 3×3 matrix. |
| src | Input 3×3 matrix. |
Promote a 3×2 affine matrix to 3×3.
| M | Output 3×3 matrix. |
| A | Input 3×2 matrix. |
Invert a 3×3 matrix (safe, adjugate).
Computes A^{-1} = adj(A) / det(A). If det(A) is zero by bj_real_is_zero, returns 0 and leaves out unspecified.
| out | Output 3×3 matrix. |
| A | Input 3×3 matrix. |
Invert a 3×3 matrix (unsafe, adjugate).
Same as bj_mat3_invert but skips the singularity check and divides by det(A) unconditionally. Faster when invertibility is guaranteed.
| out | Output 3×3 matrix. |
| A | Input 3×3 matrix (must be nonsingular). |
|
inlinestatic |
Matrix product: out = A * B.
| out | Output 3×3 matrix. |
| A | Input 3×3 matrix. |
| B | Input 3×3 matrix. |
|
inlinestatic |
Scalar multiply: out = A * k.
| out | Output 3×3 matrix. |
| A | Input 3×3 matrix. |
| k | Uniform scale factor. |
Extract a matrix row as a vector.
| M | Input 3×3 matrix. |
| r | index (0-based). |
|
inlinestatic |
Set a 3×3 matrix to identity.
| M | Output 3×3 matrix. |
|
inlinestatic |
Build a 2D orthographic projection into a 3×3 matrix.
| M | Output 3×3 matrix. |
| l | Input scalar. |
| r | scalar (0-based). |
| b | Input scalar. |
| t | Input scalar. |
Matrix operation.
| M | Output 3×3 matrix. |
| angle | Rotation angle in radians. |
Apply non-uniform XY scale to a 3×3 matrix.
| M | Output 3×3 matrix. |
| sx | Scale on x. |
| sy | Scale on y. |
Build an XY shear into a 3×3 matrix.
| M | Output 3×3 matrix. |
| shx | Input scalar. |
| shy | Input scalar. |
Build a 3×3 translation matrix.
| M | Output 3×3 matrix. |
| tx | Translation along x. |
| ty | Translation along y. |
|
inlinestatic |
Build a 2D viewport transform into a 3×3 matrix.
| M | Output 3×3 matrix. |
| x | Viewport X origin in pixels. |
| y | Viewport Y origin in pixels. |
| w | Viewport width in pixels. |
| h | Viewport height in pixels. |
|
inlinestatic |
Component-wise subtraction: out = A - B.
| out | Output 3×3 matrix. |
| A | Input 3×3 matrix. |
| B | Input 3×3 matrix. |
Transform a 2D point by a 3×3 homogeneous transform.
| M | Input 3×3 matrix. |
| p | Input point. |
Multiply a 3×3 matrix by a 3D vector: r = M * v.
| M | Input 3×3 matrix. |
| v | Input vector. |
Right-multiply by a translation: M = M * T(tx,ty).
| M | Output 3×3 matrix. |
| tx | Translation along x. |
| ty | Translation along y. |
Transpose a matrix.
| out | Output 3×3 matrix. |
| A | Input 3×3 matrix. |
Demote a 3×3 matrix to 3×2 (drop projective terms).
| M | Output 3×2 matrix. |
| A | Input 3×3 matrix. |
|
inlinestatic |
Matrix product: out = A * B.
| out | Output 3×2 matrix. |
| A | Input 3×2 matrix. |
| B | Input 3×2 matrix. |
|
inlinestatic |
Set a 3×2 affine matrix to identity.
| M | Output 3×2 matrix. |
Matrix operation.
| M | Output 3×2 matrix. |
| angle | Rotation angle in radians. |
Scalar multiply: M = sx * k.
| M | Output 3×2 matrix. |
| sx | Scale on x. |
| sy | Scale on y. |
Matrix operation.
| M | Output 3×2 matrix. |
| tx | Translation along x. |
| ty | Translation along y. |
Transform a direction vector (ignoring translation).
| M | Input 3×2 matrix. |
| v | Input vector. |
Transform a 2D point by a 3×2 affine matrix.
| M | Input 3×2 matrix. |
| p | Input point. |
|
inlinestatic |
Component-wise addition: out = A + B.
| out | Output 4×4 matrix. |
| A | Input 4×4 matrix. |
| B | Input 4×4 matrix. |
Extract a matrix column as a vector.
| M | Input 4×4 matrix. |
| c | index (0-based). |
Copy a matrix.
| dst | Output 4×4 matrix. |
| src | Input 4×4 matrix. |
Promote a 4×3 affine matrix to 4×4.
| M | Output 4×4 matrix. |
| A | Input 4×3 matrix. |
Invert a 4×4 matrix (safe).
Computes A^{-1} via cofactors. If det(A) is zero by bj_real_is_zero, returns 0 and leaves out unspecified.
| out | Output 4×4 matrix. |
| M | Input 4×4 matrix. |
Invert a 4×4 matrix (unsafe).
Same as bj_mat4_invert but skips the singularity check and divides by det(A) unconditionally.
| out | Output 4×4 matrix. |
| M | Input 4×4 matrix (must be nonsingular). |
|
inlinestatic |
Matrix product: out = A * B.
| out | Output 4×4 matrix. |
| A | Input 4×4 matrix. |
| B | Input 4×4 matrix. |
|
inlinestatic |
Scalar multiply: out = A * k.
| out | Output 4×4 matrix. |
| A | Input 4×4 matrix. |
| k | Uniform scale factor. |
Orthonormalize the 3×3 linear part of a 4×4 matrix.
| out | Output 4×4 matrix. |
| A | Input 4×4 matrix. |
|
inlinestatic |
Build a 4×4 rotation from two unit vectors (arcball).
| R | Output 4×4 matrix. |
| M | Input 4×4 matrix. |
| a | Input 2D vector. |
| b | Input 2D vector. |
| s | Scale factors as a vector. |
|
inlinestatic |
Right-multiply a 4×4 by a rotation around an arbitrary axis.
| out | Output 4×4 matrix. |
| M | Input 4×4 matrix. |
| axis | Unit axis of rotation. |
| angle | Rotation angle in radians. |
Right-multiply by an X-axis rotation.
| out | Output 4×4 matrix. |
| M | Input 4×4 matrix. |
| a | Input scalar. |
Right-multiply by a Y-axis rotation.
| out | Output 4×4 matrix. |
| M | Input 4×4 matrix. |
| a | Input scalar. |
Right-multiply by a Z-axis rotation.
| out | Output 4×4 matrix. |
| M | Input 4×4 matrix. |
| a | Input scalar. |
Extract a matrix row as a vector.
| M | Input 4×4 matrix. |
| r | index (0-based). |
|
inlinestatic |
Scale basis vectors of a 4×4 matrix by per-axis factors.
| out | Output 4×4 matrix. |
| A | Input 4×4 matrix. |
| sx | Scale on x. |
| sy | Scale on y. |
| sz | Scale on z. |
|
inlinestatic |
Build a perspective frustum into a 4×4 matrix.
| M | Output 4×4 matrix. |
| l | Input scalar. |
| r | scalar (0-based). |
| b | Input scalar. |
| t | Input scalar. |
| n | Near plane distance. |
| f | Far plane distance. |
|
inlinestatic |
Set a 4×4 matrix to identity.
| M | Output 4×4 matrix. |
|
inlinestatic |
Build a right-handed look-at view matrix.
| M | Output 4×4 matrix. |
| eye | Camera position. |
| center | Target point the camera looks at. |
| up | Approximate up direction. |
|
inlinestatic |
Build a 3D orthographic projection into a 4×4 matrix.
| M | Output 4×4 matrix. |
| l | Input scalar. |
| r | scalar (0-based). |
| b | Input scalar. |
| t | Input scalar. |
| n | Near plane distance. |
| f | Far plane distance. |
Add outer product r += s * v^T to a 4×4 matrix.
| out | Output 4×4 matrix. |
| a | Input 3D vector. |
| b | Input 3D vector. |
|
inlinestatic |
Build a 4×4 perspective projection from vertical FOV.
| M | Output 4×4 matrix. |
| y_fov | Vertical field of view in radians. |
| aspect | Aspect ratio width/height. |
| n | Near plane distance. |
| f | Far plane distance. |
Build a 4×4 translation matrix.
| M | Output 4×4 matrix. |
| x | Viewport X origin in pixels. |
| y | Viewport Y origin in pixels. |
| z | Input scalar. |
|
inlinestatic |
Build a 3D viewport transform into a 4×4 matrix.
| M | Output 4×4 matrix. |
| x | Viewport X origin in pixels. |
| y | Viewport Y origin in pixels. |
| w | Viewport width in pixels. |
| h | Viewport height in pixels. |
|
inlinestatic |
Component-wise subtraction: out = A - B.
| out | Output 4×4 matrix. |
| A | Input 4×4 matrix. |
| B | Input 4×4 matrix. |
Multiply a 4×4 matrix by a 4D vector: r = M * v.
| M | Input 4×4 matrix. |
| v | Input vector. |
Right-multiply by a translation: M = M * T(tx,ty,tz).
| M | Output 4×4 matrix. |
| x | Viewport X origin in pixels. |
| y | Viewport Y origin in pixels. |
| z | Input scalar. |
Transpose a matrix.
| out | Output 4×4 matrix. |
| A | Input 4×4 matrix. |
Demote a 4×4 matrix to 4×3 (drop projective terms).
| M | Output 4×3 matrix. |
| A | Input 4×4 matrix. |
|
inlinestatic |
Matrix product: out = A * B.
| out | Output 4×3 matrix. |
| A | Input 4×3 matrix. |
| B | Input 4×3 matrix. |
|
inlinestatic |
Set a 4×3 affine matrix to identity.
| M | Output 4×3 matrix. |
Right-multiply by an X-axis rotation.
| M | Output 4×3 matrix. |
| a | Input scalar. |
Right-multiply by a Y-axis rotation.
| M | Output 4×3 matrix. |
| a | Input scalar. |
Right-multiply by a Z-axis rotation.
| M | Output 4×3 matrix. |
| a | Input scalar. |
|
inlinestatic |
Scalar multiply: M = sx * k.
| M | Output 4×3 matrix. |
| sx | Scale on x. |
| sy | Scale on y. |
| sz | Scale on z. |
|
inlinestatic |
Matrix operation.
| M | Output 4×3 matrix. |
| tx | Translation along x. |
| ty | Translation along y. |
| tz | Translation along z. |
Transform a direction vector (ignoring translation).
| M | Input 4×3 matrix. |
| v | Input vector. |
Transform a 3D point by a 4×3 affine matrix.
| M | Input 4×3 matrix. |
| p | Input point. |
Positive modulus with non-negative result magnitude.
| x | Dividend |
| y | Divisor (must be non-zero) |
Conjugate of a quaternion.
Negates the vector part and keeps the scalar part: conj(q) = {-x,-y,-z,w}.
| q | Quaternion. |
4D dot product between two quaternions.
| a | First quaternion. |
| b | Second quaternion. |
a·b.cos(theta) where theta is the half-angle between orientations used by bj_quat_slerp. Build a quaternion from a rotation axis and angle.
| axis | Rotation axis. Need not be unit length. |
| angle_rad | Rotation angle in radians. |
Build a quaternion from a 4×4 rotation matrix.
Only the upper-left 3×3 block is used. Assumes it encodes a proper rotation. The result is normalized.
| M | Source 4×4 matrix (column-major). |
|
inlinestatic |
Return the identity quaternion.
Represents a no-rotation. Equivalent to {0,0,0,1}.
Multiplicative inverse of a quaternion.
Returns identity if the squared norm is near zero (<= BJ_EPSILON). Otherwise q^{-1} = conj(q) / ||q||^2.
| q | Quaternion. |
Hamilton product p * q.
Composition order follows standard Hamilton convention. When used to rotate vectors via v' = q * v * q^{-1}, apply q on the left.
| p | Left quaternion. |
| q | Right quaternion. |
p*q. Euclidean norm (length).
| q | Quaternion. |
||q||. Squared Euclidean norm.
| q | Quaternion. |
||q||^2.Normalize a quaternion.
Returns identity if the input length is near zero (<= BJ_EPSILON).
| q | Quaternion. |
Rotate a 3D vector by a quaternion.
| q | Rotation quaternion. Expected to be unit length for pure rotation. |
| v | Vector to rotate. |
q is not normalized inside the function. Call bj_quat_normalize beforehand if needed. Rotate a 4D vector by a quaternion, preserving w.
| q | Rotation quaternion. Expected to be unit length for pure rotation. |
| v | Vector to rotate. Its w component is passed through unchanged. |
w. Spherical linear interpolation between two orientations.
Interpolates along the shortest arc on S^3. If inputs are nearly parallel, falls back to normalized linear interpolation to avoid divide-by-zero.
| a | Start quaternion. |
| b | End quaternion. |
| t | Interpolation factor in [0,1]. |
Fill a 4×4 rotation matrix from a quaternion.
| [out] | M | Destination matrix (column-major). |
| [in] | q | Input quaternion. It is normalized internally. |
Three-way compare using absolute epsilon.
| a | First value |
| b | Second value |
Three-way compare using relative epsilon.
| a | First value |
| b | Second value |
Equality within absolute epsilon.
| a | First value |
| b | Second value |
Equality within relative epsilon.
| a | First value |
| b | Second value |
a > b by more than absolute epsilon.
| a | First value |
| b | Second value |
a > b by more than relative epsilon.
| a | First value |
| b | Second value |
a >= b within absolute epsilon.
| a | First value |
| b | Second value |
a >= b within relative epsilon.
| a | First value |
| b | Second value |
|
inlinestatic |
Absolute-zero test.
| x | Input value |
Scaled zero test using max(1, |scale|).
| x | Input value |
| scale | Scale reference |
a < b by more than absolute epsilon.
| a | First value |
| b | Second value |
a < b by more than relative epsilon.
| a | First value |
| b | Second value |
a <= b within absolute epsilon.
| a | First value |
| b | Second value |
a <= b within relative epsilon.
| a | First value |
| b | Second value |
Inequality within absolute epsilon.
| a | First value |
| b | Second value |
Inequality within relative epsilon.
| a | First value |
| b | Second value |
Internal scale helper max(1, |a|, |b|).
| a | First value |
| b | Second value |
Snap to exact zero under absolute epsilon.
| x | Input value |
Safe scalar normalization.
| x | Numerator |
| len | Denominator magnitude |
| bj_bool bj_rect_intersection | ( | const bj_rect * | p_rect_a, |
| const bj_rect * | p_rect_b, | ||
| bj_rect * | p_result ) |
Computes the intersection of two bj_rect.
| p_rect_a | Pointer to the first rectangle. Must not be 0. |
| p_rect_b | Pointer to the second rectangle. Must not be 0. |
| p_result | Pointer to the rectangle where the result will be stored. Can be 0 if only checking intersection presence. |
p_result is 0, the function only checks for intersection presence and does not compute the intersection rectangle.Example usage:
Smooth Hermite step between e0 and e1.
Clamps t to [0,1].
| e0 | Start edge |
| e1 | End edge |
| x | Input value |
Step function.
| edge | Threshold edge |
| x | Input value |
Component-wise addition of two 2D vectors: res = lhs + rhs.
| lhs | Left-hand input vector. |
| rhs | Right-hand input vector. |
Add a scaled vector: res = a + s * b.
| lhs | Input component or vector a. |
| rhs | Input component or vector b. |
| s | Scalar factor. |
Euclidean distance between two 2D vectors.
| a | Input vector a. |
| b | Input vector b. |
Squared Euclidean distance between two 2D vectors.
| a | Input vector a. |
| b | Input vector b. |
Dot product of two 2D vectors.
| a | Input component or vector a. |
| b | Input component or vector b. |
Euclidean length (L2 norm) of a 2D vector.
| v | Input vector. |
Component-wise maximum of two 2D vectors.
| res | Output 2D vector. |
| a | Input component or vector a. |
| b | Input component or vector b. |
Component-wise minimum of two 2D vectors.
| res | Output 2D vector. |
| a | Input component or vector a. |
| b | Input component or vector b. |
Per-component scaling: res[i] = v[i] * s[i].
| v | Input vector. |
| s | Scalar factor. |
Normalize a 2D vector to unit length (safe).
Computes v / ||v||. If the squared length is zero according to bj_real_is_zero, returns the zero vector to avoid division by zero. Uses a single square root.
| v | Input vector. |
v, or {0,0} if ||v|| == 0 by bj_real_is_zero.Normalize a 2D vector to unit length (unsafe).
Computes v / ||v|| without any zero-length check. Faster on hot paths where nonzero length is guaranteed.
| v | Input vector (must be nonzero). |
v.2D "cross product" (perp dot): returns scalar a.x*b.y - a.y*b.x.
Useful for orientation tests, signed area, segment intersection.
Uniform scaling by scalar: res = v * s.
| v | Input vector. |
| s | Scalar factor. |
Scale a 2D vector to a given length.
| res | Output 2D vector. |
| v | Input vector. |
| target_len | Desired length of the result. |
Component-wise subtraction of two 2D vectors: res = lhs - rhs.
| lhs | Left-hand input vector. |
| rhs | Right-hand input vector. |
Component-wise addition of two 3D vectors: res = lhs + rhs.
| res | Output 3D vector. |
| lhs | Left-hand input vector. |
| rhs | Right-hand input vector. |
Add a scaled vector: res = a + s * b.
| lhs | Input component or vector a. |
| rhs | Input component or vector b. |
| s | Scalar factor. |
3D cross product: res = l × r (right-hand rule).
| l | Left-hand input vector. |
| r | Right-hand input vector. |
Euclidean distance between two 3D vectors.
| a | Input vector a. |
| b | Input vector b. |
Squared Euclidean distance between two 3D vectors.
| a | Input vector a. |
| b | Input vector b. |
Dot product of two 3D vectors.
| a | Input component or vector a. |
| b | Input component or vector b. |
Euclidean length (L2 norm) of a 3D vector.
| v | Input vector. |
Component-wise maximum of two 3D vectors.
| res | Output 3D vector. |
| a | Input component or vector a. |
| b | Input component or vector b. |
Component-wise minimum of two 3D vectors.
| res | Output 3D vector. |
| a | Input component or vector a. |
| b | Input component or vector b. |
Normalize a 3D vector to unit length (safe).
Computes v / ||v||. Returns {0,0,0} if ||v|| is zero by bj_real_is_zero. Uses one square root.
| v | Input vector. |
v, or {0,0,0} if ||v|| == 0 by bj_real_is_zero.Normalize a 3D vector to unit length (unsafe).
Computes v / ||v|| without any zero-length check.
| v | Input vector (must be nonzero). |
v.Reflect a vector about a normal: res = v - 2*dot(v, n)*n.
| v | Input vector. |
| n | Surface normal (expected normalized). \reutrn Resulting reflect vector. |
n should be normalized for a true reflection. Uniform scaling by scalar: res = v * s.
| v | Input vector. |
| s | Scalar factor. |
Scale a 3D vector to a given length.
| res | Output 3D vector. |
| v | Input vector. |
| target_len | Desired length of the result. |
Component-wise subtraction of two 3D vectors: res = lhs - rhs.
| lhs | Left-hand input vector. |
| rhs | Right-hand input vector. |
Component-wise addition of two 4D vectors: res = lhs + rhs.
| lhs | Left-hand input vector. |
| rhs | Right-hand input vector. |
Add a scaled vector: res = a + s * b.
| lhs | Input component or vector a. |
| rhs | Input component or vector b. |
| s | Scalar factor. |
Cross product using xyz components; w is set to 1.
| res | Output 4D vector. |
| l | Left-hand input vector. |
| r | Right-hand input vector. |
Dot product of two 4D vectors.
| a | Input component or vector a. |
| b | Input component or vector b. |
Euclidean length (L2 norm) of a 4D vector.
| v | Input vector. |
Component-wise maximum of two 4D vectors.
| res | Output 4D vector. |
| a | Input component or vector a. |
| b | Input component or vector b. |
Component-wise minimum of two 4D vectors.
| res | Output 4D vector. |
| a | Input component or vector a. |
| b | Input component or vector b. |
Normalize a 4D vector to unit length (safe).
Computes v / ||v||. Returns {0,0,0,0} if ||v|| is zero by bj_real_is_zero. Uses one square root.
| v | Input vector. |
v, or {0,0,0,0} if ||v|| == 0 by bj_real_is_zero.Normalize a 4D vector to unit length (unsafe).
Computes v / ||v|| without any zero-length check.
| v | Input vector (must be nonzero). |
v.Reflect a vector about a normal: res = v - 2*dot(v, n)*n.
| res | Output 4D vector. |
| v | Input vector. |
| n | Surface normal (expected normalized). |
n should be normalized for a true reflection. Uniform scaling by scalar: res = v * s.
| v | Input vector. |
| s | Scalar factor. |