nx_ballistics.nx
buildroot/runtime/nx_ballistics.nx
about
nx_ballistics.nx -- Simulates projectile motion with and without air drag for ballistic trajectory visualization.
dependencies 0 imports · 1 importers
imports: none
imported by: nx_ballistics_gate.nx
structs
| none |
consts
| 2 | const O_MAGIC_3141593: i64 = 3141593 |
| 3 | const O_MAGIC_6283185: i64 = 6283185 |
| 4 | const O_MAGIC_1570796: i64 = 1570796 |
| 5 | const O_MAGIC_4096: i64 = 4096 |
| 13 | const W: i64 = 256 |
| 14 | const H: i64 = 256 |
| 15 | const O_FB: i64 = 0 |
| 16 | const N: i64 = 2 // 0 = vacuum, 1 = drag |
| 17 | const O_X: i64 = 524288 |
| 18 | const O_Y: i64 = 524304 |
| 19 | const O_VX: i64 = 524320 |
| 20 | const O_VY: i64 = 524336 |
| 21 | const O_GND: i64 = 524352 // grounded flags |
| 22 | const O_WX: i64 = 524368 |
| 23 | const O_WY: i64 = 524376 |
| 24 | const O_STEP: i64 = 524384 |
| 25 | const O_RST: i64 = 524392 // post-landing pause counter |
| 26 | const O_TR: i64 = 524400 // trails: N*TRAILN*2 (display px) |
| 27 | const TRAILN: i64 = 160 |
| 28 | const SC: i64 = 1000000 |
| 29 | const V0: i64 = 200000 // launch speed |
| 30 | const GSTEP: i64 = 200 // gravity (velocity decrement / step) |
| 31 | const K: i64 = 1 // drag coefficient |
| 32 | const DSCALE: i64 = 566000000 // drag divisor (tunes drag ~25% of gravity at launch) |
| 33 | const LAUNCH: i64 = 959931 // 55 deg in micro-rad |
| 34 | const STEPS_PER_TICK: i64 = 8 |
functions
| 36 | func rgb(r: i64, g: i64, b: i64) -> i64 { return (r & 255) | ((g & 255) << 8) | ((b & 255) << 16) } called by 1: render_impl |
| 37 | func isqrt(N0: i64) -> i64 { if N0<2 { return N0 } var x: i64=N0; var y: i64=(x+1)/2; while y<x { x=y; y=(x + N0/x)/2 } return x } called by 1: vmag |
| 38 | func sin_fixed(Xin: i64) -> i64 |
| 50 | func cos_fixed(X: i64) -> i64 { return sin_fixed(X+O_MAGIC_1570796) } |
| 51 | func vmag(vx: i64, vy: i64) -> i64 { return isqrt(vx*vx+vy*vy) } |
| 53 | func acc_x(vx: i64, vy: i64, drag: i64) -> i64 { if drag==0 { return 0 } return 0 - K*vmag(vx,vy)*vx/DSCALE } |
| 54 | func acc_y(vx: i64, vy: i64, drag: i64) -> i64 { if drag==0 { return 0-GSTEP } return (0-GSTEP) - K*vmag(vx,vy)*vy/DSCALE } |
| 56 | func putpx(base: i64, px: i64, py: i64, c: i64) -> i64 |
| 60 | func disc(base: i64, px: i64, py: i64, r: i64, c: i64) -> i64 |
| 67 | func clear_fb(base: i64, c: i64) -> i64 { let fb: *i64=(base+O_FB) as *i64; var i: i64=0; while i<W*H { fb[i]=c; i=i+1 } return 0 } called by 1: render_impl |
| 69 | func init_impl(base: i64) -> i64 |
| 83 | func step_one_impl(base: i64) -> i64 |
| 97 | func wx_to_px(base: i64, wx: i64) -> i64 { let WX: *i64=(base+O_WX) as *i64; return 4 + wx*248/WX[0] } |
| 98 | func wy_to_py(base: i64, wy: i64) -> i64 { let WY: *i64=(base+O_WY) as *i64; return 250 - wy*242/WY[0] } |
| 99 | func record_trail(base: i64) -> i64 |
| 106 | func tick_impl(base: i64, cmd: i64) -> i64 |
| 118 | func render_impl(base: i64) -> i64 |
| 137 | func ww() -> i64 { return W } called by 1: main |
| 138 | func hh() -> i64 { return H } called by 1: main |
| 139 | func fb_off() -> i64 { return O_FB } called by 1: main |
| 140 | func init() -> i64 { return init_impl(0) } calls 1: init_impl |
| 141 | func tick(cmd: i64) -> i64 { return tick_impl(0, cmd) } calls 1: tick_impl |
| 142 | func render() -> i64 { return render_impl(0) } calls 1: render_impl |
| 143 | func mem_bytes() -> i64 { return O_TR + N*TRAILN*2*8 + O_MAGIC_4096 } called by 1: main |