nx_phys3d.nx
buildroot/runtime/nx_phys3d.nx
about
nx_phys3d.nx -- the UNIFIED sovereign 3D rigid-body physics core (the 07-01 census's named gap; operator
2026-07-03: "real 3d s class exceed physics"). ONE engine for games + sim + CAD-motion: semi-implicit Euler,
sphere/AABB contacts, sequential impulse solver (restitution + Coulomb friction + positional correction),
sleeping. ALL INTEGER (deterministic law: fixed-point pos=1/256 m, vel=1/65536 m-per-tick; 60Hz implied) --
byte-identical replays by construction, no float, no libm. Base-relative so the same code runs native AND
in-wasm (mineworld pattern). Broadphase is O(n^2) pairs at this rung (BVH = ladder R4); shapes = sphere +
axis-aligned box (GJK convex = R5; rotation/orientation = R6 with joints -- stated, not hidden).
license_tier: ORIGINAL
dependencies 1 imports · 2 importers
imports: nx_syscalls.nx
imported by: nx_phys3d_gate.nxnx_wasm_physlab.nx
structs
| none |
consts
| 15 | const PH_MAXB: i64 = 64 |
| 16 | const PH_G: i64 = 178 // ~9.8 m/s^2 at 60Hz in vel-units (0.00272 m/tick * 65536) |
| 17 | const PH_SLOP: i64 = 4 // penetration allowance (fx256) |
| 18 | const PH_POSPCT: i64 = 128 // positional correction percent (fx256 of penetration beyond slop) |
| 19 | const PH_RESTV: i64 = 400 // |vn| below this -> restitution treated as 0 (rest, standard trick) |
| 20 | const PH_SLEEPV: i64 = 80 // per-axis |v| threshold for stillness |
| 21 | const PH_SLEEPN: i64 = 30 // still frames before sleep |
| 22 | const PH_ITERS: i64 = 6 // solver iterations per tick |
functions
| 24 | func ph_hdr(base: i64) -> *i64 { return base as *i64 } // [0]=nbodies [1]=tick [2..7]=spare |
| 25 | func ph_body(base: i64, id: i64) -> *i64 { return (base + 64 + id * 128) as *i64 } |
| 30 | func ph_acc(base: i64) -> *i64 { return (base + 64 + PH_MAXB * 128) as *i64 } |
| 31 | func ph_warm(base: i64) -> *i64 { return (base + 64 + PH_MAXB * 128 + PH_MAXB * PH_MAXB * 8) as *i64 } |
| 36 | func ph_tgt(base: i64) -> *i64 { return (base + 64 + PH_MAXB * 128 + PH_MAXB * PH_MAXB * 16) as *i64 } |
| 37 | func ph_bytes() -> i64 { return 64 + PH_MAXB * 128 + PH_MAXB * PH_MAXB * 24 } called by 1: main |
| 39 | func ph_init(base: i64) -> i64 |
| 51 | func ph_add(base: i64, shape: i64, x: i64, y: i64, z: i64, hx: i64, hy: i64, hz: i64, invm: i64, rest: i64, fric: i64) -> i64 |
| 70 | func ph_set_vel(base: i64, id: i64, vx: i64, vy: i64, vz: i64) -> i64 |
| 78 | func ph_iabs(v: i64) -> i64 { if v < 0 { return 0 - v } return v } |
| 79 | func ph_min(a: i64, b: i64) -> i64 { if a < b { return a } return b } |
| 81 | func ph_isqrt(v: i64) -> i64 |
| 94 | func ph_contact(base: i64, ia: i64, ib: i64, nx: i64, ny: i64, nz: i64, pen: i64, docorr: i64) -> i64 |
| 184 | func ph_pair(base: i64, ia: i64, ib: i64, docorr: i64) -> i64 |
| 232 | func ph_imax(a: i64, b: i64) -> i64 { if a > b { return a } return b } |
| 234 | func ph_step(base: i64) -> i64 |