Files
jak-project/goal_src/jak1/engine/camera/cam-debug.gc
T
2026-07-28 12:00:35 -07:00

1067 lines
61 KiB
Common Lisp

;;-*-Lisp-*-
(in-package goal)
(bundles "ENGINE.CGO" "GAME.CGO")
(require "engine/collide/pat-h.gc")
(require "engine/anim/joint-mod-h.gc")
(require "engine/math/euler.gc")
(require "engine/geometry/bounding-box-h.gc")
(require "engine/debug/debug.gc")
(require "engine/collide/collide-mesh-h.gc")
(require "engine/camera/camera.gc")
;; DECOMP BEGINS
;; this file is debug only
(declare-file (debug))
(when (or (not *camera-old-cpu*) (zero? *camera-old-cpu*))
(set! *camera-old-cpu* 0)
0)
(when (or (not *camera-old-vu*) (zero? *camera-old-vu*))
(set! *camera-old-vu* 0)
0)
(when (or (not *camera-old-tfrag-bytes*) (zero? *camera-old-tfrag-bytes*))
(set! *camera-old-tfrag-bytes* 0)
0)
(define-perm *camera-old-level* string (new 'global 'string 128 (the-as string #f)))
(define-perm *camera-old-stat-string-tfrag* string (new 'global 'string 128 (the-as string #f)))
(define-perm *camera-old-stat-string-tfrag-near* string (new 'global 'string 128 (the-as string #f)))
(define-perm *camera-old-stat-string-total* string (new 'global 'string 128 (the-as string #f)))
(deftype cam-dbg-scratch (structure)
((linevec4w vector4w 2 :inline :offset-assert 0)
(color vector :inline :offset-assert 32)
(plotvec vector4w 2 :inline :offset-assert 48)
(linevec vector4w 2 :inline :offset-assert 80)
(rel-vec vector :inline :offset-assert 112)
(sphere-v-start vector :inline :offset-assert 128)
(sphere-v-end vector :inline :offset-assert 144)
(sphere-v-down vector :inline :offset-assert 160)
(sphere-vec vector :inline :offset-assert 176)
(crossvec vector 3 :inline :offset-assert 192)
(bboxvec vector 6 :inline :offset-assert 240)
(fov-vv vector 4 :inline :offset-assert 336)
(fov-src vector :inline :offset-assert 400)
(fov-dest vector :inline :offset-assert 416)
(fov-vert vector :inline :offset-assert 432)
(fov-horz vector :inline :offset-assert 448))
:method-count-assert 9
:size-assert #x1d0
:flag-assert #x9000001d0)
(defmethod inspect ((obj cam-dbg-scratch))
(format #t "[~8x] ~A~%" obj 'cam-dbg-scratch)
(format #t "~Tlinevec4w[2] @ #x~X~%" (-> obj linevec4w))
(format #t "~Tcolor: ~`vector`P~%" (-> obj color))
(format #t "~Tplotvec[2] @ #x~X~%" (-> obj plotvec))
(format #t "~Tlinevec[2] @ #x~X~%" (-> obj linevec))
(format #t "~Trel-vec: ~`vector`P~%" (-> obj rel-vec))
(format #t "~Tsphere-v-start: ~`vector`P~%" (-> obj sphere-v-start))
(format #t "~Tsphere-v-end: ~`vector`P~%" (-> obj sphere-v-end))
(format #t "~Tsphere-v-down: ~`vector`P~%" (-> obj sphere-v-down))
(format #t "~Tsphere-vec: ~`vector`P~%" (-> obj sphere-vec))
(format #t "~Tcrossvec[3] @ #x~X~%" (-> obj crossvec))
(format #t "~Tbboxvec[6] @ #x~X~%" (-> obj bboxvec))
(format #t "~Tfov-vv[4] @ #x~X~%" (-> obj fov-vv))
(format #t "~Tfov-src: ~`vector`P~%" (-> obj fov-src))
(format #t "~Tfov-dest: ~`vector`P~%" (-> obj fov-dest))
(format #t "~Tfov-vert: ~`vector`P~%" (-> obj fov-vert))
(format #t "~Tfov-horz: ~`vector`P~%" (-> obj fov-horz))
obj)
(defun cam-slave-options->string ((options cam-slave-options) (output object))
"Append the names of the enabled camera-slave option bits to output and
return output as a string."
(if (= (logand (cam-slave-options AIR_EXIT) options) (cam-slave-options AIR_EXIT)) (format output "AIR_EXIT "))
(if (= (logand (cam-slave-options STICKY_ANGLE) options) (cam-slave-options STICKY_ANGLE)) (format output "STICKY_ANGLE "))
(if (= (logand options (cam-slave-options NO_ROTATE)) (cam-slave-options NO_ROTATE)) (format output "NO_ROTATE "))
(if (= (logand options (cam-slave-options BIKE_MODE)) (cam-slave-options BIKE_MODE)) (format output "BIKE_MODE "))
(if (= (logand options (cam-slave-options BLOCK_SHIFT_BUTTONS)) (cam-slave-options BLOCK_SHIFT_BUTTONS))
(format output "BLOCK_SHIFT_BUTTONS "))
(if (= (logand options (cam-slave-options GOTO_GOOD_POINT)) (cam-slave-options GOTO_GOOD_POINT))
(format output "GOTO_GOOD_POINT "))
(if (= (logand options (cam-slave-options SHRINK_MAX_ANGLE)) (cam-slave-options SHRINK_MAX_ANGLE))
(format output "SHRINK_MAX_ANGLE "))
(if (= (logand options (cam-slave-options MOVEMENT_BLOCKED)) (cam-slave-options MOVEMENT_BLOCKED))
(format output "MOVEMENT_BLOCKED "))
(if (= (logand options (cam-slave-options LINE_OF_SIGHT)) (cam-slave-options LINE_OF_SIGHT))
(format output "LINE_OF_SIGHT "))
(if (= (logand options (cam-slave-options PLAYER_MOVING_CAMERA)) (cam-slave-options PLAYER_MOVING_CAMERA))
(format output "PLAYER_MOVING_CAMERA "))
(if (= (logand options (cam-slave-options DRAG)) (cam-slave-options DRAG)) (format output "DRAG "))
(if (= (logand options (cam-slave-options FIND_HIDDEN_TARGET)) (cam-slave-options FIND_HIDDEN_TARGET))
(format output "FIND_HIDDEN_TARGET "))
(if (= (logand options (cam-slave-options COLLIDE)) (cam-slave-options COLLIDE)) (format output "COLLIDE "))
(if (= (logand options (cam-slave-options JUMP_PITCHES)) (cam-slave-options JUMP_PITCHES)) (format output "JUMP_PITCHES "))
(if (= (logand options (cam-slave-options ALLOW_Z_ROT)) (cam-slave-options ALLOW_Z_ROT)) (format output "ALLOW_Z_ROT "))
(if (= (logand options (cam-slave-options MOVE_SPHERICAL)) (cam-slave-options MOVE_SPHERICAL))
(format output "MOVE_SPHERICAL "))
(if (= (logand options (cam-slave-options SAME_SIDE)) (cam-slave-options SAME_SIDE)) (format output "SAME_SIDE "))
(if (= (logand options (cam-slave-options BUTT_CAM)) (cam-slave-options BUTT_CAM)) (format output "BUTT_CAM "))
(the-as string output))
(defun cam-index-options->string ((options cam-index-options) (output object))
"Append the historical labels for the enabled camera-index option bits to
output. These strings are opposite the current SPHERICAL and RADIAL enum
names."
(if (= (logand options (cam-index-options SPHERICAL)) (cam-index-options SPHERICAL)) (format output "RADIAL "))
(if (= (logand options (cam-index-options RADIAL)) (cam-index-options RADIAL)) (format output "SPHERICAL "))
(the-as string output))
(defun slave-los-state->string ((los-state slave-los-state))
"Return the debug name of a camera line-of-sight state, or *unknown* for an
unrecognized value."
(case los-state
(((slave-los-state between)) "between")
(((slave-los-state ccw)) "ccw")
(((slave-los-state cw)) "cw")
(((slave-los-state none)) "none")
(else "*unknown*")))
(defun cam-line-dma ()
"Append the current transformed debug-line endpoints and color to the
no-depth-test debug DMA bucket."
(with-dma-buffer-add-bucket ((debug-buffer (-> *display* frames (-> *display* on-screen) frame debug-buf)) (bucket-id debug-no-zbuf)) :bucket-group (-> *display* frames (-> *display* on-screen) frame bucket-group) (let ((cnt-tag (the-as object (-> debug-buffer base))))
(let* ((write-buffer debug-buffer)
(dma-header (the-as object (-> write-buffer base))))
(set! (-> (the-as dma-packet dma-header) dma) (new 'static 'dma-tag :id (dma-tag-id cnt)))
(set! (-> (the-as dma-packet dma-header) vif0) (new 'static 'vif-tag))
(set! (-> (the-as dma-packet dma-header) vif1) (new 'static 'vif-tag :cmd (vif-cmd direct) :msk #x1))
(set! (-> write-buffer base) (&+ (the-as pointer dma-header) 16)))
(let* ((write-buffer debug-buffer)
(gif-header (the-as object (-> write-buffer base))))
(set! (-> (the-as gs-gif-tag gif-header) tag)
(new 'static
'gif-tag64
:nloop #x1
:eop #x1
:pre #x1
:prim
(new 'static 'gs-prim :prim (gs-prim-type line) :iip #x1 :abe #x1)
:nreg #x4))
(set! (-> (the-as gs-gif-tag gif-header) regs)
(new 'static
'gif-tag-regs
:regs0 (gif-reg-id rgbaq)
:regs1 (gif-reg-id xyzf2)
:regs2 (gif-reg-id rgbaq)
:regs3 (gif-reg-id xyzf2)))
(set! (-> write-buffer base) (&+ (the-as pointer gif-header) 16)))
(let* ((write-buffer debug-buffer)
(vertex-packet (-> write-buffer base)))
(set! (-> (the-as (pointer uint128) vertex-packet) 0) (-> (the-as vector (+ 32 (scratchpad-object int))) quad))
(set! (-> (the-as (pointer uint128) vertex-packet) 1)
(-> (the-as vector (-> (scratchpad-object cam-dbg-scratch) linevec4w)) quad))
(set! (-> write-buffer base) (&+ vertex-packet 32)))
(let* ((write-buffer debug-buffer)
(vertex-packet (-> write-buffer base)))
(set! (-> (the-as (pointer uint128) vertex-packet) 0) (-> (the-as vector (+ 32 (scratchpad-object int))) quad))
(set! (-> (the-as (pointer uint128) vertex-packet) 1) (-> (the-as vector (+ 16 (scratchpad-object int))) quad))
(set! (-> write-buffer base) (&+ vertex-packet 32)))
(let ((qwc (/ (the-as int (+ (- -16 (the-as int cnt-tag)) (the-as int (-> debug-buffer base)))) 16)))
(cond
((nonzero? qwc)
(logior! (-> (the-as dma-packet cnt-tag) dma) (shr (shl qwc 48) 48))
(logior! (-> (the-as (pointer uint64) cnt-tag) 1) (shl (shr (shl qwc 48) 48) 32)))
(else (set! (-> debug-buffer base) (the-as (pointer uint64) cnt-tag))))))))
(defun camera-line2d ((start vector4w) (end vector4w))
"Draw a line between two screen-space points. Convert pixels to GS 12.4
coordinates, invert Y, and place both endpoints at the far 24-bit depth."
(set! (-> (scratchpad-object cam-dbg-scratch) linevec4w 0 x) (* (+ (-> start x) 1792) 16))
(set! (-> (scratchpad-object cam-dbg-scratch) linevec4w 0 y) (* (- (-> *video-parms* screen-maxy) (-> start y)) 16))
(set! (-> (scratchpad-object cam-dbg-scratch) linevec4w 0 z) #x7fffff)
(set! (-> (scratchpad-object cam-dbg-scratch) linevec4w 1 x) (* (+ (-> end x) 1792) 16))
(set! (-> (scratchpad-object cam-dbg-scratch) linevec4w 1 y) (* (- (-> *video-parms* screen-maxy) (-> end y)) 16))
(set! (-> (scratchpad-object cam-dbg-scratch) linevec4w 1 z) #x7fffff)
(cam-line-dma))
(defun camera-plot-float-func ((x-min float) (x-max float) (y-min float) (y-max float) (fn (function float float)) (color vector4w))
"Plot fn over [x-min, x-max] in a 400 by 200 pixel debug graph. Map
[y-min, y-max] to the plot height, draw the axes and border at screen offset
(20, 20), then connect one sample per horizontal pixel in color."
(let ((x-range (- x-max x-min))
(y-range (- y-max y-min)))
0.0
0.0
(let ((y-scale (/ 200.0 y-range))
(x-scale (/ 400.0 x-range)))
(set! (-> (scratchpad-object cam-dbg-scratch) color x) (the-as float 128))
(set! (-> (scratchpad-object cam-dbg-scratch) color y) (the-as float 128))
(set! (-> (scratchpad-object cam-dbg-scratch) color z) (the-as float 128))
(set! (-> (scratchpad-object cam-dbg-scratch) color w) (the-as float 128))
(when (and (< x-min 0.0) (< 0.0 x-max))
(set! (-> (scratchpad-object cam-dbg-scratch) plotvec 0 x) (+ (the int (* x-scale x-range (/ (- x-min) x-range))) 20))
(set! (-> (scratchpad-object cam-dbg-scratch) plotvec 0 y) 20)
(set! (-> (scratchpad-object cam-dbg-scratch) plotvec 1 x) (-> (scratchpad-object cam-dbg-scratch) plotvec 0 x))
(set! (-> (scratchpad-object cam-dbg-scratch) plotvec 1 y) (+ (the int (* y-scale y-range)) 20))
(camera-line2d (the-as vector4w (+ 48 (scratchpad-object int))) (the-as vector4w (+ 64 (scratchpad-object int)))))
(when (and (< y-min 0.0) (< 0.0 y-max))
(set! (-> (scratchpad-object cam-dbg-scratch) plotvec 0 x) 20)
(set! (-> (scratchpad-object cam-dbg-scratch) plotvec 0 y) (+ (the int (* y-scale y-range (/ (- y-min) y-range))) 20))
(set! (-> (scratchpad-object cam-dbg-scratch) plotvec 1 x) (+ (the int (* x-scale x-range)) 20))
(set! (-> (scratchpad-object cam-dbg-scratch) plotvec 1 y) (-> (scratchpad-object cam-dbg-scratch) plotvec 0 y))
(camera-line2d (the-as vector4w (+ 48 (scratchpad-object int))) (the-as vector4w (+ 64 (scratchpad-object int)))))
(set! (-> (scratchpad-object cam-dbg-scratch) plotvec 0 x) 20)
(set! (-> (scratchpad-object cam-dbg-scratch) plotvec 0 y) 20)
(set! (-> (scratchpad-object cam-dbg-scratch) plotvec 1 x) (+ (the int (* x-scale x-range)) 20))
(set! (-> (scratchpad-object cam-dbg-scratch) plotvec 1 y) 20)
(camera-line2d (the-as vector4w (+ 48 (scratchpad-object int))) (the-as vector4w (+ 64 (scratchpad-object int))))
(set! (-> (scratchpad-object cam-dbg-scratch) plotvec 0 x) 20)
(set! (-> (scratchpad-object cam-dbg-scratch) plotvec 0 y) (+ (the int (* y-scale y-range)) 20))
(set! (-> (scratchpad-object cam-dbg-scratch) plotvec 1 x) (+ (the int (* x-scale x-range)) 20))
(set! (-> (scratchpad-object cam-dbg-scratch) plotvec 1 y) (+ (the int (* y-scale y-range)) 20))
(camera-line2d (the-as vector4w (+ 48 (scratchpad-object int))) (the-as vector4w (+ 64 (scratchpad-object int))))
(set! (-> (scratchpad-object cam-dbg-scratch) plotvec 0 x) 20)
(set! (-> (scratchpad-object cam-dbg-scratch) plotvec 0 y) 20)
(set! (-> (scratchpad-object cam-dbg-scratch) plotvec 1 x) 20)
(set! (-> (scratchpad-object cam-dbg-scratch) plotvec 1 y) (+ (the int (* y-scale y-range)) 20))
(camera-line2d (the-as vector4w (+ 48 (scratchpad-object int))) (the-as vector4w (+ 64 (scratchpad-object int))))
(set! (-> (scratchpad-object cam-dbg-scratch) plotvec 0 x) (+ (the int (* x-scale x-range)) 20))
(set! (-> (scratchpad-object cam-dbg-scratch) plotvec 0 y) 20)
(set! (-> (scratchpad-object cam-dbg-scratch) plotvec 1 x) (+ (the int (* x-scale x-range)) 20))
(set! (-> (scratchpad-object cam-dbg-scratch) plotvec 1 y) (+ (the int (* y-scale y-range)) 20))
(camera-line2d (the-as vector4w (+ 48 (scratchpad-object int))) (the-as vector4w (+ 64 (scratchpad-object int))))
(let ((color-quad (-> color quad))) (set! (-> (scratchpad-object cam-dbg-scratch) color quad) color-quad))
(set! (-> (scratchpad-object cam-dbg-scratch) plotvec 1 x) 20)
(set! (-> (scratchpad-object cam-dbg-scratch) plotvec 1 y) (+ (the int (* y-scale (- (fn x-min) y-min))) 20))
(let ((x-pixel 1))
(while (>= (the int (* x-scale x-range)) x-pixel)
(let ((previous-point-quad (-> (scratchpad-object cam-dbg-scratch) plotvec 1 quad)))
(set! (-> (scratchpad-object cam-dbg-scratch) plotvec 0 quad) previous-point-quad))
(set! (-> (scratchpad-object cam-dbg-scratch) plotvec 1 x) (+ x-pixel 20))
(set! (-> (scratchpad-object cam-dbg-scratch) plotvec 1 y)
(+ (the int (* y-scale (- (fn (+ x-min (* x-range (/ (the float x-pixel) (* x-scale x-range))))) y-min))) 20))
(camera-line2d (the-as vector4w (+ 48 (scratchpad-object int))) (the-as vector4w (+ 64 (scratchpad-object int))))
(+! x-pixel 1)))))
0
(none))
(defun camera-line-setup ((color vector4w))
"Select the color for subsequent camera-line-draw calls and initialize the
identity world-to-screen transform."
(let ((color-quad (-> color quad))) (set! (-> (scratchpad-object cam-dbg-scratch) color quad) color-quad))
(init-for-transform *identity-matrix*)
0
(none))
(defun camera-line-draw ((start vector) (end vector))
"Transform and draw one world-space line using the color selected by
camera-line-setup. Reject either endpoint whose transformed depth is past
the debug renderer's unsigned cutoff."
(set! (-> (the-as (pointer uint128) (+ 80 (scratchpad-object int)))) (-> start quad))
(set! (-> (the-as (pointer uint128) (+ 96 (scratchpad-object int)))) (-> end quad))
(set! (-> (scratchpad-object cam-dbg-scratch) linevec 0 w) (the-as int 1.0))
(set! (-> (scratchpad-object cam-dbg-scratch) linevec 1 w) (the-as int 1.0))
(transform-float-point (the-as vector (+ 80 (scratchpad-object int)))
(the-as vector4w (-> (scratchpad-object cam-dbg-scratch) linevec4w)))
(transform-float-point (the-as vector (+ 96 (scratchpad-object int))) (the-as vector4w (+ 16 (scratchpad-object int))))
(cond
((< (the-as uint #xe00000) (the-as uint (-> (scratchpad-object cam-dbg-scratch) linevec4w 0 z)))
(return (the-as symbol #f)))
((< (the-as uint #xe00000) (the-as uint (-> (scratchpad-object cam-dbg-scratch) linevec4w 1 z)))
(return (the-as symbol #f))))
(cam-line-dma)
(the-as symbol 0))
(defun camera-line ((start vector) (end vector) (color vector4w))
"Draw one world-space line in color."
(camera-line-setup color)
(camera-line-draw start end)
0
(none))
(defun camera-line-rel ((start vector) (offset vector) (color vector4w))
"Draw a line from start to start plus offset."
(vector+! (the-as vector (+ 112 (scratchpad-object int))) start offset)
(camera-line start (the-as vector (+ 112 (scratchpad-object int))) color)
(none))
(defun camera-line-rel-len ((start vector) (direction vector) (length float) (color vector4w))
"Normalize direction to length and draw that displacement from start."
(vector-normalize-copy! (the-as vector (+ 112 (scratchpad-object int))) direction length)
(vector+! (the-as vector (+ 112 (scratchpad-object int))) (the-as vector (+ 112 (scratchpad-object int))) start)
(camera-line start (the-as vector (+ 112 (scratchpad-object int))) color)
(none))
(defun camera-sphere ((center vector) (radius float) (color vector))
"Draw a sphere as a ten-by-ten latitude/longitude wireframe."
(camera-line-setup (the-as vector4w color))
(dotimes (latitude 10)
(let ((ring-radius (* radius (sin (* 3276.8 (the float latitude)))))
(next-ring-radius (* radius (sin (* 3276.8 (the float (+ latitude 1)))))))
(set! (-> (scratchpad-object cam-dbg-scratch) sphere-v-start y)
(+ (-> center y) (* (cos (* 3276.8 (the float latitude))) radius)))
(set! (-> (scratchpad-object cam-dbg-scratch) sphere-v-end y) (-> (scratchpad-object cam-dbg-scratch) sphere-v-start y))
(set! (-> (scratchpad-object cam-dbg-scratch) sphere-v-down y)
(+ (-> center y) (* (cos (* 3276.8 (the float (+ latitude 1)))) radius)))
(dotimes (longitude 10)
(set! (-> (scratchpad-object cam-dbg-scratch) sphere-v-start x)
(+ (-> center x) (* (cos (* 6553.6 (the float longitude))) ring-radius)))
(set! (-> (scratchpad-object cam-dbg-scratch) sphere-v-start z)
(+ (-> center z) (* (sin (* 6553.6 (the float longitude))) ring-radius)))
(set! (-> (scratchpad-object cam-dbg-scratch) sphere-v-end x)
(+ (-> center x) (* (cos (* 6553.6 (the float (+ longitude 1)))) ring-radius)))
(set! (-> (scratchpad-object cam-dbg-scratch) sphere-v-end z)
(+ (-> center z) (* (sin (* 6553.6 (the float (+ longitude 1)))) ring-radius)))
(set! (-> (scratchpad-object cam-dbg-scratch) sphere-v-down x)
(+ (-> center x) (* (cos (* 6553.6 (the float longitude))) next-ring-radius)))
(set! (-> (scratchpad-object cam-dbg-scratch) sphere-v-down z)
(+ (-> center z) (* (sin (* 6553.6 (the float longitude))) next-ring-radius)))
(camera-line-draw (the-as vector (+ 128 (scratchpad-object int))) (the-as vector (+ 144 (scratchpad-object int))))
(camera-line-draw (the-as vector (+ 128 (scratchpad-object int))) (the-as vector (+ 160 (scratchpad-object int)))))))
0
(none))
(defun camera-cross ((axis-a vector) (axis-b vector) (center vector) (color vector4w) (half-length meters))
"Draw three perpendicular diameter lines through center. The first axis is
axis-a; the other two are formed by successive crosses with axis-b and
axis-a. half-length is the distance from center to each endpoint."
(vector-normalize-copy! (the-as vector (+ 192 (scratchpad-object int))) axis-a half-length)
(vector+! (the-as vector (+ 208 (scratchpad-object int))) center (the-as vector (+ 192 (scratchpad-object int))))
(vector-! (the-as vector (+ 224 (scratchpad-object int))) center (the-as vector (+ 192 (scratchpad-object int))))
(camera-line (the-as vector (+ 208 (scratchpad-object int))) (the-as vector (+ 224 (scratchpad-object int))) color)
(vector-cross! (the-as vector (+ 192 (scratchpad-object int))) (the-as vector (+ 192 (scratchpad-object int))) axis-b)
(vector-normalize! (the-as vector (+ 192 (scratchpad-object int))) half-length)
(vector+! (the-as vector (+ 208 (scratchpad-object int))) center (the-as vector (+ 192 (scratchpad-object int))))
(vector-! (the-as vector (+ 224 (scratchpad-object int))) center (the-as vector (+ 192 (scratchpad-object int))))
(camera-line (the-as vector (+ 208 (scratchpad-object int))) (the-as vector (+ 224 (scratchpad-object int))) color)
(vector-cross! (the-as vector (+ 192 (scratchpad-object int))) (the-as vector (+ 192 (scratchpad-object int))) axis-a)
(vector-normalize! (the-as vector (+ 192 (scratchpad-object int))) half-length)
(vector+! (the-as vector (+ 208 (scratchpad-object int))) center (the-as vector (+ 192 (scratchpad-object int))))
(vector-! (the-as vector (+ 224 (scratchpad-object int))) center (the-as vector (+ 192 (scratchpad-object int))))
(the-as basic
(camera-line (the-as vector (+ 208 (scratchpad-object int))) (the-as vector (+ 224 (scratchpad-object int))) color)))
(defun camera-bounding-box-draw ((bounds bounding-box) (unused-options basic) (unused-color rgba))
"Draw the twelve edges of bounds in the original fixed gray. The two
trailing arguments are retained for compatibility but are not read."
(camera-line-setup (new 'static 'vector4w :x #x7f :y #x7f :z #x7f :w #x80))
(set! (-> (the-as (pointer uint128) (+ 240 (scratchpad-object int)))) (-> bounds min quad))
(set! (-> (scratchpad-object cam-dbg-scratch) bboxvec 0 x) (-> bounds max x))
(set! (-> (the-as (pointer uint128) (+ 256 (scratchpad-object int)))) (-> bounds min quad))
(set! (-> (scratchpad-object cam-dbg-scratch) bboxvec 1 y) (-> bounds max y))
(set! (-> (the-as (pointer uint128) (+ 272 (scratchpad-object int)))) (-> bounds min quad))
(set! (-> (scratchpad-object cam-dbg-scratch) bboxvec 2 z) (-> bounds max z))
(set! (-> (the-as (pointer uint128) (+ 288 (scratchpad-object int)))) (-> bounds max quad))
(set! (-> (scratchpad-object cam-dbg-scratch) bboxvec 3 x) (-> bounds min x))
(set! (-> (the-as (pointer uint128) (+ 304 (scratchpad-object int)))) (-> bounds max quad))
(set! (-> (scratchpad-object cam-dbg-scratch) bboxvec 4 y) (-> bounds min y))
(set! (-> (the-as (pointer uint128) (+ 320 (scratchpad-object int)))) (-> bounds max quad))
(set! (-> (scratchpad-object cam-dbg-scratch) bboxvec 5 z) (-> bounds min z))
(camera-line-draw (-> bounds min) (the-as vector (+ 240 (scratchpad-object int))))
(camera-line-draw (-> bounds min) (the-as vector (+ 256 (scratchpad-object int))))
(camera-line-draw (-> bounds min) (the-as vector (+ 272 (scratchpad-object int))))
(camera-line-draw (-> bounds max) (the-as vector (+ 288 (scratchpad-object int))))
(camera-line-draw (-> bounds max) (the-as vector (+ 304 (scratchpad-object int))))
(camera-line-draw (-> bounds max) (the-as vector (+ 320 (scratchpad-object int))))
(camera-line-draw (the-as vector (+ 240 (scratchpad-object int))) (the-as vector (+ 304 (scratchpad-object int))))
(camera-line-draw (the-as vector (+ 304 (scratchpad-object int))) (the-as vector (+ 272 (scratchpad-object int))))
(camera-line-draw (the-as vector (+ 272 (scratchpad-object int))) (the-as vector (+ 288 (scratchpad-object int))))
(camera-line-draw (the-as vector (+ 288 (scratchpad-object int))) (the-as vector (+ 256 (scratchpad-object int))))
(camera-line-draw (the-as vector (+ 256 (scratchpad-object int))) (the-as vector (+ 320 (scratchpad-object int))))
(camera-line-draw (the-as vector (+ 320 (scratchpad-object int))) (the-as vector (+ 240 (scratchpad-object int))))
0
(none))
(deftype cam-debug-tri (structure)
((vertex vector 3 :inline :offset-assert 0)
(intersect vector :inline :offset-assert 48)
(color vector4w :offset-assert 64))
:method-count-assert 9
:size-assert #x44
:flag-assert #x900000044)
(defmethod inspect ((obj cam-debug-tri))
(format #t "[~8x] ~A~%" obj 'cam-debug-tri)
(format #t "~Tvertex[3] @ #x~X~%" (-> obj vertex))
(format #t "~Tintersect: #<vector @ #x~X>~%" (-> obj intersect))
(format #t "~Tcolor: #<vector4w @ #x~X>~%" (-> obj color))
obj)
(define *cam-debug-los-tri-current* 0)
(define *cam-debug-los-tri* (the-as (inline-array cam-debug-tri) (malloc 'debug #x8fc0)))
(define *cam-debug-coll-tri-current* 0)
(define *cam-debug-coll-tri* (the-as (inline-array cam-debug-tri) (malloc 'debug #x8fc0)))
(defun cam-debug-reset-coll-tri ()
"Clear the per-frame camera collision and line-of-sight triangle lists."
(set! *cam-debug-los-tri-current* 0)
(set! *cam-debug-coll-tri-current* 0)
0
(none))
(defun cam-debug-add-los-tri ((triangles (inline-array collide-cache-tri)) (intersection vector) (color vector))
"Save the first collision-cache triangle, intersection, and color in the
line-of-sight debug list. The list holds at most 460 entries."
(cond
((>= *cam-debug-los-tri-current* 460))
(else
(let ((saved-triangle (-> *cam-debug-los-tri* *cam-debug-los-tri-current*)))
(set! (-> saved-triangle vertex 0 quad) (-> triangles 0 vertex 0 quad))
(set! (-> saved-triangle vertex 1 quad) (-> triangles 0 vertex 1 quad))
(set! (-> saved-triangle vertex 2 quad) (-> triangles 0 vertex 2 quad))
(set! (-> saved-triangle intersect quad) (-> intersection quad))
(set! (-> saved-triangle color) (the-as vector4w color)))
(set! *cam-debug-los-tri-current* (+ *cam-debug-los-tri-current* 1))
(if (= *cam-debug-los-tri-current* 460) (format 0 "ERROR <GMJ>: cam-debug-add-los-tri overflow~%"))))
0
(none))
(defun cam-debug-add-coll-tri ((triangle cam-debug-tri) (intersection vector) (color-data cam-debug-tri))
"Copy a camera debug triangle with a new intersection and color into the
collision debug list. The list holds at most 460 entries."
(cond
((>= *cam-debug-coll-tri-current* 460))
(else
(let ((saved-triangle (-> *cam-debug-coll-tri* *cam-debug-coll-tri-current*)))
(set! (-> saved-triangle vertex 0 quad) (-> triangle vertex 0 quad))
(set! (-> saved-triangle vertex 1 quad) (-> triangle vertex 1 quad))
(set! (-> saved-triangle vertex 2 quad) (-> triangle vertex 2 quad))
(set! (-> saved-triangle intersect quad) (-> intersection quad))
(set! (-> saved-triangle color) (the-as vector4w color-data)))
(set! *cam-debug-coll-tri-current* (+ *cam-debug-coll-tri-current* 1))
(if (>= *cam-debug-coll-tri-current* 460) (format 0 "ERROR <GMJ>: cam-debug-add-coll-tri overflow~%"))))
0
(none))
(defun cam-debug-draw-tris ()
"Draw the recorded camera line-of-sight and collision triangles selected by
the corresponding display flags, with a cross at each intersection."
(camera-line-setup (new 'stack 'vector4w))
(when *display-cam-los-marks*
(dotimes (i *cam-debug-los-tri-current*)
(let ((color-quad (-> *cam-debug-los-tri* i color quad)))
(set! (-> (scratchpad-object cam-dbg-scratch) color quad) color-quad))
(camera-line-draw (the-as vector (+ (the-as uint (-> *cam-debug-los-tri* 0)) (* 80 i)))
(the-as vector (+ (the-as uint (-> *cam-debug-los-tri* 0 vertex 1)) (* 80 i))))
(camera-line-draw (the-as vector (+ (the-as uint (-> *cam-debug-los-tri* 0 vertex 1)) (* 80 i)))
(the-as vector (+ (the-as uint (-> *cam-debug-los-tri* 0 vertex 2)) (* 80 i))))
(camera-line-draw (the-as vector (+ (the-as uint (-> *cam-debug-los-tri* 0 vertex 2)) (* 80 i)))
(the-as vector (+ (the-as uint (-> *cam-debug-los-tri* 0)) (* 80 i))))
(camera-cross (new 'static 'vector :y 1024.0)
(new 'static 'vector :z 1024.0)
(-> *cam-debug-los-tri* i intersect)
(-> *cam-debug-los-tri* i color)
(meters 0.25))))
(when *display-cam-coll-marks*
(dotimes (i *cam-debug-coll-tri-current*)
(let ((color-quad (-> *cam-debug-coll-tri* i color quad)))
(set! (-> (scratchpad-object cam-dbg-scratch) color quad) color-quad))
(camera-line-draw (the-as vector (+ (the-as uint (-> *cam-debug-coll-tri* 0)) (* 80 i)))
(the-as vector (+ (the-as uint (-> *cam-debug-coll-tri* 0 vertex 1)) (* 80 i))))
(camera-line-draw (the-as vector (+ (the-as uint (-> *cam-debug-coll-tri* 0 vertex 1)) (* 80 i)))
(the-as vector (+ (the-as uint (-> *cam-debug-coll-tri* 0 vertex 2)) (* 80 i))))
(camera-line-draw (the-as vector (+ (the-as uint (-> *cam-debug-coll-tri* 0 vertex 2)) (* 80 i)))
(the-as vector (+ (the-as uint (-> *cam-debug-coll-tri* 0)) (* 80 i))))
(camera-cross (new 'static 'vector :y 1024.0)
(new 'static 'vector :z 1024.0)
(-> *cam-debug-coll-tri* i intersect)
(-> *cam-debug-coll-tri* i color)
(meters 0.25)))
#f))
(defun camera-fov-draw ((direction-a-address int)
(direction-b-address int)
(origin vector)
(near-distance float)
(far-distance float)
(color vector4w))
"Draw one side of a camera frustum from two direction-vector addresses,
origin, near distance, far distance, and color."
(vector+float*! (the-as vector (+ 336 (scratchpad-object int)))
origin
(the-as vector direction-b-address)
near-distance)
(vector+float*! (the-as vector (+ 352 (scratchpad-object int)))
origin
(the-as vector direction-a-address)
near-distance)
(vector+float*! (the-as vector (+ 368 (scratchpad-object int))) origin (the-as vector direction-a-address) far-distance)
(vector+float*! (the-as vector (+ 384 (scratchpad-object int))) origin (the-as vector direction-b-address) far-distance)
(camera-line-setup color)
(camera-line-draw (the-as vector (+ 336 (scratchpad-object int))) (the-as vector (+ 352 (scratchpad-object int))))
(camera-line-draw (the-as vector (+ 352 (scratchpad-object int))) (the-as vector (+ 368 (scratchpad-object int))))
(camera-line-draw (the-as vector (+ 368 (scratchpad-object int))) (the-as vector (+ 384 (scratchpad-object int)))))
(defun camera-fov-frame ((inverse-rotation matrix)
(origin vector)
(half-fov float)
(vertical-scale float)
(horizontal-scale float)
(color vector4w))
"Draw a camera frustum from its inverse rotation, origin, half field of view,
vertical scale, horizontal scale, and color. The near and far outlines are
4096 and 20480 GOAL units from the origin."
(vector-float*! (the-as vector (+ 432 (scratchpad-object int)))
(-> inverse-rotation vector 1)
(* vertical-scale (tan half-fov)))
(vector-float*! (the-as vector (+ 448 (scratchpad-object int)))
(the-as vector (-> inverse-rotation vector))
(* horizontal-scale (tan half-fov)))
(vector+! (the-as vector (+ 400 (scratchpad-object int)))
(-> inverse-rotation vector 2)
(vector+! (the-as vector (+ 400 (scratchpad-object int)))
(the-as vector (+ 432 (scratchpad-object int)))
(the-as vector (+ 448 (scratchpad-object int)))))
(vector-normalize! (the-as vector (+ 400 (scratchpad-object int))) 1.0)
(vector+! (the-as vector (+ 416 (scratchpad-object int)))
(-> inverse-rotation vector 2)
(vector-! (the-as vector (+ 416 (scratchpad-object int)))
(the-as vector (+ 432 (scratchpad-object int)))
(the-as vector (+ 448 (scratchpad-object int)))))
(vector-normalize! (the-as vector (+ 416 (scratchpad-object int))) 1.0)
(camera-fov-draw (+ 400 (scratchpad-object int)) (+ 416 (scratchpad-object int)) origin 4096.0 20480.0 color)
(set! (-> (the-as (pointer uint128) (+ 400 (scratchpad-object int))))
(-> (the-as vector (+ 416 (scratchpad-object int))) quad))
(vector-! (the-as vector (+ 416 (scratchpad-object int)))
(-> inverse-rotation vector 2)
(vector+! (the-as vector (+ 416 (scratchpad-object int)))
(the-as vector (+ 432 (scratchpad-object int)))
(the-as vector (+ 448 (scratchpad-object int)))))
(vector-normalize! (the-as vector (+ 416 (scratchpad-object int))) 1.0)
(camera-fov-draw (+ 400 (scratchpad-object int)) (+ 416 (scratchpad-object int)) origin 4096.0 20480.0 color)
(set! (-> (the-as (pointer uint128) (+ 400 (scratchpad-object int))))
(-> (the-as vector (+ 416 (scratchpad-object int))) quad))
(vector-! (the-as vector (+ 416 (scratchpad-object int)))
(-> inverse-rotation vector 2)
(vector-! (the-as vector (+ 416 (scratchpad-object int)))
(the-as vector (+ 432 (scratchpad-object int)))
(the-as vector (+ 448 (scratchpad-object int)))))
(vector-normalize! (the-as vector (+ 416 (scratchpad-object int))) 1.0)
(camera-fov-draw (+ 400 (scratchpad-object int)) (+ 416 (scratchpad-object int)) origin 4096.0 20480.0 color)
(set! (-> (the-as (pointer uint128) (+ 400 (scratchpad-object int))))
(-> (the-as vector (+ 416 (scratchpad-object int))) quad))
(vector+! (the-as vector (+ 416 (scratchpad-object int)))
(-> inverse-rotation vector 2)
(vector+! (the-as vector (+ 416 (scratchpad-object int)))
(the-as vector (+ 432 (scratchpad-object int)))
(the-as vector (+ 448 (scratchpad-object int)))))
(vector-normalize! (the-as vector (+ 416 (scratchpad-object int))) 1.0)
(camera-fov-draw (+ 400 (scratchpad-object int)) (+ 416 (scratchpad-object int)) origin 4096.0 20480.0 color)
(none))
(defmethod print-nth-point ((this tracking-spline) (point-index int))
"Print one breadcrumb with markers for the used head, next-to-last point,
and end point."
(if (= point-index (-> this used-point)) (format 0 "u") (format 0 " "))
(if (= point-index (-> this next-to-last-point)) (format 0 "n") (format 0 " "))
(if (= point-index (-> this end-point)) (format 0 "e") (format 0 " "))
(if (= point-index -134250495)
(format 0 " ~D~%" point-index)
(format 0
" ~D ~M ~M ~M~%"
point-index
(-> this point point-index position x)
(-> this point point-index position y)
(-> this point point-index position z)))
0
(none))
(defmethod print-all-points ((this tracking-spline))
"Print every breadcrumb in the used chain, followed by the chain terminator."
(let ((point-index (-> this used-point)))
(while (!= point-index -134250495)
(print-nth-point this point-index)
(set! point-index (-> this point point-index next)))
(print-nth-point this point-index))
0
(none))
(defmethod debug-draw ((this tracking-spline))
"Draw the used breadcrumb chain, the endpoints of the current
sampling window, and the trail correction applied to the last output."
(let ((point-index (-> this used-point))
(next-point-index (-> this point (-> this used-point) next)))
(let ((sample-position (new 'stack-no-clear 'vector)))
(when (!= next-point-index -134250495)
(sample-point! this 0.0 sample-position (the-as tracking-spline-sampler #f))
(camera-cross (new 'static 'vector :y 1024.0)
(new 'static 'vector :z 1024.0)
sample-position
(new 'static 'vector4w :x #xff :w #x80)
(meters 0.25))
(sample-point! this (-> this sample-len) sample-position (the-as tracking-spline-sampler #f))
(camera-cross (new 'static 'vector :y 1024.0)
(new 'static 'vector :z 1024.0)
sample-position
(new 'static 'vector4w :x #xff :w #x80)
(meters 0.25))))
(while (!= next-point-index -134250495)
(camera-line (-> this point point-index position)
(-> this point next-point-index position)
(new 'static 'vector4w :x #x80 :y #x80 :z #x80 :w #x80))
(set! point-index next-point-index)
(set! next-point-index (-> this point next-point-index next))))
(let ((corrected-move (new 'stack-no-clear 'vector)))
(camera-line (-> this debug-out-position) (-> this debug-old-position) (new 'static 'vector4w :x #xff :y #xff :w #x80))
(vector-! corrected-move (-> this debug-out-position) (-> this debug-old-position))
(apply-trail-correction! this corrected-move (-> this debug-last-point))
(camera-line-rel (-> this debug-old-position) corrected-move (new 'static 'vector4w :x #xff :z #xff :w #x80)))
0
(none))
(defun debug-euler ((scratch cam-dbg-scratch))
"Interpret the matrix packed from scratch.sphere-vec.w onward, print its Euler
conversion and reconstruction, and report whether any component differs by
more than 0.001."
(let ((angles (new 'stack-no-clear 'euler-angles))
(reconstructed (new 'stack-no-clear 'matrix)))
(matrix->eul angles (the-as matrix (&-> scratch sphere-vec w)) 21)
(format *stdcon* "euler angles x ~R y ~R z ~R~%" (-> angles x) (-> angles y) (-> angles z))
(format *stdcon*
"~f ~f ~f ~f~%"
(-> scratch sphere-vec w)
(-> scratch crossvec 0 x)
(-> scratch crossvec 0 y)
(-> scratch crossvec 0 z))
(format *stdcon*
"~f ~f ~f ~f~%"
(-> scratch crossvec 0 w)
(-> scratch crossvec 1 x)
(-> scratch crossvec 1 y)
(-> scratch crossvec 1 z))
(format *stdcon*
"~f ~f ~f ~f~%"
(-> scratch crossvec 1 w)
(-> scratch crossvec 2 x)
(-> scratch crossvec 2 y)
(-> scratch crossvec 2 z))
(format *stdcon*
"~f ~f ~f ~f~%"
(-> scratch crossvec 2 w)
(-> scratch bboxvec 0 x)
(-> scratch bboxvec 0 y)
(-> scratch bboxvec 0 z))
(eul->matrix reconstructed angles)
(format *stdcon*
"~f ~f ~f ~f~%"
(-> reconstructed vector 0 x)
(-> reconstructed vector 0 y)
(-> reconstructed vector 0 z)
(-> reconstructed vector 0 w))
(format *stdcon*
"~f ~f ~f ~f~%"
(-> reconstructed vector 1 x)
(-> reconstructed vector 1 y)
(-> reconstructed vector 1 z)
(-> reconstructed vector 1 w))
(format *stdcon*
"~f ~f ~f ~f~%"
(-> reconstructed vector 2 x)
(-> reconstructed vector 2 y)
(-> reconstructed vector 2 z)
(-> reconstructed vector 2 w))
(format *stdcon*
"~f ~f ~f ~f~%"
(-> reconstructed vector 3 x)
(-> reconstructed vector 3 y)
(-> reconstructed vector 3 z)
(-> reconstructed vector 3 w))
(if (or (< 0.001 (fabs (- (-> scratch sphere-vec w) (-> reconstructed vector 0 x))))
(< 0.001 (fabs (- (-> scratch crossvec 0 x) (-> reconstructed vector 0 y))))
(< 0.001 (fabs (- (-> scratch crossvec 0 y) (-> reconstructed vector 0 z))))
(< 0.001 (fabs (- (-> scratch crossvec 0 z) (-> reconstructed vector 0 w))))
(< 0.001 (fabs (- (-> scratch crossvec 0 w) (-> reconstructed vector 1 x))))
(< 0.001 (fabs (- (-> scratch crossvec 1 x) (-> reconstructed vector 1 y))))
(< 0.001 (fabs (- (-> scratch crossvec 1 y) (-> reconstructed vector 1 z))))
(< 0.001 (fabs (- (-> scratch crossvec 1 z) (-> reconstructed vector 1 w))))
(< 0.001 (fabs (- (-> scratch crossvec 1 w) (-> reconstructed vector 2 x))))
(< 0.001 (fabs (- (-> scratch crossvec 2 x) (-> reconstructed vector 2 y))))
(< 0.001 (fabs (- (-> scratch crossvec 2 y) (-> reconstructed vector 2 z))))
(< 0.001 (fabs (- (-> scratch crossvec 2 z) (-> reconstructed vector 2 w))))
(< 0.001 (fabs (- (-> scratch crossvec 2 w) (-> reconstructed vector 3 x))))
(< 0.001 (fabs (- (-> scratch bboxvec 0 x) (-> reconstructed vector 3 y))))
(< 0.001 (fabs (- (-> scratch bboxvec 0 y) (-> reconstructed vector 3 z))))
(< 0.001 (fabs (- (-> scratch bboxvec 0 z) (-> reconstructed vector 3 w)))))
(format *stdcon* "different~%")
(format *stdcon* "same~%"))))
(defun bike-cam-limit ((input float))
"Return a cosine camera limit that rises from zero to one as the nonnegative
scaled input approaches 8192, and remains one beyond that range."
(let* ((scaled-input (* 10012.444 input))
(clamped-input (fmax 0.0 scaled-input)))
(if (< clamped-input 8192.0)
(* (/ 1.0 (- 1.0 (cos 21845.334))) (+ (- (cos 21845.334)) (cos (* 2.6666667 (- 8192.0 clamped-input)))))
1.0)))
(defun camera-slave-debug ((slave camera-slave))
"Draw the active camera-slave frustum, tracking basis and follow point,
target body spheres, spline trail, and state-specific string, circular, or
authored-spline geometry when camera marks are enabled."
(when *display-camera-marks*
(let ((half-fov (* 0.5 (-> *camera-combiner* fov))))
(camera-fov-frame (-> *camera-combiner* inv-camera-rot)
(camera-pos)
half-fov
0.75
1.0
(new 'static 'vector4w :z #xff :w #x80)))
(cond
((= (-> slave blend-to-type) 2)
(let ((half-fov (* 0.5 (-> slave fov))))
(camera-fov-frame (the-as matrix (-> *camera-combiner* tracking))
(-> slave trans)
half-fov
0.75
1.0
(new 'static 'vector4w :y #xff :w #x80))))
(else
(let ((half-fov (* 0.5 (-> slave fov))))
(camera-fov-frame (the-as matrix (-> slave tracking))
(-> slave trans)
half-fov
0.75
1.0
(new 'static 'vector4w :y #xff :w #x80)))))
(debug-draw (-> slave position-spline))
(let ((line-end (new-stack-vector0)))
(let ((line-start (new-stack-vector0)))
(new-stack-matrix0)
(cond
((or (= (-> slave next-state name) 'cam-fixed)
(or (= (-> slave next-state name) 'cam-eye)
(= (-> slave next-state name) 'cam-point-watch)
(= (-> slave next-state name) 'cam-free-floating)
(= (-> slave next-state name) 'cam-orbit)))
(vector+float*! line-end (-> slave trans) (-> *camera* local-down) 4096.0)
(camera-line (-> slave trans) line-end (new 'static 'vector4w :x #xff :y #xff :z #xff :w #x80)))
((= (-> slave blend-to-type) 2)
(camera-line (-> *camera-combiner* tracking follow-pt)
(-> slave trans)
(new 'static 'vector4w :x #xff :y #xff :z #xff :w #x80))
(vector+float*! line-end (-> *camera-combiner* tracking follow-pt) (-> *camera* local-down) 4096.0)
(camera-line (-> *camera-combiner* tracking follow-pt) line-end (new 'static 'vector4w :x #xff :y #xff :z #xff :w #x80)))
(else
(camera-line (-> slave tracking follow-pt) (-> slave trans) (new 'static 'vector4w :x #xff :y #xff :z #xff :w #x80))
(vector+float*! line-end (-> slave tracking follow-pt) (-> *camera* local-down) 4096.0)
(camera-line (-> slave tracking follow-pt) line-end (new 'static 'vector4w :x #xff :y #xff :z #xff :w #x80))))
(set! (-> line-start quad) (-> slave trans quad))
(cond
((= (-> slave blend-to-type) 2)
(vector+float*! line-end line-start (the-as vector (-> *camera-combiner* tracking)) 2048.0)
(camera-line line-start line-end (new 'static 'vector4w :x #xff :w #x80))
(vector+float*! line-end line-start (-> *camera-combiner* tracking inv-mat vector 1) 2048.0)
(camera-line line-start line-end (new 'static 'vector4w :y #xff :w #x80))
(vector+float*! line-end line-start (-> *camera-combiner* tracking inv-mat vector 2) 2048.0)
(camera-line line-start line-end (new 'static 'vector4w :z #xff :w #x80)))
(else
(vector+float*! line-end line-start (the-as vector (-> slave tracking)) 2048.0)
(camera-line line-start line-end (new 'static 'vector4w :x #xff :w #x80))
(vector+float*! line-end line-start (-> slave tracking inv-mat vector 1) 2048.0)
(camera-line line-start line-end (new 'static 'vector4w :y #xff :w #x80))
(vector+float*! line-end line-start (-> slave tracking inv-mat vector 2) 2048.0)
(camera-line line-start line-end (new 'static 'vector4w :z #xff :w #x80)))))
(vector--float*! line-end (-> *camera* tpos-curr) (-> *camera* local-down) (-> *camera* foot-offset))
(camera-sphere line-end 512.0 (the-as vector (new 'static 'vector4w :y #xff :w #x80)))
(vector--float*! line-end (-> *camera* tpos-curr) (-> *camera* local-down) (-> *camera* head-offset))
(camera-sphere line-end 512.0 (the-as vector (new 'static 'vector4w :y #xff :w #x80))))
(cond
((= (-> slave next-state name) 'cam-string)
(camera-sphere (-> slave desired-pos) 512.0 (the-as vector (new 'static 'vector4w :z #xff :w #x80)))
(camera-line-rel (-> *camera* tpos-curr-adj) (-> slave view-flat) (new 'static 'vector4w :z #xff :w #x80))
(camera-line (-> slave string-trans)
(the-as vector (+ (the-as uint (-> *camera* target-spline)) (* 48 (-> slave los-tgt-spline-pt))))
(new 'static 'vector4w :y #xff :w #x80))
(camera-line (-> slave los-last-pos)
(the-as vector (+ (the-as uint (-> *camera* target-spline)) (* 48 (-> slave los-tgt-spline-pt))))
(new 'static 'vector4w :x #xff :w #x80)))
((= (-> slave next-state name) 'cam-circular)
(let ((pivot-axis-end (new-stack-vector0)))
(vector+float*! pivot-axis-end (-> slave pivot-pt) (-> *camera* local-down) 4096.0)
(camera-line (-> slave pivot-pt) pivot-axis-end (new 'static 'vector4w :x #xff :y #xff :z #xff :w #x80)))
(camera-line (-> slave pivot-pt) (-> slave trans) (new 'static 'vector4w :x #xff :y #xff :z #xff :w #x80)))
((= (-> slave next-state name) 'cam-spline)
(let ((path-data (new 'stack 'curve))
(path-offset (res-lump-struct (-> slave cam-entity) 'spline-offset structure)))
(if (not path-offset) (set! path-offset (new-stack-vector0)))
(when (get-curve-data! (-> slave cam-entity) path-data 'campath 'campath-k -1000000000.0)
(let ((previous-point (new-stack-vector0))
(current-point (new-stack-vector0))
(authored-line (res-lump-data (-> slave cam-entity) 'campoints pointer :time 1.0)))
(curve-get-pos! current-point 0.0 path-data)
(vector+! current-point current-point (the-as vector path-offset))
(dotimes (i 8)
(set! (-> previous-point quad) (-> current-point quad))
(curve-get-pos! current-point (* 0.125 (the float (+ i 1))) path-data)
(vector+! current-point current-point (the-as vector path-offset))
(camera-line previous-point current-point (new 'static 'vector4w :x #xff :y #xff :w #x80)))
(dotimes (i (-> path-data num-cverts))
(vector+! previous-point (-> path-data cverts i) (the-as vector path-offset))
(vector+! current-point (-> path-data cverts (mod (+ i 1) (-> path-data num-cverts))) (the-as vector path-offset))
(camera-line previous-point current-point (new 'static 'vector4w :y #xff :z #xff :w #x80)))
(if authored-line
(camera-line (the-as vector (&+ authored-line 0))
(the-as vector (&+ authored-line 16))
(new 'static 'vector4w :x #xff :y #xff :z #xff :w #x80))
(camera-line (-> path-data cverts 0)
(-> path-data cverts (+ (-> path-data num-cverts) -1))
(new 'static 'vector4w :x #xff :y #xff :z #xff :w #x80)))))))))
0
(none))
(defun master-draw-coordinates ((direction vector))
"Draw RGB world axes in front of the camera combiner. If direction is
non-null, also draw its normalized direction in yellow."
(let ((axis-end (new-stack-vector0))
(axis-origin (new-stack-vector0)))
(let ((rotation (new-stack-matrix0))) (set-vector! axis-end 0.0 8192.0 0.0 1.0) (matrix-rotate-yxz! rotation axis-end))
(vector+! axis-origin
(-> *camera-combiner* trans)
(vector-normalize-copy! axis-origin (-> *camera-combiner* inv-camera-rot vector 2) 24576.0))
(let ((axis-destination axis-end)
(origin-copy axis-origin)
(axis-offset axis-end))
(set! (-> axis-offset x) 4096.0)
(set! (-> axis-offset y) 0.0)
(set! (-> axis-offset z) 0.0)
(set! (-> axis-offset w) 1.0)
(vector+! axis-destination origin-copy axis-offset))
(add-debug-line #t (bucket-id debug-no-zbuf) axis-origin axis-end (new 'static 'rgba :r #xff :a #x80) #f (the-as rgba -1))
(let ((axis-destination axis-end)
(origin-copy axis-origin)
(axis-offset axis-end))
(set! (-> axis-offset x) 0.0)
(set! (-> axis-offset y) 4096.0)
(set! (-> axis-offset z) 0.0)
(set! (-> axis-offset w) 1.0)
(vector+! axis-destination origin-copy axis-offset))
(add-debug-line #t (bucket-id debug-no-zbuf) axis-origin axis-end (new 'static 'rgba :g #xff :a #x80) #f (the-as rgba -1))
(let ((axis-destination axis-end)
(origin-copy axis-origin)
(axis-offset axis-end))
(set! (-> axis-offset x) 0.0)
(set! (-> axis-offset y) 0.0)
(set! (-> axis-offset z) 4096.0)
(set! (-> axis-offset w) 1.0)
(vector+! axis-destination origin-copy axis-offset))
(add-debug-line #t (bucket-id debug-no-zbuf) axis-origin axis-end (new 'static 'rgba :b #xff :a #x80) #f (the-as rgba -1))
(when direction
(set! (-> axis-end quad) (-> direction quad))
(vector-normalize! axis-end 4096.0)
(vector+! axis-end axis-origin axis-end)
(add-debug-line #t
(bucket-id debug-no-zbuf)
axis-origin
axis-end
(new 'static 'rgba :r #x7f :g #x7f :a #x80)
#f
(the-as rgba -1))))
0
(none))
(deftype cam-collision-record (structure)
((pos vector :inline :offset-assert 0)
(vel vector :inline :offset-assert 16)
(desired-pos vector :inline :offset-assert 32)
(cam-tpos-cur vector :inline :offset-assert 48)
(cam-tpos-old vector :inline :offset-assert 64)
(view-flat vector :inline :offset-assert 80)
(string-min-val vector :inline :offset-assert 96)
(string-max-val vector :inline :offset-assert 112)
(view-off vector :inline :offset-assert 128)
(min-z-override float :offset-assert 144)
(string-push-z float :offset-assert 148)
(view-off-param float :offset-assert 152)
(frame int32 :offset-assert 156)
(iteration int32 :offset-assert 160)
(move-type symbol :offset-assert 164))
:method-count-assert 9
:size-assert #xa8
:flag-assert #x9000000a8)
(deftype cam-collision-record-array (inline-array-class)
((data cam-collision-record :dynamic :offset-assert 16))
:method-count-assert 9
:size-assert #x10
:flag-assert #x900000010)
(set! (-> cam-collision-record-array heap-base) (the-as uint 176))
(define *cam-collision-record-first* 0)
(define *cam-collision-record-last* 0)
(define *cam-collision-record-show* 0)
(define *cam-collision-record* (new 'debug 'cam-collision-record-array 600))
(defun cam-collision-record-save ((position vector) (velocity vector) (iteration int) (move-kind symbol) (slave camera-slave))
"When collision history recording is enabled, append one camera movement
attempt to the 600-entry ring, including collision parameters and the
camera-slave state needed to reproduce and inspect the probe."
(when *record-cam-collide-history*
(let ((record (the-as cam-collision-record (+ (+ (* 176 *cam-collision-record-last*) 12) (the-as int *cam-collision-record*)))))
(vector-copy! (-> record pos) position)
(vector-copy! (-> record vel) velocity)
(vector-copy! (-> record view-flat) (-> slave view-flat))
(vector-copy! (-> record desired-pos) (-> slave desired-pos))
(vector-copy! (-> record cam-tpos-cur) (-> *camera* tpos-curr-adj))
(vector-copy! (-> record cam-tpos-old) (-> *camera* tpos-old-adj))
(vector-copy! (-> record string-min-val) (-> slave string-min-val))
(vector-copy! (-> record string-max-val) (-> slave string-max-val))
(vector-copy! (-> record view-off) (-> slave view-off))
(set! (-> record frame) (the-as int (-> *display* base-frame-counter)))
(set! (-> record iteration) iteration)
(set! (-> record move-type) move-kind)
(set! (-> record min-z-override) (-> slave min-z-override))
(set! (-> record string-push-z) (-> *camera* string-push-z))
(set! (-> record view-off-param) (-> slave view-off-param)))
(set! *cam-collision-record-show* *cam-collision-record-last*)
(set! *cam-collision-record-last* (+ *cam-collision-record-last* 1))
(set! *cam-collision-record-last* (mod *cam-collision-record-last* 600))
(when (= *cam-collision-record-last* *cam-collision-record-first*)
(set! *cam-collision-record-first* (+ *cam-collision-record-first* 1))
(set! *cam-collision-record-first* (mod *cam-collision-record-first* 600))))
0
(none))
(defun cam-collision-record-step ((delta int))
"Move the selected collision-history index by delta, wrapping within all 600
storage slots."
(set! *cam-collision-record-show* (+ *cam-collision-record-show* delta))
(while (>= *cam-collision-record-show* 600)
(set! *cam-collision-record-show* (+ *cam-collision-record-show* -600)))
(while (< *cam-collision-record-show* 0)
(set! *cam-collision-record-show* (+ *cam-collision-record-show* 600)))
0
(none))
(defun cam-collision-record-draw ()
"Select a collision-history entry with the d-pad, print its saved camera
state, repeat its line-sphere probe, and draw the movement, hit triangle,
intersection direction, and normal."
(cond
((cpad-pressed? 0 down) (cam-collision-record-step 1))
((cpad-hold? 0 right) (cam-collision-record-step 1))
((cpad-pressed? 0 up) (cam-collision-record-step -1))
((cpad-hold? 0 left) (cam-collision-record-step -1)))
(let ((record (the-as cam-collision-record (+ (+ (* 176 *cam-collision-record-show*) 12) (the-as int *cam-collision-record*))))
(movement-color (new 'stack 'vector4w))
(collision-color (new 'stack 'vector4w)))
(format *stdcon* "move-type ~A~%" (-> record move-type))
(cond
((= (-> record move-type) 'normal) (set! (-> movement-color x) 255) (set! (-> movement-color y) 255))
((= (-> record move-type) 'jump) (set! (-> movement-color x) 255))
((= (-> record move-type) 'no-hit) (set! (-> movement-color y) 255))
(else (set! (-> movement-color z) 255)))
(set! (-> movement-color w) 128)
(set! (-> collision-color x) 127)
(set! (-> collision-color y) 127)
(set! (-> collision-color z) 127)
(set! (-> collision-color w) 128)
(camera-line-rel-len (-> record pos) (-> record vel) (fmax 81.92 (vector-length (-> record vel))) movement-color)
(let* ((hit (new 'stack-no-clear 'collide-tri-result))
(travel (fill-and-probe-using-line-sphere *collide-cache*
(-> record pos)
(-> record vel)
(-> *CAMERA-bank* collide-move-rad)
(collide-kind background)
(the-as process #f)
hit
(new 'static 'pat-surface :nocamera #x1)))
(toward-start (new 'stack-no-clear 'vector)))
(format *stdcon* "frame ~D iteration ~D travel ~f~%" (-> record frame) (-> record iteration) travel)
(format *stdcon*
"mzo ~M psz ~M vop ~f~%"
(-> record min-z-override)
(-> record string-push-z)
(-> record view-off-param))
(format *stdcon* "pos ~M ~M ~M~%" (-> record pos x) (-> record pos y) (-> record pos z))
(format *stdcon* "vel ~M ~M ~M~%" (-> record vel x) (-> record vel y) (-> record vel z))
(format *stdcon* "des ~M ~M ~M~%" (-> record desired-pos x) (-> record desired-pos y) (-> record desired-pos z))
(format *stdcon* "flt ~M ~M ~M~%" (-> record view-flat x) (-> record view-flat y) (-> record view-flat z))
(format *stdcon* "cur ~M ~M ~M~%" (-> record cam-tpos-cur x) (-> record cam-tpos-cur y) (-> record cam-tpos-cur z))
(format *stdcon* "old ~M ~M ~M~%" (-> record cam-tpos-old x) (-> record cam-tpos-old y) (-> record cam-tpos-old z))
(format *stdcon*
"smn ~M ~M ~M~%"
(-> record string-min-val x)
(-> record string-min-val y)
(-> record string-min-val z))
(format *stdcon*
"smx ~M ~M ~M~%"
(-> record string-max-val x)
(-> record string-max-val y)
(-> record string-max-val z))
(format *stdcon* "vof ~M ~M ~M~%" (-> record view-off x) (-> record view-off y) (-> record view-off z))
(when (>= travel 0.0)
(camera-line (the-as vector (-> hit vertex)) (-> hit vertex 1) movement-color)
(camera-line (-> hit vertex 1) (-> hit vertex 2) movement-color)
(camera-line (-> hit vertex 2) (the-as vector (-> hit vertex)) movement-color)
(vector-! toward-start (-> record pos) (-> hit intersect))
(vector-normalize! toward-start 1.0)
(camera-line-rel-len (-> hit intersect) toward-start (-> *CAMERA-bank* collide-move-rad) collision-color)
(camera-line-rel-len (-> hit intersect) (-> hit normal) (-> *CAMERA-bank* collide-move-rad) collision-color))))
0
(none))
(defun camera-master-debug ((cam-master camera-master))
"Draw the camera-master diagnostics selected by the global display flags:
alternate-camera geometry, last attacker, saved performance statistics,
collision history, target spline, coordinate axes, and collision triangles."
(when *display-cam-other*
(let ((half-fov (* 0.5 (-> *camera-other-fov* data))))
(camera-fov-frame *camera-other-matrix* *camera-other-trans* half-fov 0.75 1.0 (new 'static 'vector4w :x #xff :w #x80)))
(camera-line *camera-other-trans* *camera-other-root* (new 'static 'vector4w :x #xff :y #xff :z #xff :w #x80))
(let ((axis-end (new 'stack-no-clear 'vector))
(axis-origin *camera-other-trans*))
(vector+float*! axis-end axis-origin (the-as vector (-> *camera-other-matrix* vector)) 2048.0)
(camera-line axis-origin axis-end (new 'static 'vector4w :x #xff :w #x80))
(vector+float*! axis-end axis-origin (-> *camera-other-matrix* vector 1) 2048.0)
(camera-line axis-origin axis-end (new 'static 'vector4w :y #xff :w #x80))
(vector+float*! axis-end axis-origin (-> *camera-other-matrix* vector 2) 2048.0)
(camera-line axis-origin axis-end (new 'static 'vector4w :z #xff :w #x80))))
(when *display-camera-last-attacker*
(format *stdcon* "last attacker '")
(let ((last-attacker (handle->process (-> last-try-to-look-at-data who))))
(if last-attacker (format *stdcon* "~S" (-> last-attacker name))))
(format *stdcon* "'~%"))
(when *display-camera-old-stats*
(format *stdcon*
"old ~S cpu ~D old vu ~D (go to menu before comparing)~%"
*camera-old-level*
*camera-old-cpu*
*camera-old-vu*)
(format *stdcon* "old tfrag-mem ~D~%" (sar *camera-old-tfrag-bytes* 10))
(format *stdcon* "~S~%" *camera-old-stat-string-tfrag-near*)
(format *stdcon* "~S~%" *camera-old-stat-string-tfrag*)
(format *stdcon* "~S~%" *camera-old-stat-string-total*))
(if *display-cam-collide-history* (cam-collision-record-draw))
(if *display-cam-master-marks* (debug-draw (-> cam-master target-spline)))
(if *display-xyz-axes* (master-draw-coordinates (the-as vector #f)))
(cam-debug-draw-tris)
0
(none))
(defun debug-set-camera-pos-rot! ((position vector) (inverse-rotation matrix))
"Move the live camera combiner to position and inverse-rotation. Temporarily
enter the free-floating state so the transform can be replaced, then return
to the fixed state. Return position."
(when (and *camera* *camera-combiner*)
(send-event *camera* 'change-state cam-free-floating 0)
(vector-copy! (-> *camera-combiner* trans) position)
(matrix-copy! (-> *camera-combiner* inv-camera-rot) inverse-rotation)
(send-event *camera* 'change-state cam-fixed 0))
position)
(defun external-cam-reset! ()
"Reset the external math camera to the current combiner transform,
or to the identity at the origin when the combiner is unavailable."
(vector-reset! (-> *math-camera* trans))
(matrix-identity! (-> *math-camera* inv-camera-rot))
(when *camera-combiner*
(matrix-copy! (-> *math-camera* inv-camera-rot) (-> *camera-combiner* inv-camera-rot))
(vector-copy! (-> *math-camera* trans) (-> *camera-combiner* trans)))
0
(none))