Files
jak-project/goal_src/jak1/engine/math/transformq-h.gc
T
2026-07-26 14:43:53 -04:00

74 lines
4.9 KiB
Common Lisp

;;-*-Lisp-*-
(in-package goal)
(bundles "ENGINE.CGO" "GAME.CGO")
(require "engine/math/quaternion-h.gc")
(require "engine/math/vector-h.gc")
(require "engine/math/transform-h.gc")
;; DECOMP BEGINS
;; A transform whose rotation storage is interpreted as a quaternion.
;; This is the usual compact transform representation.
(deftype transformq (transform)
;; Overlay transform.rot without changing the inherited layout.
((quat quaternion :inline :overlay-at (-> rot x))))
;; The basic-object counterpart of transformq.
(deftype trsq (trs)
;; Overlay trs.rot without changing the inherited layout.
((quat quaternion :inline :overlay-at (-> rot x))))
;; A quaternion transform with linear, angular, and scale velocities.
;; Moving game objects commonly inherit this type for its steering controls; Jak's
;; control object does as well. Most controls assume Y is up and roll and pitch remain
;; small, as expected for actors that stay upright.
(deftype trsqv (trsq)
((pause-adjust-distance meters :offset 4) ;; Actor logic-pause distance adjustment.
(nav-radius meters :offset 8) ;; Navigation bounding-sphere radius.
(transv vector :inline) ;; Linear velocity in meters per second.
(rotv vector :inline) ;; Angular velocity in rotation units per second.
(scalev vector :inline) ;; Scale velocity.
(dir-targ quaternion :inline) ;; Desired orientation used by target and vehicle controls.
;; World-Y reversal filter. The signed previous step confirms a reversal that persists for a
;; second frame; the timestamp permits an immediate reversal after 0.2 seconds without a full turn.
(angle-change-time time-frame)
(old-y-angle-diff float))
(:methods
(seek-toward-heading-vec! "Turn about world Y toward heading's XZ yaw. Clamp each frame's step by max-yaw-rate and
response-time. A fresh reversal requires one confirming frame unless no full turn has been accepted
for 0.2 seconds." (_type_ vector float time-frame) quaternion)
(set-heading-vec! "Immediately turn toward heading within the plane perpendicular to the current up direction,
preserving that up direction." (_type_ vector) quaternion)
(seek-to-point-toward-point! "Turn about world Y toward target-point from this position using max-yaw-rate and
response-time." (_type_ vector float time-frame) quaternion)
(point-toward-point! "Immediately turn toward target-point within the plane perpendicular to the current up
direction." (_type_ vector) quaternion)
(seek-toward-yaw-angle! "Turn toward yaw using max-yaw-rate and response-time." (_type_ float float time-frame) quaternion)
(set-yaw-angle-clear-roll-pitch! "Set yaw immediately with a horizontal forward direction and world +Y up." (_type_ float) quaternion)
(set-roll-to-grav! "Align local up with standard world up while retaining forward, then apply roll-offset." (_type_ float) quaternion)
(set-roll-to-grav-2! "Align local up with standard world up projected perpendicular to forward, rebuild the right
axis, then apply roll-offset about local Z." (_type_ float) quaternion)
(rotate-toward-orientation! "Rotate the current local Y axis toward target's Y axis at z-rate, then the resulting local Z
axis toward target's Z axis at y-rate. Each rate is converted to a per-frame maximum." (_type_ quaternion float float) quaternion)
(set-quaternion! "Copy rotation into this transform." (_type_ quaternion) quaternion)
(set-heading-vec-clear-roll-pitch! "Build an orientation from normalized heading and world +Y. This removes roll; a horizontal
heading also removes pitch." (_type_ vector) quaternion)
(point-toward-point-clear-roll-pitch! "Build an orientation toward target-point using world +Y. This removes roll; a target at the
same height also removes pitch." (_type_ vector) quaternion)
(rot->dir-targ! "Copy the current rotation into dir-targ." (_type_) quaternion)
(y-angle "Return the current quaternion's yaw." (_type_) float)
(global-y-angle-to-point "Return the world yaw from this position to point." (_type_ vector) float)
(relative-y-angle-to-point "Return the shortest yaw from this orientation toward point." (_type_ vector) float)
(roll-relative-to-gravity "Return signed roll relative to standard world up after projecting world up perpendicular to
the current forward axis." (_type_) float)
(set-and-limit-velocity (_type_ int vector float) trsqv)
(get-quaternion "Return the transform's quaternion storage." (_type_) quaternion)))
(defmethod global-y-angle-to-point ((this trsqv) (point vector))
"Return the world yaw from this position to point."
(vector-y-angle (vector-! (new 'stack-no-clear 'vector) point (-> this trans))))
(defmethod relative-y-angle-to-point ((this trsqv) (point vector))
"Return the shortest yaw from this orientation toward point."
(deg-diff (y-angle this) (vector-y-angle (vector-! (new 'stack-no-clear 'vector) point (-> this trans)))))