Files
jak-project/goal_src/jak1/examples/debug-jak2.gc
T
water111 4eea31c3e9 [jak 2] texture (#1866)
- Decompile and patch `texture.gc` for PC
- Improve decompiler when offset doesn't fit in immediate (for types
larger than 8k and some scratchpad accesses)
- Fix symbol->string issues in both jak 1 and 2
- Fix bug with VIF interrupt used to profile VU code (hooked up to
OpenGLRenderer BucketRenderers in PC port)
- Support `~o` in `format`.
- Uncomment stuff in `merc.gc` that now works!

![image](https://user-images.githubusercontent.com/48171810/189505469-941b4a3e-23c7-4740-aa1b-2e461ed19fa9.png)

fixes https://github.com/open-goal/jak-project/issues/1850
2022-09-11 14:17:55 -04:00

114 lines
4.4 KiB
Common Lisp

(defun hack-update-camera ((location vector) (inv-rot matrix))
"Debugging function to set the camera's position and orientation"
;; update to compute the perspective matrix.
(update-math-camera
*math-camera*
'ntsc
'aspect4x3
(-> *math-camera* fov)
)
;; copy the input rotation
(matrix-copy! (-> *math-camera* inv-camera-rot) inv-rot)
;; inverse of rotation matrix matrix is its transpose
(matrix-transpose! (-> *math-camera* camera-rot) (-> *math-camera* inv-camera-rot))
;; fake some value here
(set! (-> *math-camera* fov-correction-factor) 1.0)
;; do the math
(set! (-> *math-camera* trans quad) (-> location quad))
(let ((cam-temp (-> *math-camera* camera-temp))
(cam-rot (-> *math-camera* camera-rot))
(inv-cam-rot (-> *math-camera* inv-camera-rot))
(cam-trans (-> *math-camera* trans))
)
(let ((rotated-trans (new-stack-vector0)))
(set! (-> rotated-trans x) (- (-> cam-trans x)))
(set! (-> rotated-trans y) (- (-> cam-trans y)))
(set! (-> rotated-trans z) (- (-> cam-trans z)))
(set! (-> rotated-trans w) 1.0)
(vector-matrix*! rotated-trans rotated-trans cam-rot)
(set! (-> cam-rot vector 3 quad) (-> rotated-trans quad))
)
(matrix*! cam-temp cam-rot (-> *math-camera* perspective))
(set! (-> inv-cam-rot vector 3 quad) (-> cam-trans quad))
;; fixes it!
;(set! (-> *math-camera* camera-temp data 15) -6.)
)
(none)
)
(defun test-function ((iter int))
"This function draws the debug stuff. You can edit this, then reload this file to play with it."
;; val will increase from 0 to 1, then reset back to 0.
(let* ((frame (the float (mod (* 4 iter) 1600)))
(val (/ frame 1600.0)))
(format *stdcon* "~0kval ~f~%" val)
;; orbit the camera around in a circle with radius 5 m.
(let* ((rad (meters 5.0))
(x (* rad (sin (* (degrees 360.0) val))))
(z (* rad (cos (* (degrees 360.0) val))))
(cam-pos (new 'stack 'vector))
(cam-inv-rot (new 'stack 'matrix))
)
;; this matrix will look directly at the origin...
(set! (-> cam-pos x) x)
(set! (-> cam-pos z) z)
(set! (-> cam-pos y) (meters 1.))
(forward-down->inv-matrix cam-inv-rot cam-pos (new 'static 'vector :y 1.0))
;; if the camera is here.
(set! (-> cam-pos x) (- 0. x))
(set! (-> cam-pos z) (- 0. z))
(set! (-> cam-pos y) (meters -3.))
(hack-update-camera cam-pos cam-inv-rot)
;; create some test points
(let ((p0 (new 'static 'vector :x (meters .8) :y (meters .2) :z (meters 2.0)))
(p1 (new 'static 'vector :x (meters .3) :y (meters .3) :z (meters 2.5)))
(p2 (new 'static 'vector :x (meters .5) :y (meters .7) :z (meters 1.5)))
(b0 (new 'static 'vector :x (meters .5) :y (meters .5) :z (meters .5)))
(b1 (new 'static 'vector :x (meters -.5) :y (meters -.5) :z (meters -.5)))
)
(add-debug-cross #t (bucket-id debug-no-zbuf) (new 'static 'vector) (meters 2.0))
(add-debug-box #t (bucket-id debug-no-zbuf) p0 p2 (new 'static 'rgba :b #x80 :r #x80 :g #x80 :a #x80))
(add-debug-flat-triangle #t (bucket-id debug-no-zbuf) p0 p1 p2 (new 'static 'rgba :r #x80 :a #x80))
(add-debug-text-3d #t (bucket-id debug-no-zbuf) "triangle!" p0 (the font-color 1) (the vector2h #f))
(add-debug-sphere #t (bucket-id debug-no-zbuf) p0 (meters 0.5) (new 'static 'rgba :r #x80 :a #x80))
(add-debug-line-sphere #t (bucket-id debug-no-zbuf)
(new 'static 'vector :x (meters 0.8))
(new 'static 'vector :y (meters -4.0))
(meters 1.0) (new 'static 'rgba :r #x40 :g #x80 :a #x80))
)
)
)
(none)
)
(defun launch-test-process ()
"Call this to launch a process that draws the debug demo"
(let ((proc (get-process *nk-dead-pool* process 1024)))
(activate proc *active-pool* "test" *kernel-dram-stack*)
(run-next-time-in-process proc (lambda ()
(let ((iter 0))
(while #t
(test-function iter)
(suspend)
(+! iter 1)
)
)
)
)
proc)
)