mirror of
https://github.com/open-goal/jak-project
synced 2026-08-11 11:33:51 -04:00
63 lines
2.7 KiB
Common Lisp
63 lines
2.7 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")
|
|
|
|
(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."
|
|
(the-as vector
|
|
(cond
|
|
(*camera-combiner* (-> *camera-combiner* stack))
|
|
(*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))
|
|
"Build a unit-scale camera transform from start-entity's
|
|
orientation and the position stored in the scale vector of its extra transform, then send it to
|
|
the camera master as an immediate teleport."
|
|
(let ((teleport-transform (new 'stack 'transformq)))
|
|
(vector-copy! (-> teleport-transform trans) (-> (the-as transform (-> start-entity extra)) scale))
|
|
(quaternion-copy! (-> teleport-transform quat) (-> start-entity quat))
|
|
(vector-identity! (-> teleport-transform scale))
|
|
(send-event *camera* 'teleport-to-transformq teleport-transform))
|
|
0
|
|
(none))
|