nx_raycast_voxel.nx
buildroot/runtime/nx_raycast_voxel.nx
about
nx_raycast_voxel.nx -- DDA voxel ray traversal.
Per user 2026-05-19 session 1: "we want to build minecraft
equivalent on the lowest possible hardware." THE rendering core
for that vision. Digital Differential Analyzer ray traversal walks
a ray from camera through nx_tissue voxel grid, returning the
first non-empty voxel + distance + which face was hit.
Fixed-point math throughout — NO floating point. Per cardinals
minimum-hardware-floor + bits-up-exceed-never-match: this primitive
runs on Cortex-M0+ (no FPU) without modification.
Q14 fixed point: 16384 = 1.0; range ~ -131072 to +131071 (covers
32x32x32 worlds with headroom for camera + direction vectors).
Composes:
nx_tissue -- the voxel world being traversed
nx_palette -- voxel palette indices returned on hit
nx_fb_1bpp -- caller renders the hit results into framebuffer
nx_metabolism -- raycast is the canonical hot path that
metabolism promotes through tier ladder
V1 ships:
- sealed enum NxRayFace (which face of voxel was hit)
- struct NxRay + NxRayHit
- cast: DDA walk; returns first non-empty voxel or MISS
- normalize_q14: caller-helper to scale a direction to Q14
dependencies 3 imports · 4 importers
imports: nx_syscalls.nxnx_tier.nxnx_tissue.nx
imported by: nx_game_engine_compose_test.nxnx_minecraft_mcu_compose_test.nxnx_pets_voxel_view.nxnx_raycast_voxel_test.nx
structs
| 60 | struct NxRay |
| 72 | struct NxRayHit |
consts
| 32 | const NX_MAGIC_2147483647: i64 = 2147483647 |
| 34 | const NX_RV_Q14: nx_int = 16384 |
| 38 | const NX_RF_NONE: nx_int = 0 |
| 39 | const NX_RF_X_POS: nx_int = 1 |
| 40 | const NX_RF_X_NEG: nx_int = 2 |
| 41 | const NX_RF_Y_POS: nx_int = 3 |
| 42 | const NX_RF_Y_NEG: nx_int = 4 |
| 43 | const NX_RF_Z_POS: nx_int = 5 |
| 44 | const NX_RF_Z_NEG: nx_int = 6 |
| 45 | const NX_RF_N_FACES: nx_int = 7 |
| 49 | const NX_RV_HIT: nx_int = 0 |
| 50 | const NX_RV_MISS: nx_int = 1 |
| 51 | const NX_RV_OUT_OF_BOX: nx_int = 2 |
| 52 | const NX_RV_MAX_STEPS: nx_int = 3 |
functions
| 82 | func nx_rf_is_valid(f: nx_int) -> nx_int called by 1: main |
| 90 | func _abs_q14(x: nx_int) -> nx_int called by 1: nx_raycast_voxel |
| 97 | func _sign(x: nx_int) -> nx_int called by 1: nx_raycast_voxel |
| 105 | func nx_ray_new(origin_x_q14: nx_int, origin_y_q14: nx_int, origin_z_q14: nx_int, |
| 130 | func nx_raycast_voxel(ray: *NxRay, world: *NxTissue, out: *NxRayHit) -> nx_int |
| 245 | func nx_ray_hit_face_normal_q14(hit: *NxRayHit, out_nx_q14: *i64, called by 1: main |