code wiki / (root) / nx_camera_q14.nx

nx_camera_q14.nx

buildroot/runtime/nx_camera_q14.nx

24694 B662 linesdepth 3pulls 3 transitivereach 5 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

about

nx_camera_q14.nx -- camera + projection + 4x4 matrix math in Q14. /voxels runtime primitive per nxc2/docs/NISHI_GAME_ENGINE_ROADMAP.md. The math layer that powers view, projection, and per-vertex transform for the software rasterizer (queued). Flat-buffer API: every matrix is a 16-element i64 array (row-major, Q14 entries). Every vector is a 4-element i64 array. No struct usage by design -- this primitive stays WAT-clean for browser delivery today. Once self-host closes OP_GEP-on-WAT, a companion nx_camera_struct.nx will wrap these flat-buffer helpers behind a natural CameraState struct. Both APIs ship side-by-side after that. Q14 convention (matches nx_matrix.nx + nx_sound.nx): 1.0 = 16384. Compose freely with existing primitives that use Q14. Trig: 19-entry sin table at 5-degree resolution covering 0..90. Symmetry folds extend to 0..360. Linear interpolation between table entries yields ~0.5 degree max error -- acceptable for general camera control where the eye cannot distinguish under 1 degree. FULL CAPABILITY (per feedback-maximum-capability-no-simplification cardinal, 2026-05-16): higher-resolution variants use Bhaskara I's sin approximation (closed-form rational, accurate to ~0.0017 peak absolute error = ~28 Q14 units, no table required). Variants: nx_camera_sin_q14_centideg(d100): input in centi-degrees, range [-36000, 36000] -- 0.01-degree precision nx_camera_sin_q14_millideg(d1000): input in milli-degrees, range [-360000, 360000] -- 0.001-degree precision Both variants use the same Bhaskara closed-form, scaled to the integer input unit. The 5-degree table remains the legacy API for callers that don't need sub-degree precision. Loss audit: - Q14 multiplications lose 14 fractional bits per multiply. For

dependencies 3 imports · 5 importers

nx_syscalls.nx nx_hal.nx nx_tier.nx nx_camera_q14.nx nx_mountain_chain.nx nx_pets_voxel3d.nx nx_river_carve.nx nx_silhouette_quality.nx nx_weather_pattern.nx

imports: nx_syscalls.nxnx_hal.nxnx_tier.nx

imported by: nx_mountain_chain.nxnx_pets_voxel3d.nxnx_river_carve.nxnx_silhouette_quality.nxnx_weather_pattern.nx

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main nx_camera_sin_q14_deg _normalise_deg _sin_table_alloc sys_mmap nx_hal_exit nx_hal_active_shim nx_hal_exit_linux nx_hal_exit_bare_metal nx_hal_exit_nishi_silicon nx_camera_cos_q14_deg nx_camera_sin_q14_deg ↻ sys_mmap ↻ nx_camera_identity_4x4 nx_camera_translation_4x4 nx_camera_identity_4x4 ↻ nx_camera_rotation_y_deg nx_camera_cos_q14_deg ↻ nx_camera_sin_q14_deg ↻ nx_camera_identity_4x4 ↻ nx_camera_mat4_mul nx_camera_mat4_vec4 nx_camera_perspective nx_camera_cos_q14_deg ↻ nx_camera_sin_q14_deg ↻ nx_camera_identity_4x4 ↻ nx_camera_sin_q14_centideg _normalise_centideg nx_camera_cos_q14_centideg nx_camera_sin_q14_centideg ↻ nx_camera_sin_q14_millideg _normalise_millideg

structs

none

consts

70const NX_MAGIC_1428: i64 = 1428
71const NX_MAGIC_2845: i64 = 2845
72const NX_MAGIC_4240: i64 = 4240
73const NX_MAGIC_5604: i64 = 5604
74const NX_MAGIC_6923: i64 = 6923
75const NX_MAGIC_8192: i64 = 8192
76const NX_MAGIC_9397: i64 = 9397
77const NX_MAGIC_10531: i64 = 10531
78const NX_MAGIC_11585: i64 = 11585
79const NX_MAGIC_12551: i64 = 12551
80const NX_MAGIC_13421: i64 = 13421
81const NX_MAGIC_14189: i64 = 14189
82const NX_MAGIC_14849: i64 = 14849
83const NX_MAGIC_15394: i64 = 15394
84const NX_MAGIC_15824: i64 = 15824
85const NX_MAGIC_16134: i64 = 16134
86const NX_MAGIC_16321: i64 = 16321
87const NX_MAGIC_16384: i64 = 16384
88const NX_MAGIC_36000: i64 = 36000
89const NX_MAGIC_27000: i64 = 27000
90const NX_MAGIC_18000: i64 = 18000
91const NX_MAGIC_9000: i64 = 9000
92const NX_MAGIC_405000000: i64 = 405000000
93const NX_MAGIC_360000: i64 = 360000
94const NX_MAGIC_270000: i64 = 270000
95const NX_MAGIC_180000: i64 = 180000
96const NX_MAGIC_90000: i64 = 90000
97const NX_MAGIC_40500000000: i64 = 40500000000
98const NX_MAGIC_14000: i64 = 14000
99const NX_MAGIC_3000: i64 = 3000
100const NX_MAGIC_8162: i64 = 8162
101const NX_MAGIC_8222: i64 = 8222
102const NX_MAGIC_45000: i64 = 45000
103const NX_MAGIC_45001: i64 = 45001
104const NX_MAGIC_11530: i64 = 11530
105const NX_MAGIC_11620: i64 = 11620
108const NX_CAM_Q: nx_int = 16384
116const NX_CAM_M4_ELEMS: nx_int = 16
117const NX_CAM_M4_BYTES: nx_int = 128 // 16 * 8
120const NX_CAM_V4_ELEMS: nx_int = 4
121const NX_CAM_V4_BYTES: nx_int = 32
124const NX_CAM_TRIG_RES_DEG: nx_int = 5 // table entry every 5 degrees
125const NX_CAM_TRIG_N: nx_int = 19 // 0, 5, 10, ..., 85, 90 = 19 entries

functions

132func _sin_table_alloc() -> *i64
called by 1: nx_camera_sin_q14_deg calls 1: sys_mmap
157func _normalise_deg(deg: nx_int) -> nx_int
172func nx_camera_sin_q14_deg(deg: nx_int) -> nx_int
210func nx_camera_cos_q14_deg(deg: nx_int) -> nx_int
227func _normalise_centideg(d100: nx_int) -> nx_int
234func nx_camera_sin_q14_centideg(d100: nx_int) -> nx_int
263func nx_camera_cos_q14_centideg(d100: nx_int) -> nx_int
275func _normalise_millideg(d1000: nx_int) -> nx_int
282func nx_camera_sin_q14_millideg(d1000: nx_int) -> nx_int
309func nx_camera_cos_q14_millideg(d1000: nx_int) -> nx_int
324func nx_camera_identity_4x4(out: *i64) -> *i64
338func nx_camera_translation_4x4(tx: nx_int, ty: nx_int, tz: nx_int, out: *i64) -> *i64
352func nx_camera_rotation_y_deg(deg: nx_int, out: *i64) -> *i64
368func nx_camera_rotation_x_deg(deg: nx_int, out: *i64) -> *i64
396func nx_camera_perspective(
456func nx_camera_mat4_mul(a: *i64, b: *i64, out: *i64) -> *i64
called by 2: mainvp_build_mvp
480func nx_camera_mat4_vec4(m: *i64, v: *i64, out: *i64) -> *i64
called by 2: mainvp_project
496func main() -> i64