|
Banjo API 1.0.0-rc.2
Low-level C99 game development API
|
Topics | |
| Geometry 2D | |
Data Structures | |
| struct | bj_mat3x3 |
| struct | bj_mat3x2 |
| struct | bj_mat4x4 |
| struct | bj_mat4x3 |
| struct | bj_rect |
| struct | bj_vec2 |
| struct | bj_vec3 |
| struct | bj_vec4 |
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 ((struct bj_vec2){BJ_FZERO, BJ_FZERO}) |
| #define | BJ_VEC3_ZERO ((struct bj_vec3){BJ_FZERO, BJ_FZERO, BJ_FZERO}) |
| #define | BJ_VEC4_ZERO ((struct bj_vec4){BJ_FZERO, BJ_FZERO, BJ_FZERO, BJ_FZERO}) |
Functions | |
| static void | bj_mat3_set_identity (struct bj_mat3x3 *restrict M) |
| static void | bj_mat3_copy (struct bj_mat3x3 *restrict dst, const struct bj_mat3x3 *restrict src) |
| static struct bj_vec3 | bj_mat3_row (const struct bj_mat3x3 *restrict M, int r) |
| static struct bj_vec3 | bj_mat3_col (const struct bj_mat3x3 *restrict M, int c) |
| static void | bj_mat3_transpose (struct bj_mat3x3 *restrict out, const struct bj_mat3x3 *restrict A) |
| static void | bj_mat3_add (struct bj_mat3x3 *restrict out, const struct bj_mat3x3 *restrict A, const struct bj_mat3x3 *restrict B) |
| static void | bj_mat3_sub (struct bj_mat3x3 *restrict out, const struct bj_mat3x3 *restrict A, const struct bj_mat3x3 *restrict B) |
| static void | bj_mat3_mul_scalar (struct bj_mat3x3 *restrict out, const struct bj_mat3x3 *restrict A, bj_real k) |
| static void | bj_mat3_mul (struct bj_mat3x3 *restrict out, const struct bj_mat3x3 *restrict A, const struct bj_mat3x3 *restrict B) |
| static struct bj_vec3 | bj_mat3_transform_vec3 (const struct bj_mat3x3 *restrict M, struct bj_vec3 v) |
| static struct bj_vec2 | bj_mat3_transform_point (const struct bj_mat3x3 *restrict M, struct bj_vec2 p) |
| static void | bj_mat3_set_translation (struct bj_mat3x3 *restrict M, bj_real tx, bj_real ty) |
| static void | bj_mat3_translate (struct bj_mat3x3 *restrict M, bj_real tx, bj_real ty) |
| static void | bj_mat3_set_scaling_xy (struct bj_mat3x3 *restrict M, bj_real sx, bj_real sy) |
| static void | bj_mat3_set_shear_xy (struct bj_mat3x3 *restrict M, bj_real shx, bj_real shy) |
| static void | bj_mat3_set_rotation_z (struct bj_mat3x3 *restrict M, bj_real angle) |
| static bj_real | bj_mat3_determinant (const struct bj_mat3x3 *restrict A) |
| static bj_bool | bj_mat3_invert (struct bj_mat3x3 *restrict out, const struct bj_mat3x3 *restrict A) |
| static void | bj_mat3_invert_unsafe (struct bj_mat3x3 *restrict out, const struct bj_mat3x3 *restrict A) |
| static void | bj_mat3_set_ortho (struct bj_mat3x3 *restrict M, bj_real l, bj_real r, bj_real b, bj_real t) |
| static void | bj_mat3_set_viewport (struct bj_mat3x3 *restrict M, bj_real x, bj_real y, bj_real w, bj_real h) |
| static void | bj_mat3x2_set_identity (struct bj_mat3x2 *restrict M) |
| static void | bj_mat3x2_set_translation (struct bj_mat3x2 *restrict M, bj_real tx, bj_real ty) |
| static void | bj_mat3x2_set_scaling_xy (struct bj_mat3x2 *restrict M, bj_real sx, bj_real sy) |
| static void | bj_mat3x2_set_rotation_z (struct bj_mat3x2 *restrict M, bj_real angle) |
| static void | bj_mat3x2_mul (struct bj_mat3x2 *restrict out, const struct bj_mat3x2 *restrict A, const struct bj_mat3x2 *restrict B) |
| static struct bj_vec2 | bj_mat3x2_transform_point (const struct bj_mat3x2 *restrict M, struct bj_vec2 p) |
| static struct bj_vec2 | bj_mat3x2_transform_dir (const struct bj_mat3x2 *restrict M, struct bj_vec2 v) |
| static void | bj_mat3_from_mat3x2 (struct bj_mat3x3 *restrict M, const struct bj_mat3x2 *restrict A) |
| static void | bj_mat3x2_from_mat3 (struct bj_mat3x2 *restrict M, const struct bj_mat3x3 *restrict A) |
| static void | bj_mat4_set_identity (struct bj_mat4x4 *restrict M) |
| static void | bj_mat4_copy (struct bj_mat4x4 *restrict dst, const struct bj_mat4x4 *restrict src) |
| static struct bj_vec4 | bj_mat4_row (const struct bj_mat4x4 *restrict M, int r) |
| static struct bj_vec4 | bj_mat4_col (const struct bj_mat4x4 *restrict M, int c) |
| static void | bj_mat4_transpose (struct bj_mat4x4 *restrict out, const struct bj_mat4x4 *restrict A) |
| static void | bj_mat4_add (struct bj_mat4x4 *restrict out, const struct bj_mat4x4 *restrict A, const struct bj_mat4x4 *restrict B) |
| static void | bj_mat4_sub (struct bj_mat4x4 *restrict out, const struct bj_mat4x4 *restrict A, const struct bj_mat4x4 *restrict B) |
| static void | bj_mat4_mul_scalar (struct bj_mat4x4 *restrict out, const struct bj_mat4x4 *restrict A, bj_real k) |
| static void | bj_mat4_scale_axes (struct bj_mat4x4 *restrict out, const struct bj_mat4x4 *restrict A, bj_real sx, bj_real sy, bj_real sz) |
| static void | bj_mat4_mul (struct bj_mat4x4 *restrict out, const struct bj_mat4x4 *restrict A, const struct bj_mat4x4 *restrict B) |
| static struct bj_vec4 | bj_mat4_transform_vec4 (const struct bj_mat4x4 *restrict M, struct bj_vec4 v) |
| static void | bj_mat4_set_translation (struct bj_mat4x4 *restrict M, bj_real x, bj_real y, bj_real z) |
| static void | bj_mat4_translate (struct bj_mat4x4 *restrict M, bj_real x, bj_real y, bj_real z) |
| static void | bj_mat4_set_outer_product (struct bj_mat4x4 *restrict out, struct bj_vec3 a, struct bj_vec3 b) |
| static void | bj_mat4_rotate_axis_angle (struct bj_mat4x4 *restrict out, const struct bj_mat4x4 *restrict M, struct bj_vec3 axis, bj_real angle) |
| static void | bj_mat4_rotate_x (struct bj_mat4x4 *restrict out, const struct bj_mat4x4 *restrict M, bj_real a) |
| static void | bj_mat4_rotate_y (struct bj_mat4x4 *restrict out, const struct bj_mat4x4 *restrict M, bj_real a) |
| static void | bj_mat4_rotate_z (struct bj_mat4x4 *restrict out, const struct bj_mat4x4 *restrict M, bj_real a) |
| static void | bj_mat4_rotate_arcball (struct bj_mat4x4 *restrict R, const struct bj_mat4x4 *restrict M, struct bj_vec2 a, struct bj_vec2 b, bj_real s) |
| static bj_bool | bj_mat4_invert (struct bj_mat4x4 *restrict out, const struct bj_mat4x4 *restrict M) |
| static void | bj_mat4_invert_unsafe (struct bj_mat4x4 *restrict out, const struct bj_mat4x4 *restrict M) |
| static void | bj_mat4_orthonormalize (struct bj_mat4x4 *restrict out, const struct bj_mat4x4 *restrict A) |
| static void | bj_mat4_set_frustum (struct bj_mat4x4 *restrict M, bj_real l, bj_real r, bj_real b, bj_real t, bj_real n, bj_real f) |
| static void | bj_mat4_set_ortho (struct bj_mat4x4 *restrict M, bj_real l, bj_real r, bj_real b, bj_real t, bj_real n, bj_real f) |
| static void | bj_mat4_set_perspective (struct bj_mat4x4 *restrict M, bj_real y_fov, bj_real aspect, bj_real n, bj_real f) |
| static void | bj_mat4_set_viewport (struct bj_mat4x4 *restrict M, bj_real x, bj_real y, bj_real w, bj_real h) |
| static void | bj_mat4_set_lookat (struct bj_mat4x4 *restrict M, struct bj_vec3 eye, struct bj_vec3 center, struct bj_vec3 up) |
| static void | bj_mat4x3_set_identity (struct bj_mat4x3 *restrict M) |
| static void | bj_mat4x3_set_translation (struct bj_mat4x3 *restrict M, bj_real tx, bj_real ty, bj_real tz) |
| static void | bj_mat4x3_set_scaling_xyz (struct bj_mat4x3 *restrict M, bj_real sx, bj_real sy, bj_real sz) |
| static void | bj_mat4x3_set_rotation_x (struct bj_mat4x3 *restrict M, bj_real a) |
| static void | bj_mat4x3_set_rotation_y (struct bj_mat4x3 *restrict M, bj_real a) |
| static void | bj_mat4x3_set_rotation_z (struct bj_mat4x3 *restrict M, bj_real a) |
| static void | bj_mat4x3_mul (struct bj_mat4x3 *restrict out, const struct bj_mat4x3 *restrict A, const struct bj_mat4x3 *restrict B) |
| static struct bj_vec3 | bj_mat4x3_transform_point (const struct bj_mat4x3 *restrict M, struct bj_vec3 p) |
| static struct bj_vec3 | bj_mat4x3_transform_dir (const struct bj_mat4x3 *restrict M, struct bj_vec3 v) |
| static void | bj_mat4_from_mat4x3 (struct bj_mat4x4 *restrict M, const struct bj_mat4x3 *restrict A) |
| static void | bj_mat4x3_from_mat4 (struct bj_mat4x3 *restrict M, const struct bj_mat4x4 *restrict A) |
| 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) |
| bj_bool | bj_rect_intersection (const struct bj_rect *rect_a, const struct bj_rect *rect_b, struct bj_rect *result) |
| void | bj_rect_union (const struct bj_rect *rect_a, const struct bj_rect *rect_b, struct bj_rect *result) |
| static struct bj_vec2 | bj_vec2_map (struct bj_vec2 a, bj_real(*f)(bj_real)) |
| static struct bj_vec2 | bj_vec2_add (struct bj_vec2 lhs, struct bj_vec2 rhs) |
| static struct bj_vec2 | bj_vec2_add_scaled (struct bj_vec2 lhs, struct bj_vec2 rhs, bj_real s) |
| static struct bj_vec2 | bj_vec2_sub (const struct bj_vec2 lhs, const struct bj_vec2 rhs) |
| static struct bj_vec2 | bj_vec2_scale (struct bj_vec2 v, bj_real s) |
| static struct bj_vec2 | bj_vec2_mul_comp (const struct bj_vec2 v, const struct bj_vec2 s) |
| static bj_real | bj_vec2_dot (struct bj_vec2 a, struct bj_vec2 b) |
| static bj_real | bj_vec2_perp_dot (struct bj_vec2 a, struct bj_vec2 b) |
| static bj_real | bj_vec2_len (struct bj_vec2 v) |
| static struct bj_vec2 | bj_vec2_scale_to_len (struct bj_vec2 v, bj_real L) |
| static bj_real | bj_vec2_distance_sq (struct bj_vec2 a, struct bj_vec2 b) |
| static bj_real | bj_vec2_distance (const struct bj_vec2 a, const struct bj_vec2 b) |
| static struct bj_vec2 | bj_vec2_normalize (struct bj_vec2 v) |
| static struct bj_vec2 | bj_vec2_normalize_unsafe (struct bj_vec2 v) |
| static struct bj_vec2 | bj_vec2_min (struct bj_vec2 a, struct bj_vec2 b) |
| static struct bj_vec2 | bj_vec2_max (struct bj_vec2 a, struct bj_vec2 b) |
| static struct bj_vec3 | bj_vec3_map (struct bj_vec3 a, bj_real(*f)(bj_real)) |
| static struct bj_vec3 | bj_vec3_add (struct bj_vec3 lhs, struct bj_vec3 rhs) |
| static struct bj_vec3 | bj_vec3_add_scaled (struct bj_vec3 lhs, struct bj_vec3 rhs, bj_real s) |
| static struct bj_vec3 | bj_vec3_sub (struct bj_vec3 lhs, struct bj_vec3 rhs) |
| static struct bj_vec3 | bj_vec3_scale (struct bj_vec3 v, bj_real s) |
| static bj_real | bj_vec3_dot (struct bj_vec3 a, struct bj_vec3 b) |
| static bj_real | bj_vec3_len (struct bj_vec3 v) |
| static struct bj_vec3 | bj_vec3_scale_to_len (struct bj_vec3 v, bj_real L) |
| static bj_real | bj_vec3_distance_sq (struct bj_vec3 a, struct bj_vec3 b) |
| static bj_real | bj_vec3_distance (struct bj_vec3 a, struct bj_vec3 b) |
| static struct bj_vec3 | bj_vec3_normalize (struct bj_vec3 v) |
| static struct bj_vec3 | bj_vec3_normalize_unsafe (struct bj_vec3 v) |
| static struct bj_vec3 | bj_vec3_min (struct bj_vec3 a, struct bj_vec3 b) |
| static struct bj_vec3 | bj_vec3_max (struct bj_vec3 a, struct bj_vec3 b) |
| static struct bj_vec3 | bj_vec3_cross (struct bj_vec3 l, struct bj_vec3 r) |
| static struct bj_vec3 | bj_vec3_reflect (struct bj_vec3 v, struct bj_vec3 n) |
| static struct bj_vec4 | bj_vec4_map (struct bj_vec4 a, bj_real(*f)(bj_real)) |
| static struct bj_vec4 | bj_vec4_add (struct bj_vec4 lhs, struct bj_vec4 rhs) |
| static struct bj_vec4 | bj_vec4_add_scaled (struct bj_vec4 lhs, struct bj_vec4 rhs, bj_real s) |
| static struct bj_vec4 | bj_vec4_sub (struct bj_vec4 lhs, struct bj_vec4 rhs) |
| static struct bj_vec4 | bj_vec4_scale (struct bj_vec4 v, bj_real s) |
| static bj_real | bj_vec4_dot (struct bj_vec4 a, struct bj_vec4 b) |
| static bj_real | bj_vec4_len (struct bj_vec4 v) |
| static struct bj_vec4 | bj_vec4_normalize (struct bj_vec4 v) |
| static struct bj_vec4 | bj_vec4_normalize_unsafe (struct bj_vec4 v) |
| static struct bj_vec4 | bj_vec4_min (struct bj_vec4 a, struct bj_vec4 b) |
| static struct bj_vec4 | bj_vec4_max (struct bj_vec4 a, struct bj_vec4 b) |
| static struct bj_vec4 | bj_vec4_cross_xyz (struct bj_vec4 l, struct bj_vec4 r) |
| static struct bj_vec4 | bj_vec4_reflect (struct bj_vec4 v, struct bj_vec4 n) |
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.
The relative variants (bj_real_eq_rel and friends) have the same limitation: relative tolerance scales the threshold with magnitude but doesn't restore transitivity. | |
| 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 |
A small math toolkit: a choose-your-precision real type, constants, the standard <math.h> functions with consistent naming, and a few extras.
Most C math is <math.h>, and the function you want depends on the floating-point type: sin for double, sinf for float, sinl for long double. Banjo wraps these so you can write code once that works regardless of the precision your build is using.
At the centre is bj_real, Banjo's "the floating-point type" that's chosen at build time. By default bj_real is float; define BJ_API_FLOAT64 or BJ_API_LONG_DOUBLE to make it double or long double respectively. Then every bj_* math function and constant follows along: bj_sin uses the right sin flavour, BJ_PI is the right precision, and so on.
What's in here:
BJ_F literal-suffix helper and BJ_EPSILON for the smallest meaningful difference at your chosen precision.bj_* form that matches the selected precision.bj_* aliases that resolve to the active precision.These functions don't carry units, they treat their inputs as pure numbers. Use them as the math layer underneath domain code like Physics (which does think in units).
| struct bj_mat3x3 |
3×3 column-major matrix.
Used for 2D homogeneous (projective) transforms: the 2×2 linear block plus a third column for projective terms.
| Data Fields | ||
|---|---|---|
| bj_real | m[9] | |
| struct bj_mat3x2 |
| struct bj_mat4x4 |
| struct bj_mat4x3 |
| struct bj_rect |
Axis-aligned rectangle: a top-left corner plus a width and height.
Covers pixels [x, x+w) × [y, y+h). Position is signed so a rectangle can be partly or fully off-surface; size is unsigned.
| struct bj_vec2 |
| struct bj_vec3 |
| struct bj_vec4 |
| #define bj_abs bj_absf |
Absolute value.
Definition at line 233 of file math.h.
Referenced by bj_real_eq(), bj_real_eq_rel(), bj_real_is_zero(), bj_real_is_zero_scaled(), bj_real_relative_scale(), and shader_code().
| #define bj_acos bj_acosf |
Arc cosine.
Definition at line 234 of file math.h.
Referenced by bj_mat4_rotate_arcball(), and bj_quat_slerp().
| #define bj_copysign bj_copysignf |
| #define bj_cos bj_cosf |
Cosine.
Definition at line 237 of file math.h.
Referenced by bj_mat3_set_rotation_z(), bj_mat3x2_set_rotation_z(), bj_mat4_rotate_axis_angle(), bj_mat4_rotate_x(), bj_mat4_rotate_y(), bj_mat4_rotate_z(), bj_mat4x3_set_rotation_x(), bj_mat4x3_set_rotation_y(), bj_mat4x3_set_rotation_z(), bj_quat_from_axis_angle(), init_asteroids(), init_planet(), palette(), and reset_ball().
| #define BJ_EPSILON (FLT_EPSILON) |
Machine epsilon for bj_real when float is selected.
Definition at line 80 of file math.h.
Referenced by bj_quat_from_axis_angle(), bj_quat_inverse(), bj_quat_normalize(), bj_quat_slerp(), bj_real_eq(), bj_real_eq_rel(), bj_real_gt(), bj_real_gt_rel(), bj_real_is_zero(), bj_real_is_zero_scaled(), bj_real_lt(), and bj_real_lt_rel().
| #define bj_exp bj_expf |
| #define BJ_F | ( | x | ) |
Literal suffix helper for bj_real when float is selected.
Definition at line 78 of file math.h.
Referenced by bj_galileo_position(), bj_mat3_from_mat3x2(), bj_mat3_invert(), bj_mat3_invert_unsafe(), bj_mat3_set_identity(), bj_mat3_set_ortho(), bj_mat3_set_rotation_z(), bj_mat3_set_viewport(), bj_mat3x2_set_identity(), bj_mat4_from_mat4x3(), bj_mat4_invert(), bj_mat4_invert_unsafe(), bj_mat4_rotate_arcball(), bj_mat4_rotate_axis_angle(), bj_mat4_set_frustum(), bj_mat4_set_identity(), bj_mat4_set_ortho(), bj_mat4_set_perspective(), bj_mat4_set_viewport(), bj_mat4x3_set_identity(), bj_newton_plummer_gravitation(), bj_quat_from_axis_angle(), bj_quat_from_mat4(), bj_quat_identity(), bj_quat_inverse(), bj_quat_normalize(), bj_quat_slerp(), bj_quat_to_mat4(), bj_real_is_zero_scaled(), bj_real_relative_scale(), bj_smoothstep(), bj_step(), bj_vec2_normalize(), bj_vec2_normalize_unsafe(), bj_vec3_normalize(), bj_vec3_normalize_unsafe(), bj_vec3_reflect(), bj_vec4_normalize(), bj_vec4_normalize_unsafe(), bj_vec4_reflect(), draw(), init_asteroids(), init_planet(), init_sun(), initialize(), orbital_speed_soft(), palette(), reset_ball(), run_distributions(), and shader_code().
| #define BJ_FI | ( | x | ) |
| #define bj_floor bj_floorf |
| #define bj_fmod bj_fmodf |
| #define BJ_FZERO (BJ_F(0.0)) |
Zero constant in bj_real.
Definition at line 89 of file math.h.
Referenced by bj_mat3_from_mat3x2(), bj_mat3_set_identity(), bj_mat3_set_ortho(), bj_mat3_set_rotation_z(), bj_mat3_set_viewport(), bj_mat3_transform_point(), bj_mat3_translate(), bj_mat3x2_set_identity(), bj_mat3x2_set_rotation_z(), bj_mat4_from_mat4x3(), bj_mat4_rotate_arcball(), bj_mat4_set_frustum(), bj_mat4_set_identity(), bj_mat4_set_ortho(), bj_mat4_set_outer_product(), bj_mat4_set_perspective(), bj_mat4_set_viewport(), bj_mat4_translate(), bj_mat4x3_set_identity(), bj_mod(), bj_newton_plummer_gravitation(), bj_quat_from_mat4(), bj_quat_identity(), bj_quat_slerp(), bj_quat_to_mat4(), bj_real_snap_zero(), bj_real_snorm_safe(), bj_smoothstep(), bj_step(), bj_vec2_normalize(), bj_vec2_scale_to_len(), bj_vec3_normalize(), bj_vec3_scale_to_len(), bj_vec4_cross_xyz(), bj_vec4_normalize(), orbital_speed_soft(), and shader_code().
| #define BJ_M3 | ( | c, | |
| r ) |
Index a 3×3 matrix element at column c, row r. 0 <= c,r < 3.
Definition at line 61 of file mat.h.
Referenced by bj_mat3_col(), bj_mat3_determinant(), bj_mat3_from_mat3x2(), bj_mat3_invert(), bj_mat3_invert_unsafe(), bj_mat3_mul(), bj_mat3_row(), bj_mat3_set_identity(), bj_mat3_set_ortho(), bj_mat3_set_rotation_z(), bj_mat3_set_scaling_xy(), bj_mat3_set_shear_xy(), bj_mat3_set_translation(), bj_mat3_set_viewport(), bj_mat3_transform_point(), bj_mat3_transform_vec3(), bj_mat3_translate(), bj_mat3_transpose(), and bj_mat3x2_from_mat3().
| #define BJ_M32 | ( | c, | |
| r ) |
Index a 3×2 matrix element at column c, row r. 0 <= c < 3, 0 <= r < 2.
Definition at line 72 of file mat.h.
Referenced by bj_mat3_from_mat3x2(), bj_mat3x2_from_mat3(), bj_mat3x2_mul(), bj_mat3x2_set_identity(), bj_mat3x2_set_rotation_z(), bj_mat3x2_set_scaling_xy(), bj_mat3x2_set_translation(), bj_mat3x2_transform_dir(), and bj_mat3x2_transform_point().
| #define BJ_M4 | ( | c, | |
| r ) |
Index a 4×4 matrix element at column c, row r. 0 <= c,r < 4.
Definition at line 81 of file mat.h.
Referenced by bj_mat4_col(), bj_mat4_from_mat4x3(), bj_mat4_invert(), bj_mat4_invert_unsafe(), bj_mat4_mul(), bj_mat4_orthonormalize(), bj_mat4_rotate_axis_angle(), bj_mat4_rotate_x(), bj_mat4_rotate_y(), bj_mat4_rotate_z(), bj_mat4_row(), bj_mat4_scale_axes(), bj_mat4_set_frustum(), bj_mat4_set_identity(), bj_mat4_set_lookat(), bj_mat4_set_ortho(), bj_mat4_set_outer_product(), bj_mat4_set_perspective(), bj_mat4_set_translation(), bj_mat4_set_viewport(), bj_mat4_transform_vec4(), bj_mat4_translate(), bj_mat4_transpose(), bj_mat4x3_from_mat4(), bj_quat_from_mat4(), and bj_quat_to_mat4().
| #define BJ_M43 | ( | c, | |
| r ) |
Index a 4×3 matrix element at column c, row r. 0 <= c < 4, 0 <= r < 3.
Definition at line 91 of file mat.h.
Referenced by bj_mat4_from_mat4x3(), bj_mat4x3_from_mat4(), bj_mat4x3_mul(), bj_mat4x3_set_identity(), bj_mat4x3_set_rotation_x(), bj_mat4x3_set_rotation_y(), bj_mat4x3_set_rotation_z(), bj_mat4x3_set_scaling_xyz(), bj_mat4x3_set_translation(), bj_mat4x3_transform_dir(), and bj_mat4x3_transform_point().
| #define bj_max bj_maxf |
Maximum of two floats.
Definition at line 242 of file math.h.
Referenced by bj_real_is_zero_scaled(), and bj_real_relative_scale().
| #define BJ_PI (BJ_F(3.141592653589793238462643383279502884)) |
PI in the selected bj_real precision.
Definition at line 111 of file math.h.
Referenced by reset_ball().
| #define BJ_PI_D (3.14159265358979323846264338327950288) |
| #define BJ_PI_F (3.14159265358979323846f) |
| #define BJ_PI_L (3.141592653589793238462643383279502884L) |
| #define bj_pow bj_powf |
Power.
Definition at line 244 of file math.h.
Referenced by bj_newton_plummer_gravitation(), orbital_speed_soft(), and shader_code().
| #define bj_round bj_roundf |
Round to nearest integer.
Definition at line 245 of file math.h.
Referenced by run_distributions().
| #define bj_sin bj_sinf |
Sine.
Definition at line 246 of file math.h.
Referenced by bj_mat3_set_rotation_z(), bj_mat3x2_set_rotation_z(), bj_mat4_rotate_axis_angle(), bj_mat4_rotate_x(), bj_mat4_rotate_y(), bj_mat4_rotate_z(), bj_mat4x3_set_rotation_x(), bj_mat4x3_set_rotation_y(), bj_mat4x3_set_rotation_z(), bj_quat_from_axis_angle(), bj_quat_slerp(), init_asteroids(), init_planet(), reset_ball(), and shader_code().
| #define bj_sqrt bj_sqrtf |
Square root.
Definition at line 247 of file math.h.
Referenced by bj_mat4_rotate_arcball(), bj_quat_from_axis_angle(), bj_quat_from_mat4(), bj_quat_norm(), bj_quat_normalize(), bj_vec2_distance(), bj_vec2_len(), bj_vec2_normalize(), bj_vec2_normalize_unsafe(), bj_vec3_distance(), bj_vec3_len(), bj_vec3_normalize(), bj_vec3_normalize_unsafe(), bj_vec4_len(), bj_vec4_normalize(), bj_vec4_normalize_unsafe(), and orbital_speed_soft().
| #define bj_tan bj_tanf |
| #define BJ_TAU (BJ_F(6.283185307179586476925286766559005768)) |
TAU in the selected bj_real precision.
Definition at line 113 of file math.h.
Referenced by init_asteroids().
| #define BJ_TAU_D (6.28318530717958647692528676655900576) |
| #define BJ_TAU_F (6.28318530717958647692f) |
| #define BJ_TAU_L (6.283185307179586476925286766559005768L) |
Zero 2D vector literal {0, 0}.
Definition at line 57 of file vec.h.
Referenced by init_asteroids(), and init_planet().
| typedef float bj_real |
Selected real type for float configuration.
Fractional part of x.
| x | Input value |
Definition at line 298 of file math.h.
Referenced by shader_code().
Extract a matrix column as a vector.
| M | Input 3×3 matrix. |
| c | index (0-based). |
Definition at line 137 of file mat.h.
Referenced by bj_mat3_col().
|
inlinestatic |
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. |
|
inlinestatic |
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. |
Definition at line 219 of file mat.h.
Referenced by update_projection().
Extract a matrix row as a vector.
| M | Input 3×3 matrix. |
| r | index (0-based). |
Definition at line 124 of file mat.h.
Referenced by bj_mat3_row(), and bj_mat3_translate().
|
inlinestatic |
Set a 3×3 matrix to identity.
| M | Output 3×3 matrix. |
Definition at line 97 of file mat.h.
Referenced by bj_mat3_set_scaling_xy(), bj_mat3_set_shear_xy(), and bj_mat3_set_translation().
|
inlinestatic |
Build a 2D orthographic projection into a 3×3 matrix.
Maps the rectangle [l, r] × [b, t] in source space to the [-1, 1] × [-1, 1] normalised range. Y is inverted relative to a top-left-origin source.
| M | Output 3×3 matrix. |
| l | Left edge of the source rectangle. |
| r | Right edge of the source rectangle (must differ from l). |
| b | Bottom edge of the source rectangle. |
| t | Top edge of the source rectangle (must differ from b). |
Definition at line 479 of file mat.h.
Referenced by update_projection().
Build a non-uniform XY scale into a 3×3 matrix.
Overwrites M with the identity, then sets the X and Y scale on the diagonal. Use bj_mat3_mul to apply this to an existing transform.
| M | Output 3×3 matrix. |
| sx | Scale on X. |
| sy | Scale on 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. |
Definition at line 506 of file mat.h.
Referenced by update_projection().
|
inlinestatic |
Transform a 2D point by a 3×3 homogeneous transform.
| M | Input 3×3 matrix. |
| p | Input point. |
Definition at line 264 of file mat.h.
Referenced by bj_mat3_transform_point().
|
inlinestatic |
Multiply a 3×3 matrix by a 3D vector: r = M * v.
| M | Input 3×3 matrix. |
| v | Input vector. |
Definition at line 245 of file mat.h.
Referenced by bj_mat3_transform_vec3(), and draw().
|
inlinestatic |
Set a 3×2 affine matrix to identity.
| M | Output 3×2 matrix. |
Definition at line 529 of file mat.h.
Referenced by bj_mat3x2_set_scaling_xy(), and bj_mat3x2_set_translation().
|
inlinestatic |
Transform a direction vector by a 3×2 affine matrix (ignoring translation).
Applies the 2×2 linear block only. Use for directions, normals (when the linear part is rigid/orthogonal), and offsets: anything that shouldn't pick up the translation column.
| M | Input 3×2 matrix. |
| v | Input direction vector. |
Definition at line 671 of file mat.h.
Referenced by bj_mat3x2_transform_dir().
|
inlinestatic |
Transform a 2D point by a 3×2 affine matrix.
Applies the 2×2 linear block and adds the translation column. No projective divide: bj_mat3x2 has no projective term.
| M | Input 3×2 matrix. |
| p | Input point. |
Definition at line 646 of file mat.h.
Referenced by bj_mat3x2_transform_point().
Extract a matrix column as a vector.
| M | Input 4×4 matrix. |
| c | index (0-based). |
Definition at line 790 of file mat.h.
Referenced by bj_mat4_col().
|
inlinestatic |
Copy a matrix.
| dst | Output 4×4 matrix. |
| src | Input 4×4 matrix. |
Definition at line 756 of file mat.h.
Referenced by bj_mat4_orthonormalize(), and bj_mat4_rotate_axis_angle().
|
inlinestatic |
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. |
|
inlinestatic |
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 |
Right-multiply by an arcball rotation between two screen points.
Lifts each 2D input onto the unit hemisphere (if outside the unit disc, it's normalised onto the equator instead), takes the rotation from A to B, and right-multiplies it into M, writing the result to R. Used to implement trackball-style camera controls driven by mouse drag.
| R | Output 4×4 matrix. |
| M | Input 4×4 matrix. |
| a | Start point in screen-normalised coordinates (typically [-1,1]^2). |
| b | End point in screen-normalised coordinates. |
| s | Scalar speed multiplier applied to the rotation angle. |
|
inlinestatic |
Right-multiply a 4×4 by a rotation around an arbitrary axis.
Composes out = M * R(axis, angle). The axis is normalised internally; if its length is below 1e-4, the rotation is skipped and out = M.
| out | Output 4×4 matrix. |
| M | Input 4×4 matrix. |
| axis | Axis of rotation (need not be unit length). |
| angle | Rotation angle in radians. |
Definition at line 1070 of file mat.h.
Referenced by bj_mat4_rotate_arcball().
|
inlinestatic |
Right-multiply a 4×4 by an X-axis rotation: out = M * Rx(a).
| out | Output 4×4 matrix. |
| M | Input 4×4 matrix. |
| a | Rotation angle in radians. |
|
inlinestatic |
Right-multiply a 4×4 by a Y-axis rotation: out = M * Ry(a).
| out | Output 4×4 matrix. |
| M | Input 4×4 matrix. |
| a | Rotation angle in radians. |
|
inlinestatic |
Right-multiply a 4×4 by a Z-axis rotation: out = M * Rz(a).
| out | Output 4×4 matrix. |
| M | Input 4×4 matrix. |
| a | Rotation angle in radians. |
Extract a matrix row as a vector.
| M | Input 4×4 matrix. |
| r | index (0-based). |
Definition at line 771 of file mat.h.
Referenced by bj_mat4_row(), and bj_mat4_translate().
|
inlinestatic |
Build a perspective frustum projection into a 4×4 matrix.
Maps the frustum bounded by [l, r] × [b, t] on the near plane (and the corresponding rays out to the far plane) to NDC. Depth maps to [0, 1]. Y is inverted relative to a top-left-origin source.
| M | Output 4×4 matrix. |
| l | Left edge on the near plane. |
| r | Right edge on the near plane (must satisfy r > l). |
| b | Bottom edge on the near plane. |
| t | Top edge on the near plane (must satisfy t > b). |
| n | Near plane distance. |
| f | Far plane distance (must satisfy f > n). |
|
inlinestatic |
Set a 4×4 matrix to identity.
| M | Output 4×4 matrix. |
Definition at line 729 of file mat.h.
Referenced by bj_mat4_set_lookat(), bj_mat4_set_translation(), and bj_quat_to_mat4().
|
inlinestatic |
Build a 3D orthographic projection into a 4×4 matrix.
Maps the box [l, r] × [b, t] × [n, f] to NDC. Depth maps to [0, 1]. Y is inverted relative to a top-left-origin source.
| M | Output 4×4 matrix. |
| l | Left edge of the source box. |
| r | Right edge of the source box (must differ from l). |
| b | Bottom edge of the source box. |
| t | Top edge of the source box (must differ from b). |
| n | Near plane distance. |
| f | Far plane distance (must differ from n). |
|
inlinestatic |
Build the outer product a * b^T as a 4×4 matrix.
Overwrites out with the 3×3 outer-product block embedded in a 4×4 zero matrix: out[i, j] = a[i] * b[j] for i, j < 3, all other entries zero. The 4×4 result has rank 1.
| out | Output 4×4 matrix. |
| a | Left vector (becomes the column of the outer product). |
| b | Right vector (becomes the row of the outer product). |
|
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. |
|
inlinestatic |
Multiply a 4×4 matrix by a 4D vector: r = M * v.
| M | Input 4×4 matrix. |
| v | Input vector. |
Definition at line 960 of file mat.h.
Referenced by bj_mat4_transform_vec4().
|
inlinestatic |
Right-multiply by a translation: M = M * T(x, y, z).
In place: M is overwritten with the composed result.
| M | In/out 4×4 matrix. |
| x | Translation along X. |
| y | Translation along Y. |
| z | Translation along Z. |
Definition at line 1009 of file mat.h.
Referenced by bj_mat4_set_lookat().
|
inlinestatic |
Set a 4×3 affine matrix to identity.
| M | Output 4×3 matrix. |
Definition at line 1635 of file mat.h.
Referenced by bj_mat4x3_set_rotation_x(), bj_mat4x3_set_rotation_y(), bj_mat4x3_set_rotation_z(), bj_mat4x3_set_scaling_xyz(), and bj_mat4x3_set_translation().
Build a 4×3 X-axis rotation.
Overwrites M with the identity and sets the rotation block.
| M | Output 4×3 matrix. |
| a | Rotation angle in radians. |
Build a 4×3 Y-axis rotation.
Overwrites M with the identity and sets the rotation block.
| M | Output 4×3 matrix. |
| a | Rotation angle in radians. |
Build a 4×3 Z-axis rotation.
Overwrites M with the identity and sets the rotation block.
| M | Output 4×3 matrix. |
| a | Rotation angle in radians. |
|
inlinestatic |
Transform a direction vector (ignoring translation).
| M | Input 4×3 matrix. |
| v | Input vector. |
Definition at line 1837 of file mat.h.
Referenced by bj_mat4x3_transform_dir().
|
inlinestatic |
Transform a 3D point by a 4×3 affine matrix.
| M | Input 4×3 matrix. |
| p | Input point. |
Definition at line 1818 of file mat.h.
Referenced by bj_mat4x3_transform_point().
Conjugate of a quaternion.
Negates the vector part and keeps the scalar part: conj(q) = {-x,-y,-z,w}.
| q | Quaternion. |
Definition at line 138 of file quat.h.
Referenced by bj_quat_conjugate().
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. Definition at line 73 of file quat.h.
Referenced by bj_quat_norm2(), and 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. |
Definition at line 263 of file quat.h.
Referenced by bj_quat_from_axis_angle().
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 normalised.
| M | Source 4×4 matrix (column-major). |
Definition at line 374 of file quat.h.
Referenced by bj_quat_from_mat4().
|
inlinestatic |
Return the identity quaternion.
Represents a no-rotation. Equivalent to {0,0,0,1}.
Definition at line 57 of file quat.h.
Referenced by bj_quat_from_axis_angle(), bj_quat_identity(), bj_quat_inverse(), and bj_quat_normalize().
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. |
Definition at line 156 of file quat.h.
Referenced by bj_quat_inverse().
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. Definition at line 178 of file quat.h.
Referenced by bj_quat_mul().
Squared Euclidean norm.
| q | Quaternion. |
||q||^2.Definition at line 88 of file quat.h.
Referenced by bj_quat_inverse(), bj_quat_norm(), and bj_quat_normalize().
Normalise a quaternion.
Returns identity if the input length is near zero (<= BJ_EPSILON).
| q | Quaternion. |
Definition at line 115 of file quat.h.
Referenced by bj_quat_from_mat4(), bj_quat_normalize(), bj_quat_slerp(), and bj_quat_to_mat4().
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 normalised inside the function. Call bj_quat_normalize beforehand if needed. Definition at line 291 of file quat.h.
Referenced by bj_quat_rotate_vec3(), and bj_quat_rotate_vec4().
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. Definition at line 313 of file quat.h.
Referenced by bj_quat_rotate_vec4().
Spherical linear interpolation between two orientations.
Interpolates along the shortest arc on S^3. If inputs are nearly parallel, falls back to normalised linear interpolation to avoid divide-by-zero.
| a | Start quaternion. |
| b | End quaternion. |
| t | Interpolation factor in [0,1]. |
Definition at line 204 of file quat.h.
Referenced by bj_quat_slerp().
Fill a 4×4 rotation matrix from a quaternion.
| [out] | M | Destination matrix (column-major). |
| [in] | q | Input quaternion. It is normalised internally. |
Equality within absolute epsilon.
| a | First value |
| b | Second value |
Definition at line 342 of file math.h.
Referenced by bj_real_neq().
Equality within relative epsilon.
| a | First value |
| b | Second value |
Definition at line 416 of file math.h.
Referenced by bj_real_neq_rel().
a > b by more than absolute epsilon.
| a | First value |
| b | Second value |
Definition at line 366 of file math.h.
Referenced by bj_real_cmp(), and bj_real_lte().
a > b by more than relative epsilon.
| a | First value |
| b | Second value |
Definition at line 440 of file math.h.
Referenced by bj_real_cmp_rel(), and bj_real_lte_rel().
|
inlinestatic |
Absolute-zero test.
| x | Input value |
Definition at line 479 of file math.h.
Referenced by bj_mat3_invert(), bj_mat4_invert(), bj_real_snap_zero(), bj_real_snorm_safe(), bj_vec2_normalize(), bj_vec2_scale_to_len(), bj_vec3_normalize(), bj_vec3_scale_to_len(), and bj_vec4_normalize().
a < b by more than absolute epsilon.
| a | First value |
| b | Second value |
Definition at line 358 of file math.h.
Referenced by bj_real_cmp(), and bj_real_gte().
a < b by more than relative epsilon.
| a | First value |
| b | Second value |
Definition at line 432 of file math.h.
Referenced by bj_real_cmp_rel(), and bj_real_gte_rel().
Internal scale helper max(1, |a|, |b|).
| a | First value |
| b | Second value |
Definition at line 406 of file math.h.
Referenced by bj_real_eq_rel(), bj_real_gt_rel(), and bj_real_lt_rel().
| bj_bool bj_rect_intersection | ( | const struct bj_rect * | rect_a, |
| const struct bj_rect * | rect_b, | ||
| struct bj_rect * | result ) |
Compute the intersection of two rectangles.
Useful for clipping a drawing operation to a viewport, or for testing whether two on-screen regions overlap.
| rect_a | Pointer to the first rectangle. Must not be NULL. |
| rect_b | Pointer to the second rectangle. Must not be NULL. |
| result | Pointer to receive the intersection, or NULL to only test for overlap without computing it. |
| void bj_rect_union | ( | const struct bj_rect * | rect_a, |
| const struct bj_rect * | rect_b, | ||
| struct bj_rect * | result ) |
Compute the bounding box that contains both rectangles.
Useful for accumulating damage rectangles (each invalidate enlarges the bounding region) and similar set-of-pixels-affected bookkeeping.
A zero-sized input rectangle contributes nothing to the union; a NULL input is treated the same way. If both inputs are zero-sized or NULL, result is set to the empty rectangle {0,0,0,0}.
result may alias either input pointer for in-place accumulation.
| rect_a | Pointer to the first rectangle, or NULL. |
| rect_b | Pointer to the second rectangle, or NULL. |
| result | Pointer to receive the bounding box. Must not be NULL. |
Component-wise addition: lhs + rhs.
| lhs | Left-hand vector. |
| rhs | Right-hand vector. |
Definition at line 115 of file vec.h.
Referenced by bj_vec2_add().
|
inlinestatic |
Fused scaled add: lhs + s * rhs.
Common building block for physics integration (pos += dt * vel), linear interpolation, and weighted sums.
| lhs | Base vector. |
| rhs | Vector to add (after scaling). |
| s | Scalar weight applied to rhs. |
Definition at line 131 of file vec.h.
Referenced by bj_vec2_add_scaled().
Euclidean distance: ||a - b||.
| a | First vector. |
| b | Second vector. |
Squared Euclidean distance: ||a - b||^2.
Faster than bj_vec2_distance. No square root. Prefer this when you only need to compare distances or test against a squared threshold (d2 < r*r).
| a | First vector. |
| b | Second vector. |
Definition at line 255 of file vec.h.
Referenced by bj_vec2_distance().
Dot product: a.x*b.x + a.y*b.y.
| a | First vector. |
| b | Second vector. |
Definition at line 189 of file vec.h.
Referenced by bj_mat4_rotate_arcball().
Euclidean length: sqrt(x^2 + y^2).
| v | Input vector. |
Definition at line 219 of file vec.h.
Referenced by bj_mat4_rotate_arcball(), bj_vec2_scale_to_len(), and shader_code().
Apply a scalar function component-wise: (f(x), f(y)).
Use to lift any bj_real -> bj_real mapping (e.g. bj_sqrt, bj_abs, bj_floor, a user clamp) over a vector.
| a | Input vector. |
| f | Function to apply to each component. |
Definition at line 101 of file vec.h.
Referenced by bj_vec2_map(), and shader_code().
Component-wise maximum: (max(a.x,b.x), max(a.y,b.y)).
| a | First vector. |
| b | Second vector. |
Definition at line 333 of file vec.h.
Referenced by bj_vec2_max().
Component-wise minimum: (min(a.x,b.x), min(a.y,b.y)).
| a | First vector. |
| b | Second vector. |
Definition at line 322 of file vec.h.
Referenced by bj_vec2_min().
Component-wise (Hadamard) product: (v.x*s.x, v.y*s.y).
Use when each axis needs its own factor: anisotropic scaling, per-axis modulation, blending channel weights.
| v | Input vector. |
| s | Per-component scale vector. |
Definition at line 175 of file vec.h.
Referenced by bj_vec2_mul_comp().
Normalise to unit length (safe).
Computes v / ||v|| using one square root. Returns {0, 0} if the input is zero-length according to bj_real_is_zero, so it's safe on arbitrary input.
| v | Input vector. |
v, or {0, 0} if ||v|| == 0.Definition at line 286 of file vec.h.
Referenced by bj_mat4_rotate_arcball(), and bj_vec2_normalize().
Normalise to unit length (unsafe).
Same as bj_vec2_normalize but skips the zero-length check. Faster on hot paths where the caller can guarantee non-zero length; passing a zero vector produces undefined results.
| v | Input vector (must satisfy ||v|| > 0). |
v.Definition at line 310 of file vec.h.
Referenced by bj_vec2_normalize_unsafe().
2D perp-dot product (signed scalar): a.x*b.y - a.y*b.x.
The 2D analogue of the 3D cross product's z component. Sign tells you the orientation of (a, b): positive if b is to the left of a, negative if to the right, zero if collinear. Magnitude equals twice the signed area of the triangle (0, a, b).
Useful for orientation tests, signed-area computations, and segment-intersection predicates.
| a | First vector. |
| b | Second vector. |
Uniform scaling by a scalar: v * s.
| v | Input vector. |
| s | Scalar factor. |
Definition at line 160 of file vec.h.
Referenced by bj_vec2_scale(), bj_vec2_scale_to_len(), and shader_code().
Rescale a vector to a chosen length.
Equivalent to normalize(v) * L. Returns the zero vector if v is zero-length according to bj_real_is_zero, so it's safe on arbitrary input.
| v | Input vector. |
| L | Desired length of the result. |
Definition at line 235 of file vec.h.
Referenced by bj_vec2_scale_to_len().
Component-wise subtraction: lhs - rhs.
| lhs | Left-hand vector. |
| rhs | Right-hand vector. |
Definition at line 146 of file vec.h.
Referenced by bj_vec2_sub(), and shader_code().
Component-wise addition: lhs + rhs.
| lhs | Left-hand vector. |
| rhs | Right-hand vector. |
Definition at line 358 of file vec.h.
Referenced by bj_vec3_add(), and shader_code().
|
inlinestatic |
Fused scaled add: lhs + s * rhs.
| lhs | Base vector. |
| rhs | Vector to add (after scaling). |
| s | Scalar weight applied to rhs. |
Definition at line 374 of file vec.h.
Referenced by bj_vec3_add_scaled().
3D cross product: l × r (right-hand rule).
The result is perpendicular to both inputs; its length equals ||l|| * ||r|| * sin(theta) where theta is the angle between them. With the right-hand rule, x × y = z.
| l | Left-hand vector. |
| r | Right-hand vector. |
Definition at line 567 of file vec.h.
Referenced by bj_mat4_rotate_arcball(), bj_mat4_set_lookat(), bj_quat_rotate_vec3(), and bj_vec3_cross().
Euclidean distance: ||a - b||.
| a | First vector. |
| b | Second vector. |
Squared Euclidean distance: ||a - b||^2.
Faster than bj_vec3_distance. No square root. Prefer this when you only need to compare distances or test against a squared threshold.
| a | First vector. |
| b | Second vector. |
Definition at line 471 of file vec.h.
Referenced by bj_vec3_distance().
Dot product: a.x*b.x + a.y*b.y + a.z*b.z.
| a | First vector. |
| b | Second vector. |
Definition at line 426 of file vec.h.
Referenced by bj_mat4_orthonormalize(), bj_mat4_rotate_arcball(), and bj_vec3_reflect().
Euclidean length: sqrt(x^2 + y^2 + z^2).
| v | Input vector. |
Definition at line 436 of file vec.h.
Referenced by bj_mat4_rotate_axis_angle(), and bj_vec3_scale_to_len().
Apply a scalar function component-wise: (f(x), f(y), f(z)).
| a | Input vector. |
| f | Function to apply to each component. |
Definition at line 344 of file vec.h.
Referenced by bj_vec3_map().
Component-wise maximum.
| a | First vector. |
| b | Second vector. |
Definition at line 551 of file vec.h.
Referenced by bj_vec3_max().
Component-wise minimum.
| a | First vector. |
| b | Second vector. |
Definition at line 536 of file vec.h.
Referenced by bj_vec3_min().
Normalise to unit length (safe).
Computes v / ||v|| using one square root. Returns {0, 0, 0} if the input is zero-length according to bj_real_is_zero.
| v | Input vector. |
v, or {0, 0, 0} if ||v|| == 0.Definition at line 502 of file vec.h.
Referenced by bj_mat4_orthonormalize(), bj_mat4_set_lookat(), and bj_vec3_normalize().
Normalise to unit length (unsafe).
Same as bj_vec3_normalize but skips the zero-length check.
| v | Input vector (must satisfy ||v|| > 0). |
v.Definition at line 524 of file vec.h.
Referenced by bj_vec3_normalize_unsafe().
Reflect a vector about a surface normal: v - 2*dot(v, n)*n.
Mirrors v across the plane defined by the normal n. The result is only a true reflection when n is unit length; caller is responsible for normalising if needed.
| v | Input vector. |
| n | Surface normal (expected to be unit length). |
Definition at line 588 of file vec.h.
Referenced by bj_vec3_reflect().
Uniform scaling by a scalar: v * s.
| v | Input vector. |
| s | Scalar factor. |
Definition at line 411 of file vec.h.
Referenced by bj_mat4_orthonormalize(), bj_vec3_scale(), bj_vec3_scale_to_len(), and shader_code().
Rescale a vector to a chosen length.
Equivalent to normalize(v) * L. Returns the zero vector if v is zero-length according to bj_real_is_zero.
| v | Input vector. |
| L | Desired length of the result. |
Definition at line 451 of file vec.h.
Referenced by bj_vec3_scale_to_len().
Component-wise subtraction: lhs - rhs.
| lhs | Left-hand vector. |
| rhs | Right-hand vector. |
Definition at line 393 of file vec.h.
Referenced by bj_mat4_orthonormalize(), bj_mat4_set_lookat(), and bj_vec3_sub().
Component-wise addition: lhs + rhs.
| lhs | Left-hand vector. |
| rhs | Right-hand vector. |
Definition at line 619 of file vec.h.
Referenced by bj_vec4_add().
|
inlinestatic |
Fused scaled add: lhs + s * rhs.
| lhs | Base vector. |
| rhs | Vector to add (after scaling). |
| s | Scalar weight applied to rhs. |
Definition at line 636 of file vec.h.
Referenced by bj_vec4_add_scaled().
Cross product of the XYZ components, with w = 0.
Computes the 3D cross product on the xyz part of two 4D vectors, ignoring w. The result's w is set to zero so the output behaves as a direction (not a point) under homogeneous transforms.
| l | Left-hand vector. |
| r | Right-hand vector. |
Definition at line 789 of file vec.h.
Referenced by bj_vec4_cross_xyz().
Dot product over all four components.
| a | First vector. |
| b | Second vector. |
Definition at line 691 of file vec.h.
Referenced by bj_mat4_translate(), and bj_vec4_reflect().
Euclidean length: sqrt(x^2 + y^2 + z^2 + w^2).
| v | Input vector. |
Apply a scalar function component-wise to all four components.
| a | Input vector. |
| f | Function to apply to each component. |
Definition at line 605 of file vec.h.
Referenced by bj_vec4_map().
Component-wise maximum across all four components.
| a | First vector. |
| b | Second vector. |
Definition at line 768 of file vec.h.
Referenced by bj_vec4_max().
Component-wise minimum across all four components.
| a | First vector. |
| b | Second vector. |
Definition at line 752 of file vec.h.
Referenced by bj_vec4_min().
Normalise to unit length (safe).
Computes v / ||v|| using one square root. Returns {0, 0, 0, 0} if the input is zero-length according to bj_real_is_zero.
| v | Input vector. |
v, or {0, 0, 0, 0} if ||v|| == 0.Definition at line 718 of file vec.h.
Referenced by bj_vec4_normalize().
Normalise to unit length (unsafe).
Same as bj_vec4_normalize but skips the zero-length check.
| v | Input vector (must satisfy ||v|| > 0). |
v.Definition at line 740 of file vec.h.
Referenced by bj_vec4_normalize_unsafe().
Reflect a vector about a surface normal: v - 2*dot(v, n)*n.
Mirrors v across the plane defined by the normal n. The result is only a true reflection when n is unit length.
| v | Input vector. |
| n | Surface normal (expected to be unit length). |
Definition at line 809 of file vec.h.
Referenced by bj_vec4_reflect().
Uniform scaling by a scalar: v * s.
| v | Input vector. |
| s | Scalar factor. |
Definition at line 675 of file vec.h.
Referenced by bj_vec4_scale().
Component-wise subtraction: lhs - rhs.
| lhs | Left-hand vector. |
| rhs | Right-hand vector. |
Definition at line 656 of file vec.h.
Referenced by bj_vec4_sub().