|
Banjo API 1.0.0-rc.2
Low-level C99 game development API
|
Go to the source code of this file.
Data Structures | |
| struct | bj_vec2 |
| struct | bj_vec3 |
| struct | bj_vec4 |
Macros | |
| #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 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) |
Fixed-size vector types (2D, 3D, 4D) and inline operations.
Three plain-struct vector types (bj_vec2, bj_vec3, bj_vec4), each holding bj_real components. They're POD: just the named fields, no padding, no hidden state, so they interoperate freely with arrays, file I/O, and other libraries that want the same layout.
All functions in this header are header-only static BJ_INLINE and pass/return vectors by value. With three or four components per vector that's the cheap path; the compiler keeps everything in registers and the API reads like math.
What's here, per dimension: addition, subtraction, scaling, scaled addition (a + s*b), component-wise product, dot product, length and squared length, distance and squared distance, safe and unsafe normalisation, component-wise min/max, and (for 3D and 4D) cross product and reflection.
Coordinate convention. For 3D, the cross product follows the right-hand rule: x × y = z. For 2D pixel coordinates as used by the bitmap/drawing subsystems, X increases right and Y increases downward (top-left origin); see Bitmap.
Safe vs unsafe normalisation. The *_normalize functions guard against zero-length input via bj_real_is_zero and return the zero vector in that case. The *_normalize_unsafe variants skip the check and are faster on hot paths where the caller can guarantee non-zero length; passing a zero-length vector to them is undefined.
Definition in file vec.h.