Files
jak-project/goal_src/jak1/engine/camera/cam-interface.gc
T
2026-08-07 20:58:40 -04:00

67 lines
2.5 KiB
Common Lisp

;;-*-Lisp-*-
(in-package goal)
(bundles "ENGINE.CGO" "GAME.CGO")
(require "engine/camera/cam-interface-h.gc")
(require "engine/math/quaternion.gc")
(require "kernel/gstate.gc")
(require "engine/gfx/math-camera-h.gc")
(require "engine/entity/entity-h.gc")
(require "engine/math/transformq-h.gc")
;; DECOMP BEGINS
(defun position-in-front-of-camera! ((out vector) (forward-distance float) (up-distance float))
"Place out at forward-distance along the camera's
forward axis and up-distance along its up axis, measured from the current camera translation."
(vector-float*! out (-> *math-camera* inv-camera-rot vector 2) forward-distance)
(vector+float*! out out (-> *math-camera* inv-camera-rot vector 1) up-distance)
(vector+! out out (-> *math-camera* trans))
out)
(defun matrix-local->world ((smooth? symbol) (unused-mode symbol))
"Return the camera local-to-world rotation. smooth? selects the
smoothed inverse-camera matrix; the second argument is retained for the shared interface but is
unused."
(if smooth?
(-> *math-camera* inv-camera-rot-smooth)
(-> *math-camera* inv-camera-rot)))
(defun matrix-world->local ()
"Return the current world-to-camera rotation matrix."
(-> *math-camera* camera-rot))
(define-perm *camera-dummy-vector* vector (vector-reset! (new 'global 'vector)))
(defun camera-pos ()
"Return the active camera position. Prefer the combiner output while a
camera transition is active, otherwise use the renderer camera, with a zero-vector fallback
before camera initialization."
(cond
(*camera-combiner*
(-> *camera-combiner* trans))
(*math-camera*
(-> *math-camera* trans))
(else
*camera-dummy-vector*)))
(defun math-camera-pos ()
"Return the renderer's current camera translation."
(-> *math-camera* trans))
(defun camera-angle ()
"Return the camera's horizontal heading from the X and Z components of
the world-to-camera right axis."
(let ((right-x (-> *math-camera* camera-rot vector 0 x))
(right-z (-> *math-camera* camera-rot vector 0 z)))
(atan right-z right-x)))
(defbehavior camera-teleport-to-entity process ((start-entity entity-actor))
"Teleport the camera to the entity position."
(let ((teleport-transform (new 'stack 'transformq)))
(vector-copy! (-> teleport-transform trans) (-> start-entity extra trans))
(quaternion-copy! (-> teleport-transform quat) (-> start-entity quat))
(vector-identity! (-> teleport-transform scale))
(send-event *camera* 'teleport-to-transformq teleport-transform))
0
(none))