jak-project/goal_src/jak2/engine/gfx/math-camera.gc

719 lines
25 KiB
Common Lisp

;;-*-Lisp-*-
(in-package goal)
;; name: math-camera.gc
;; name in dgo: math-camera
;; dgos: ENGINE, GAME
#|@file
;;;;;;;;;;;;;;;;;;;;
math camera basics
;;;;;;;;;;;;;;;;;;;;
the math camera computes the perspective matrix, hvdf offset, and hmge scale.
multiplying a point by the perspective matrix, doing the persepctive divide, then adding hvdf offset gives you:
H : horizontal position (in GS coordinates)
V : vertical position (in GS coordinates)
D : depth (as a 24-bit integer for the z buffer)
F : fog
Multiplying by hmge then checking the clipping flags can be used to see if a point is outside the view frustum.
The "camera-temp" matrix is the perspective matrix multplied by the camera tranformation and is used
renderers that want a single matrix.
|#
(define-extern sprite-distorter-generate-tables (function none))
;; DECOMP BEGINS
;;;;;;;;;;;;;;;;;;;
;; fog correction
;;;;;;;;;;;;;;;;;;;
;; The math-camera matrices are used to compute fogging values, which are a per-vertex uint8 that
;; tells the GS how "foggy" the color should be. This should be proportional to how far away the vertex
;; is. There is a scaling factor applied so the fog intensity isn't affected by the field of view angle.
;; The fog-corrector stores a fog-end fog-start value that is corrected for the field of view.
;; the actual correction factor is computed in cam-update.gc
;; Without this corrector, the fogginess of the world would change as the fov changes
;; (for example, when jak gets on the zoomer, the fov changes slightly)
(deftype fog-corrector (structure)
((fog-end float :offset-assert 0)
(fog-start float :offset-assert 4)
)
:method-count-assert 9
:size-assert #x8
:flag-assert #x900000008
)
(defun fog-corrector-setup ((arg0 fog-corrector) (arg1 math-camera))
"Set the fog corrector based on the supplied math-camera"
(set! (-> arg0 fog-end) (* (-> arg1 fog-end) (-> arg1 fov-correction-factor)))
(set! (-> arg0 fog-start) (* (-> arg1 fog-start) (-> arg1 fov-correction-factor)))
(none)
)
(define *math-camera-fog-correction* (new 'global 'fog-corrector))
(defun update-math-camera ((arg0 math-camera) (arg1 symbol) (arg2 symbol) (arg3 float))
"Compute some one-time camera constants. These should only change when changing aspect ratio."
(local-vars (sv-16 float))
;; compute frustum slopes.
(set! (-> arg0 x-ratio) (tan (* 0.5 arg3)))
(if (= arg2 'aspect4x3)
(set! (-> arg0 y-ratio) (* 0.75 (-> arg0 x-ratio)))
(set! (-> arg0 y-ratio) (* 0.5625 (-> arg0 x-ratio)))
)
(with-pc
(cond
((-> *pc-settings* use-vis?)
;; using game vis, cannot allow seeing more of the view
;; crops excess aspect ratio at the top and bottom
;(set! (-> arg0 y-ratio) (* (1/ (-> *pc-settings* aspect-ratio)) (-> arg0 x-ratio)))
)
((-> *pc-settings* movie?)
;; this mess is just so that we can force the original 16x9 cropping during cutscenes.
(if (<= (-> *pc-settings* aspect-ratio) ASPECT_16X9)
(set! (-> arg0 y-ratio) (* (1/ (-> *pc-settings* aspect-ratio)) (-> arg0 x-ratio)))
(begin
(set! (-> arg0 y-ratio) (* (1/ ASPECT_16X9) (-> arg0 x-ratio)))
(*! (-> arg0 x-ratio) (/ (-> *pc-settings* aspect-ratio) ASPECT_16X9))
)
)
)
(else
;; not using game vis, allow *extended* aspect ratios
;; there is no vertical cropping, and you can see more of the sides
(set! (-> arg0 y-ratio) (* (1/ ASPECT_4X3) (-> arg0 x-ratio))) ;; same cropping as 4x3
(*! (-> arg0 x-ratio) (/ (-> *pc-settings* aspect-ratio) ASPECT_4X3)) ;; extend fov! shows more on the sides.
)
)
)
;; compute culling constants. these seem unused...
(let ((f1-3 (-> arg0 x-ratio))
(f0-7 (-> arg0 y-ratio))
(v1-6 (-> arg0 cull-info))
)
(/ (+ 1.0 (* 4.0 f1-3 f1-3)) (+ 1.0 (* f1-3 f1-3)))
(let ((f2-5 (/ (+ 1.0 (* 4.0 f0-7 f0-7)) (+ 1.0 (* f0-7 f0-7)))))
(set! (-> v1-6 x-fact) (/ (+ 1.0 (* 4.0 f1-3 f1-3)) (* f1-3 (sqrtf (+ 1.0 (* 16.0 f1-3 f1-3))))))
(set! (-> v1-6 y-fact) (/ (+ 1.0 (* 4.0 f0-7 f0-7)) (* f0-7 (sqrtf (+ 1.0 (* 16.0 f0-7 f0-7))))))
(set! (-> v1-6 z-fact) (sqrtf (+ (* (+ -4.0 f2-5) (+ -4.0 f2-5) f0-7 f0-7) (* (+ -1.0 f2-5) (+ -1.0 f2-5)))))
)
(let* ((f2-11 (* f1-3 (-> arg0 d)))
(f1-5 (* f0-7 (-> arg0 d)))
(f0-10 (+ (* f2-11 f2-11) (* f1-5 f1-5)))
(f1-8 (-> arg0 d))
)
(set! (-> v1-6 cam-radius) (sqrtf (+ f0-10 (* f1-8 f1-8))))
)
(let* ((f1-12 (* (-> arg0 d) (-> arg0 x-ratio)))
(f0-14 (-> arg0 d))
(f2-13 (* 4.0 f1-12))
(f3-21 (-> arg0 d))
)
(let ((f4-21 (/ 1.0 (sqrtf (+ (* f1-12 f1-12) (* f0-14 f0-14)))))
(f5-11 (/ 1.0 (sqrtf (+ (* f2-13 f2-13) (* f3-21 f3-21)))))
)
(set! (-> v1-6 xz-dir-ax) (* f1-12 f4-21))
(set! (-> v1-6 xz-dir-az) (* f0-14 f4-21))
(set! (-> v1-6 xz-dir-bx) (* f2-13 f5-11))
(set! (-> v1-6 xz-dir-bz) (* f3-21 f5-11))
)
(set! (-> v1-6 xz-cross-ab) (- (* f1-12 f3-21) (* f0-14 f2-13)))
)
(let* ((f1-15 (* (-> arg0 d) (-> arg0 y-ratio)))
(f0-18 (-> arg0 d))
(f2-15 (* 4.0 f1-15))
(f3-22 (-> arg0 d))
)
(let ((f4-26 (/ 1.0 (sqrtf (+ (* f1-15 f1-15) (* f0-18 f0-18)))))
(f5-16 (/ 1.0 (sqrtf (+ (* f2-15 f2-15) (* f3-22 f3-22)))))
)
(set! (-> v1-6 yz-dir-ay) (* f1-15 f4-26))
(set! (-> v1-6 yz-dir-az) (* f0-18 f4-26))
(set! (-> v1-6 yz-dir-by) (* f2-15 f5-16))
(set! (-> v1-6 yz-dir-bz) (* f3-22 f5-16))
)
(set! (-> v1-6 yz-cross-ab) (- (* f1-15 f3-22) (* f0-18 f2-15)))
)
)
;; apply fog correction.
(fog-corrector-setup *math-camera-fog-correction* arg0)
;; reset camera rotation
(matrix-identity! (-> arg0 camera-rot))
;;;;;;;;;;;;;; Perspective matrix setup
;; these min/max depths are the values we'd want to write to the 24-bit integer depth buffer
(let ((f0-21 100.0)
(f2-16 16760631.0)
)
16777115.0
(let ((f30-0 (/ (* (-> arg0 d) (- (-> arg0 fog-min) (-> arg0 fog-max)))
(- (-> *math-camera-fog-correction* fog-end) (-> *math-camera-fog-correction* fog-start))
)
)
(f1-21 (* -0.5 (- f2-16 f0-21))) ;; half range of depth buffer
)
(let ((f4-34 (/ f1-21 (* (-> arg0 d) (- (-> arg0 f) (-> arg0 d)))))
(f3-30 (-> arg0 fov-correction-factor))
)
(set! (-> arg0 perspective data 0) (* f3-30 (- (/ (-> arg0 x-pix) (* (-> arg0 x-ratio) (-> arg0 d))))))
(set! (-> arg0 perspective data 5) (* f3-30 (- (/ (-> arg0 y-pix) (* (-> arg0 y-ratio) (-> arg0 d))))))
(set! (-> arg0 perspective data 10) (* f3-30 (+ (-> arg0 f) (-> arg0 d)) f4-34))
(set! (-> arg0 perspective data 11) (* (/ f3-30 (-> arg0 d)) f30-0))
(set! (-> arg0 perspective trans z) (* -2.0 f4-34 (-> arg0 f) (-> arg0 d) f3-30))
)
(let ((f24-0 2048.0)
(f26-0 2048.0)
(f28-0 (/ (- (* (-> *math-camera-fog-correction* fog-end) (-> arg0 fog-max))
(* (-> *math-camera-fog-correction* fog-start) (-> arg0 fog-min))
)
(- (-> *math-camera-fog-correction* fog-end) (-> *math-camera-fog-correction* fog-start))
)
)
)
(let ((f22-0 (* 0.5 (+ f2-16 f0-21))))
(set! (-> arg0 hmge-scale x) (/ 1.0 (-> arg0 x-clip)))
(set! (-> arg0 hmge-scale y) (/ 1.0 (-> arg0 y-clip)))
(set! (-> arg0 hmge-scale z) (/ 1.0 f1-21))
(set! (-> arg0 hmge-scale w) (/ 1.0 f30-0))
(set! (-> arg0 inv-hmge-scale x) (-> arg0 x-clip))
(set! (-> arg0 inv-hmge-scale y) (-> arg0 y-clip))
(set! (-> arg0 inv-hmge-scale z) f1-21)
(set! (-> arg0 inv-hmge-scale w) f30-0)
(cond
((or (zero? *screen-shot-work*) (= (-> *screen-shot-work* count) -1))
(set! (-> arg0 hvdf-off x) f24-0)
(set! (-> arg0 hvdf-off y) f26-0)
)
(else
(let* ((v1-32 (-> *screen-shot-work* count))
(a0-36 (-> *screen-shot-work* size))
(f0-34 (the float a0-36))
(f20-0 (/ (the float (mod v1-32 a0-36)) f0-34))
)
(set! sv-16 (/ (the float (/ v1-32 a0-36)) f0-34))
(format 0 "~f ~f~%" f20-0 sv-16)
(set! (-> arg0 hvdf-off x) (- f24-0 f20-0))
)
(set! (-> arg0 hvdf-off y) (- f26-0 sv-16))
)
)
(set! (-> arg0 hvdf-off z) f22-0)
(set! (-> arg0 hvdf-off w) f28-0)
(set! (-> arg0 guard x) (/ (-> arg0 x-clip) (-> arg0 x-pix)))
(set! (-> arg0 guard y) (/ (-> arg0 y-clip) (-> arg0 y-pix)))
(set! (-> arg0 guard z) 1.0)
(set! (-> arg0 guard w) 1.0)
(set! (-> arg0 isometric trans z) (- 16777215.0 f22-0))
;; PC HACK!
;; for whatever reason, the font render ends up computing a depth #x1000000 instead of
;; #xffffffff, which overflows the 24-bit z buffer.
;; cheating this by 1 bit seems to fix it.
(#when PC_PORT
;; #x4b002032 -> #x4b002031
(set! (-> arg0 isometric vector 3 z) (the-as float (- (the-as int (-> arg0 isometric vector 3 z)) 1)))
)
)
(set! (-> arg0 isometric trans w) f30-0)
(let ((f1-28 (-> arg0 perspective data 0))
(f2-19 (-> arg0 perspective data 5))
(f0-48 (* -1.9996 (-> arg0 perspective data 0)))
)
(let ((v1-39 (-> arg0 sprite-2d)))
(set! (-> v1-39 data 0) f0-48)
(set! (-> v1-39 data 1) 0.0)
(set! (-> v1-39 data 2) 0.0)
(set! (-> v1-39 data 3) 0.0)
)
(let ((v1-40 (&-> arg0 sprite-2d data 4)))
(set! (-> v1-40 0) 0.0)
(set! (-> v1-40 1) (- (* (/ f2-19 f1-28) f0-48)))
(set! (-> v1-40 2) 0.0)
(set! (-> v1-40 3) 0.0)
)
(let ((v1-41 (&-> arg0 sprite-2d data 8)))
(set! (-> v1-41 0) 0.0)
(set! (-> v1-41 1) 0.0)
(set! (-> v1-41 2) (- f0-48))
(set! (-> v1-41 3) 0.0)
)
(set-vector! (-> arg0 sprite-2d trans) 0.0 0.0 (* 500000000.0 f0-48) (* 60.0 f0-48 (-> arg0 pfog0)))
)
(set! (-> arg0 sprite-2d-hvdf quad) (-> arg0 hvdf-off quad))
(set! (-> arg0 sprite-2d-hvdf x) 2048.0)
(set! (-> arg0 sprite-2d-hvdf y) 2048.0)
(set! (-> arg0 sprite-2d-hvdf z) (-> arg0 hvdf-off z))
(set! (-> arg0 pfog0) f30-0)
(set! (-> arg0 pfog1) f28-0)
)
)
)
0
;; garbage giftags
(make-u128 0 (shl #x301ec000 32))
(make-u128 0 (shl #x303ec000 32))
(let ((v1-54 (-> arg0 pfog0)))
(let ((a0-42 (-> arg0 vis-gifs)))
(set! (-> a0-42 0 fog0) (the-as uint v1-54))
(set! (-> a0-42 0 strip) (the-as uint #x301e4000))
(set! (-> a0-42 0 regs) (the-as uint 1042))
(set! (-> a0-42 0 fan) (the-as uint #x301ec000))
)
#|
(let ((a0-43 (&-> arg0 gifgr)))
(s.w! a0-43 v1-54)
(let ((a1-9 (make-u128 0 (shl #x20164000 32))))
(s.w! (+ a0-43 4) a1-9)
)
(let ((a1-10 65))
(s.w! (+ a0-43 8) a1-10)
)
(let ((a1-11 #x301ec000))
(s.w! (+ a0-43 12) a1-11)
)
)
|#
(let ((a0-44 (-> arg0 vis-gifs)))
(set! (-> a0-44 0 fog0) (the-as uint v1-54))
(set! (-> a0-44 0 strip) (the-as uint #x303e4000))
(set! (-> a0-44 0 regs) (the-as uint 1042))
(set! (-> a0-44 0 fan) (the-as uint #x303ec000))
)
(let ((a0-45 (-> arg0 vis-gifs)))
(set! (-> a0-45 0 fog0) (the-as uint v1-54))
(set! (-> a0-45 0 strip) (the-as uint #x303e4000))
(set! (-> a0-45 0 regs) (the-as uint 1042))
(set! (-> a0-45 0 fan) (the-as uint #x303ec000))
)
)
(if (nonzero? sprite-distorter-generate-tables)
(sprite-distorter-generate-tables)
)
arg0
)
(defmethod new math-camera ((allocation symbol) (type-to-make type))
"Set up a new math-camera in NTSC mode."
(let ((gp-0 (object-new allocation type-to-make (the-as int (-> type-to-make size)))))
(set! (-> gp-0 d) 1024.0)
(set! (-> gp-0 f) 40960000.0)
(set! (-> gp-0 fov) 11650.845)
(set! (-> gp-0 x-pix) 256.0)
(set! (-> gp-0 x-clip) 1024.0)
(set! (-> gp-0 y-pix) 112.0)
(set! (-> gp-0 y-clip) 448.0)
(set! (-> gp-0 fog-start) 40960.0)
(set! (-> gp-0 fog-end) 819200.0)
(set! (-> gp-0 fog-max) 255.0)
(set! (-> gp-0 fog-min) 150.0)
(matrix-identity! (-> gp-0 inv-camera-rot))
(matrix-identity! (-> gp-0 camera-rot))
(vector-reset! (-> gp-0 trans))
(quaternion-identity! (-> gp-0 quat-other))
(set-vector! (-> gp-0 trans-other) 0.0 0.0 0.0 1.0)
(matrix-identity! (-> gp-0 inv-camera-rot-other))
(matrix-identity! (-> gp-0 camera-rot-other))
(matrix-identity! (-> gp-0 camera-temp-other))
(set! (-> gp-0 isometric data 0) 1.0)
(set! (-> gp-0 isometric data 5) 0.5)
(set! (-> gp-0 isometric data 10) -1.0)
(set! (-> gp-0 reset) 1)
(set! (-> gp-0 smooth-step) 0.0)
(set! (-> gp-0 smooth-t) 0.0)
(update-math-camera gp-0 'ntsc 'aspect4x3 (-> gp-0 fov))
)
)
(define *math-camera* (new 'global 'math-camera))
(defun math-cam-start-smoothing ((arg0 float) (arg1 float))
"Unused camera smoothing"
(set! (-> *math-camera* smooth-step) (/ 1.0 arg0))
(set! (-> *math-camera* smooth-t) arg1)
(matrix->quaternion (-> *math-camera* inv-camera-rot-smooth-from) (-> *math-camera* inv-camera-rot-smooth))
)
(defun move-target-from-pad ((arg0 transform) (arg1 int))
"Unused function to adjust trans based on inputs from the pad.
This function must be extremely old because it takes a non-quaternion transform,
and all target stuff uses quaternions."
(let ((s4-0 (new-stack-vector0)))
(set! (-> s4-0 x) (cond
((cpad-hold? arg1 circle)
-80.0
)
((cpad-hold? arg1 square)
80.0
)
(else
0.0
)
)
)
(set! (-> s4-0 y) 0.0)
(set! (-> s4-0 z) (cond
((cpad-hold? arg1 down)
-80.0
)
((cpad-hold? arg1 up)
80.0
)
(else
0.0
)
)
)
(set! (-> s4-0 w) 1.0)
(let ((a0-5 (new-stack-vector0))
(s3-0 (new-stack-matrix0))
)
(vector-negate! a0-5 (-> arg0 rot))
(matrix-rotate-zyx! s3-0 (-> arg0 rot))
(vector-matrix*! s4-0 s4-0 s3-0)
)
(vector+! (-> arg0 trans) (-> arg0 trans) s4-0)
)
(set! (-> arg0 trans w) 1.0)
(if (cpad-hold? arg1 r1)
(set! (-> arg0 trans y) (+ 80.0 (-> arg0 trans y)))
)
(if (cpad-hold? arg1 r2)
(set! (-> arg0 trans y) (+ -80.0 (-> arg0 trans y)))
)
(if (cpad-hold? arg1 x)
(set! (-> arg0 rot x) (+ 546.13336 (-> arg0 rot x)))
)
(if (cpad-hold? arg1 triangle)
(set! (-> arg0 rot x) (+ -546.13336 (-> arg0 rot x)))
)
(if (cpad-hold? arg1 left)
(set! (-> arg0 rot y) (+ 546.13336 (-> arg0 rot y)))
)
(if (cpad-hold? arg1 right)
(set! (-> arg0 rot y) (+ -546.13336 (-> arg0 rot y)))
)
arg0
)
(defun transform-point-vector! ((arg0 vector) (arg1 vector))
"Apply camera transformation to a point. Return true if it is visible or not.
This returns the point in GS coords, but as float instead of int, so it's
not really useful. See transform-point-qword! for more details"
(rlet ((acc :class vf)
(Q :class vf)
(vf0 :class vf)
(vf23 :class vf)
(vf24 :class vf)
(vf25 :class vf)
(vf26 :class vf)
(vf27 :class vf)
(vf28 :class vf)
(vf29 :class vf)
(vf30 :class vf)
(vf31 :class vf)
)
(init-vf0-vector)
(let ((v1-0 0))
)
(.lvf vf24 (&-> *math-camera* camera-temp vector 0 quad))
(.lvf vf25 (&-> *math-camera* camera-temp vector 1 quad))
(.lvf vf26 (&-> *math-camera* camera-temp vector 2 quad))
(.lvf vf27 (&-> *math-camera* camera-temp vector 3 quad))
(.lvf vf29 (&-> *math-camera* hmge-scale quad))
(.lvf vf30 (&-> *math-camera* hvdf-off quad))
(.lvf vf28 (&-> arg1 quad))
(.mul.x.vf acc vf24 vf28)
(.add.mul.y.vf acc vf25 vf28 acc)
(.add.mul.z.vf acc vf26 vf28 acc)
(.add.mul.w.vf vf28 vf27 vf0 acc)
(.add.w.vf vf23 vf0 vf0)
(.mul.vf vf31 vf28 vf29)
;;(TODO.VCLIP vf31 vf31)
(let ((clip (vu-clip vf31 0)))
(.div.vf Q vf0 vf31 :fsf #b11 :ftf #b11)
(.wait.vf)
;;(.cfc2.i v1-7 Clipping)
(.mul.vf vf28 vf28 Q :mask #b111)
(.mul.vf vf23 vf23 Q)
(.add.vf vf28 vf28 vf30)
(.max.x.vf vf28 vf28 vf0 :mask #b1000)
(.svf (&-> arg0 quad) vf28)
(zero? (logand clip 63))
)
)
)
;; definition for function transform-point-qword!
(defun transform-point-qword! ((arg0 vector4w) (arg1 vector))
"Apply camera transformation to point, returning fixed point 28.4 position
that can be given to the GS directly."
(rlet ((acc :class vf)
(Q :class vf)
(vf0 :class vf)
(vf23 :class vf)
(vf24 :class vf)
(vf25 :class vf)
(vf26 :class vf)
(vf27 :class vf)
(vf28 :class vf)
(vf29 :class vf)
(vf30 :class vf)
(vf31 :class vf)
)
(init-vf0-vector)
(let ((v1-0 0))
)
;; this camera matrix has both the projection and camera translation/rotation
(.lvf vf24 (&-> *math-camera* camera-temp vector 0 quad))
(.lvf vf25 (&-> *math-camera* camera-temp vector 1 quad))
(.lvf vf26 (&-> *math-camera* camera-temp vector 2 quad))
(.lvf vf27 (&-> *math-camera* camera-temp vector 3 quad))
;; scaling
(.lvf vf29 (&-> *math-camera* hmge-scale quad))
;; offset
(.lvf vf30 (&-> *math-camera* hvdf-off quad))
;; input point
(.lvf vf28 (&-> arg1 quad))
;; matrix multiply, result in vf28
;(print-vf vf28)
(.mul.x.vf acc vf24 vf28)
(.add.mul.y.vf acc vf25 vf28 acc)
(.add.mul.z.vf acc vf26 vf28 acc)
(.add.mul.w.vf vf28 vf27 vf0 acc)
;(print-vf vf28)
(.add.w.vf vf23 vf0 vf0) ;; set w = 1.0
;; apply hmge scaling. the result of this multiply sets clipping flags appropriately
(.mul.vf vf31 vf28 vf29) ;; scale.
;;(TODO.VCLIP vf31 vf31)
(let ((clip (vu-clip vf31 0))) ;; clip!
;; perspective divide
(.div.vf Q vf0 vf31 :fsf #b11 :ftf #b11)
(.wait.vf)
;;(.cfc2.i v1-7 Clipping)
;; perspective
(.mul.vf vf28 vf28 Q :mask #b111)
;; compute scale factor (w was 1.0)
(.mul.vf vf23 vf23 Q)
;; apply hvdf offsets
(.add.vf vf28 vf28 vf30)
;; saturate fog
(.max.x.vf vf28 vf28 vf0 :mask #b1000)
;; convert to GS fixed point
(vftoi4.xyzw vf28 vf28)
;; store result!
(.svf (&-> arg0 quad) vf28)
;; return result of clipping.
(zero? (logand clip 63))
)
)
)
(defun transform-point-vector-scale! ((arg0 vector) (arg1 vector))
"Similar to transform-point-qword! but returns the scale factor instead."
(local-vars (v0-0 float))
(rlet ((acc :class vf)
(Q :class vf)
(vf0 :class vf)
(vf23 :class vf)
(vf24 :class vf)
(vf25 :class vf)
(vf26 :class vf)
(vf27 :class vf)
(vf28 :class vf)
(vf29 :class vf)
(vf30 :class vf)
(vf31 :class vf)
)
(init-vf0-vector)
(let ((v1-0 0))
)
(.lvf vf24 (&-> *math-camera* camera-temp vector 0 quad))
(.lvf vf25 (&-> *math-camera* camera-temp vector 1 quad))
(.lvf vf26 (&-> *math-camera* camera-temp vector 2 quad))
(.lvf vf27 (&-> *math-camera* camera-temp vector 3 quad))
(.lvf vf29 (&-> *math-camera* hmge-scale quad))
(.lvf vf30 (&-> *math-camera* hvdf-off quad))
(.lvf vf28 (&-> arg1 quad))
(.mul.x.vf acc vf24 vf28)
(.add.mul.y.vf acc vf25 vf28 acc)
(.add.mul.z.vf acc vf26 vf28 acc)
(.add.mul.w.vf vf28 vf27 vf0 acc)
(.add.w.vf vf23 vf0 vf0)
(.mul.vf vf31 vf28 vf29)
;;(TODO.VCLIP vf31 vf31) clip result was unused
(.div.vf Q vf0 vf31 :fsf #b11 :ftf #b11)
(.wait.vf)
;;(.cfc2.i v1-7 Clipping)
(.mul.vf vf28 vf28 Q :mask #b111)
(.mul.vf vf23 vf23 Q)
(.add.vf vf28 vf28 vf30)
(.max.x.vf vf28 vf28 vf0 :mask #b1000)
(.svf (&-> arg0 quad) vf28)
;;(let ((a0-2 (zero? (logand v1-7 63))))
;; )
(.mov v0-0 vf23)
v0-0
)
)
(defun reverse-transform-point! ((arg0 vector) (arg1 vector) (arg2 vector) (arg3 vector))
"Likely transform arg3 from screen space to world coords, using arg1/arg2 for... something."
(let* ((v1-1 (-> *math-camera* perspective))
(s2-0 (-> *math-camera* camera-rot))
(f30-0 (* (/ (-> v1-1 data 11) (-> v1-1 data 0)) (-> *math-camera* hmge-scale w)))
(f28-0 (* (/ (-> v1-1 data 11) (-> v1-1 data 5)) (-> *math-camera* hmge-scale w)))
(s4-0 (vector-rotate*! (new 'stack-no-clear 'vector) arg2 s2-0))
(v1-3 (vector-matrix*! (new 'stack-no-clear 'vector) arg1 s2-0))
(f0-8 (/ (+ (* (-> s4-0 x) (-> v1-3 x)) (* (-> s4-0 y) (-> v1-3 y)) (* (-> s4-0 z) (-> v1-3 z)))
(+ (* (-> s4-0 x) (-> arg3 x) f30-0) (* (-> s4-0 y) (-> arg3 y) f28-0) (-> s4-0 z))
)
)
(f1-16 (* (-> arg3 x) f0-8 f30-0))
(f2-9 (* (-> arg3 y) f0-8 f28-0))
(t9-2 vector-matrix*!)
(a0-5 arg0)
(a1-3 (new 'stack-no-clear 'vector))
)
(set! (-> a1-3 x) f1-16)
(set! (-> a1-3 y) f2-9)
(set! (-> a1-3 z) f0-8)
(set! (-> a1-3 w) 1.0)
(t9-2 a0-5 a1-3 (-> *math-camera* inv-camera-rot))
)
(none)
)
(defun init-for-transform ((arg0 matrix))
"Sets up VU0 registers with camera info.
This is probably a very old function and it's only used by camera debug.
It stashes some data in vector float registers that must be there before calling transform-float-point."
(rlet ((vf1 :class vf)
(vf17 :class vf)
(vf18 :class vf)
(vf19 :class vf)
(vf2 :class vf)
(vf23 :class vf)
(vf24 :class vf)
(vf25 :class vf)
(vf26 :class vf)
(vf27 :class vf)
(vf28 :class vf)
(vf29 :class vf)
(vf3 :class vf)
(vf4 :class vf)
(vf6 :class vf)
(vf7 :class vf)
(vf8 :class vf)
(vf9 :class vf)
)
(let ((gp-0 (new-stack-matrix0))
(s5-0 (new-stack-matrix0))
(s4-0 (new 'stack 'vector4s-3))
(s3-0 (new-stack-vector0))
(s2-0 (new 'stack 'vector4s-3))
)
(matrix*! s5-0 arg0 (-> *math-camera* camera-temp))
(matrix-3x3-inverse-transpose! gp-0 arg0)
(let ((v1-3 s3-0))
(set! (-> v1-3 x) 0.4)
(set! (-> v1-3 y) 0.4)
(set! (-> v1-3 z) 0.4)
(set! (-> v1-3 w) 1.0)
)
(let ((v1-4 (-> s4-0 data)))
(set! (-> v1-4 0) 1.0)
(set! (-> v1-4 1) 1.0)
(set! (-> v1-4 2) 1.0)
(set! (-> v1-4 3) 1.0)
)
(let ((v1-5 (&-> s4-0 data 4)))
(set! (-> v1-5 0) 0.0)
(set! (-> v1-5 1) 0.0)
(set! (-> v1-5 2) 0.0)
(set! (-> v1-5 3) 1.0)
)
(let ((v1-6 (&-> s4-0 data 8)))
(set! (-> v1-6 0) 0.0)
(set! (-> v1-6 1) 0.0)
(set! (-> v1-6 2) 0.0)
(set! (-> v1-6 3) 1.0)
)
(let ((v1-7 (-> s2-0 data)))
(set! (-> v1-7 0) 1.0)
(set! (-> v1-7 1) 0.0)
(set! (-> v1-7 2) 0.0)
(set! (-> v1-7 3) 1.0)
)
(let ((v1-8 (&-> s2-0 data 4)))
(set! (-> v1-8 0) 0.0)
(set! (-> v1-8 1) 1.0)
(set! (-> v1-8 2) 0.0)
(set! (-> v1-8 3) 1.0)
)
(let ((v1-9 (&-> s2-0 data 8)))
(set! (-> v1-9 0) 0.0)
(set! (-> v1-9 1) 0.0)
(set! (-> v1-9 2) 1.0)
(set! (-> v1-9 3) 1.0)
)
(.lvf vf7 (&-> *math-camera* hmge-scale quad))
(.lvf vf8 (&-> *math-camera* hvdf-off quad))
(.lvf vf9 (&-> *math-camera* giftex))
(let ((v1-13 255))
(.mov vf6 v1-13)
)
;;(.mov v1-14 vf6)
(.itof.vf vf6 vf6)
(.svf (&-> *transform-regs* vf7) vf7)
(.svf (&-> *transform-regs* vf8) vf8)
(.svf (&-> *transform-regs* vf9) vf9)
(.svf (&-> *transform-regs* vf6) vf6)
(set! (-> *transform-regs* vf1) (-> s5-0 vector 0 quad))
(set! (-> *transform-regs* vf2) (-> s5-0 vector 1 quad))
(set! (-> *transform-regs* vf3) (-> s5-0 vector 2 quad))
(set! (-> *transform-regs* vf4) (-> s5-0 vector 3 quad))
(set! (-> *transform-regs* vf17) (-> gp-0 vector 0 quad))
(set! (-> *transform-regs* vf18) (-> gp-0 vector 1 quad))
(set! (-> *transform-regs* vf19) (-> gp-0 vector 2 quad))
(set! (-> *transform-regs* vf23) (-> s2-0 quad 0))
(set! (-> *transform-regs* vf24) (-> s2-0 quad 1))
(set! (-> *transform-regs* vf25) (-> s2-0 quad 2))
(set! (-> *transform-regs* vf27) (-> s4-0 quad 0))
(set! (-> *transform-regs* vf28) (-> s4-0 quad 1))
(set! (-> *transform-regs* vf29) (-> s4-0 quad 2))
(set! (-> *transform-regs* vf26) (-> s3-0 quad))
)
(none)
)
)