Files
jak-project/goal_src/jak1/engine/math/euler.gc
T
Tyler Wilding d1ece445d4 Dependency graph work - Part 1 - Preliminary work (#3505)
Relates to #1353 

This adds no new functionality or overhead to the compiler, yet. This is
the preliminary work that has:
- added code to the compiler in several spots to flag when something is
used without being properly required/imported/whatever (disabled by
default)
- that was used to generate project wide file dependencies (some
circulars were manually fixed)
- then that graph underwent a transitive reduction and the result was
written to all `jak1` source files.

The next step will be making this actually produce and use a dependency
graph. Some of the reasons why I'm working on this:
- eliminates more `game.gp` boilerplate. This includes the `.gd` files
to some extent (`*-ag` files and `tpage` files will still need to be
handled) this is the point of the new `bundles` form. This should make
it even easier to add a new file into the source tree.
- a build order that is actually informed from something real and
compiler warnings that tell you when you are using something that won't
be available at build time.
- narrows the search space for doing LSP actions -- like searching for
references. Since it would be way too much work to store in the compiler
every location where every symbol/function/etc is used, I have to do
ad-hoc searches. By having a dependency graph i can significantly reduce
that search space.
- opens the doors for common shared code with a legitimate pattern.
Right now jak 2 shares code from the jak 1 folder. This is basically a
hack -- but by having an explicit require syntax, it would be possible
to reference arbitrary file paths, such as a `common` folder.

Some stats:
- Jak 1 has about 2500 edges between files, including transitives
- With transitives reduced at the source code level, each file seems to
have a modest amount of explicit requirements.

Known issues:
- Tracking the location for where `defmacro`s and virtual state
definitions were defined (and therefore the file) is still problematic.
Because those forms are in a macro environment, the reader does not
track them. I'm wondering if a workaround could be to search the
reader's text_db by not just the `goos::Object` but by the text
position. But for the purposes of finishing this work, I just statically
analyzed and searched the code with throwaway python code.
2024-05-12 12:37:59 -04:00

261 lines
10 KiB
Common Lisp

;;-*-Lisp-*-
(in-package goal)
(bundles "ENGINE.CGO" "GAME.CGO")
(require "engine/math/quaternion.gc")
(require "engine/math/euler-h.gc")
;; name: euler.gc
;; name in dgo: euler
;; dgos: GAME, ENGINE
;; In general, the euler angle stuff is really inefficient. I don't think it's really used outside of
;; a few camera debugging functions.
(defun set-eul! ((arg0 euler-angles) (arg1 float) (arg2 float) (arg3 float) (arg4 int))
"Set the euler angles. The 4th argument is for flags."
(set! (-> arg0 data 0) arg1)
(set! (-> arg0 data 1) arg2)
(set! (-> arg0 data 2) arg3)
(set! (-> arg0 data 3) (the float arg4))
arg0
)
(defun eul->matrix ((arg0 matrix) (arg1 euler-angles))
"Convert euler angles to rotation matrix."
(matrix-identity! arg0)
(let ((s5-0 (new 'stack-no-clear 'vector)))
;; copy to temp storage.
(set! (-> s5-0 quad) (-> arg1 quad))
(if (= (logand (the int (-> s5-0 data 3)) 1) 1)
(let ((f0-2 (-> s5-0 data 0)))
(set! (-> s5-0 data 0) (-> s5-0 data 2))
(set! (-> s5-0 data 2) f0-2)
)
)
(when (= (logand (sar (the int (-> s5-0 data 3)) 2) 1) 1)
(set! (-> s5-0 data 0) (- (-> s5-0 data 0)))
(set! (-> s5-0 data 1) (- (-> s5-0 data 1)))
(set! (-> s5-0 data 2) (- (-> s5-0 data 2)))
)
(let* ((f26-0 (cos (-> s5-0 data 0)))
(f30-0 (cos (-> s5-0 data 1)))
(f22-0 (cos (-> s5-0 data 2)))
(f24-0 (sin (-> s5-0 data 0)))
(f28-0 (sin (-> s5-0 data 1)))
(f4-0 (sin (-> s5-0 data 2)))
(f0-17 (* f26-0 f22-0))
(f1-1 (* f26-0 f4-0))
(f2-0 (* f24-0 f22-0))
(f3-0 (* f24-0 f4-0))
)
(let* ((v1-12 (logand (sar (the int (-> s5-0 data 3)) 2) 1))
(a1-2 (-> EulSafe (logand (sar (the int (-> s5-0 data 3)) 3) 3)))
(a0-21 (-> EulNext (+ a1-2 v1-12)))
(v1-17 (-> EulNext (+ (- 1 v1-12) a1-2)))
)
(cond
((= (logand (sar (the int (-> s5-0 data 3)) 1) 1) 1)
(set! (-> (the-as (pointer float) (+ (+ (shl a1-2 4) (shl a1-2 2)) (the-as int arg0))))
f30-0
)
(set! (-> (the-as (pointer float) (+ (+ (shl a1-2 4) (shl a0-21 2)) (the-as int arg0))))
(* f28-0 f24-0)
)
(set! (-> (the-as (pointer float) (+ (+ (shl a1-2 4) (shl v1-17 2)) (the-as int arg0))))
(* f28-0 f26-0)
)
(set! (-> (the-as (pointer float) (+ (+ (shl a0-21 4) (shl a1-2 2)) (the-as int arg0))))
(* f28-0 f4-0)
)
(set! (-> (the-as (pointer float) (+ (+ (shl a0-21 4) (shl a0-21 2)) (the-as int arg0))))
(- f0-17 (* f30-0 f3-0))
)
(set! (-> (the-as (pointer float) (+ (+ (shl a0-21 4) (shl v1-17 2)) (the-as int arg0))))
(- (- f2-0) (* f30-0 f1-1))
)
(set! (-> (the-as (pointer float) (+ (+ (shl v1-17 4) (shl a1-2 2)) (the-as int arg0))))
(- (* f28-0 f22-0))
)
(set! (-> (the-as (pointer float) (+ (+ (shl v1-17 4) (shl a0-21 2)) (the-as int arg0))))
(+ f1-1 (* f30-0 f2-0))
)
(let ((f0-19 (+ (- f3-0) (* f30-0 f0-17))))
(set! (-> (the-as (pointer float) (+ (+ (shl v1-17 4) (shl v1-17 2)) (the-as int arg0))))
f0-19
)
)
)
(else
(set! (-> (the-as (pointer float) (+ (+ (shl a1-2 4) (shl a1-2 2)) (the-as int arg0))))
(* f30-0 f22-0)
)
(set! (-> (the-as (pointer float) (+ (+ (shl a1-2 4) (shl a0-21 2)) (the-as int arg0))))
(+ (- f1-1) (* f28-0 f2-0))
)
(set! (-> (the-as (pointer float) (+ (+ (shl a1-2 4) (shl v1-17 2)) (the-as int arg0))))
(+ f3-0 (* f28-0 f0-17))
)
(set! (-> (the-as (pointer float) (+ (+ (shl a0-21 4) (shl a1-2 2)) (the-as int arg0))))
(* f30-0 f4-0)
)
(set! (-> (the-as (pointer float) (+ (+ (shl a0-21 4) (shl a0-21 2)) (the-as int arg0))))
(+ f0-17 (* f28-0 f3-0))
)
(set! (-> (the-as (pointer float) (+ (+ (shl a0-21 4) (shl v1-17 2)) (the-as int arg0))))
(+ (- f2-0) (* f28-0 f1-1))
)
(set! (-> (the-as (pointer float) (+ (+ (shl v1-17 4) (shl a1-2 2)) (the-as int arg0))))
(- f28-0)
)
(set! (-> (the-as (pointer float) (+ (+ (shl v1-17 4) (shl a0-21 2)) (the-as int arg0))))
(* f30-0 f24-0)
)
(let ((f0-25 (* f30-0 f26-0)))
(set! (-> (the-as (pointer float) (+ (+ (shl v1-17 4) (shl v1-17 2)) (the-as int arg0))))
f0-25
)
)
)
)
)
)
)
arg0
)
(defun matrix->eul ((arg0 euler-angles) (arg1 matrix) (arg2 int))
"Conver matrix to euler angles. Takes some weird flag for what kind of euler angles"
(let* ((v1-4 (logand (sar arg2 2) 1))
(s3-0 (-> EulSafe (logand (sar arg2 3) 3)))
(s2-0 (-> EulNext (+ s3-0 v1-4)))
(s1-0 (-> EulNext (+ (- 1 v1-4) s3-0)))
)
(if (= (logand (sar arg2 1) 1) 1)
(let* ((f0-0 (-> (the-as (pointer float) (+ (+ (shl s2-0 2) (shl s3-0 4)) (the-as int arg1)))))
(f0-2 (* f0-0 f0-0))
(f1-0 (-> (the-as (pointer float) (+ (+ (shl s1-0 2) (shl s3-0 4)) (the-as int arg1)))))
(f30-0 (sqrtf (+ f0-2 (* f1-0 f1-0))))
)
(cond
((< 0.00001 f30-0)
(set! (-> arg0 data 0)
(atan (-> (the-as (pointer float) (+ (+ (shl s2-0 2) (shl s3-0 4)) (the-as int arg1))))
(-> (the-as (pointer float) (+ (+ (shl s1-0 2) (shl s3-0 4)) (the-as int arg1))))
)
)
(set! (-> arg0 data 1)
(atan f30-0 (-> (the-as (pointer float) (+ (+ (shl s3-0 2) (shl s3-0 4)) (the-as int arg1)))))
)
(let ((f0-13 (atan
(-> (the-as (pointer float) (+ (+ (shl s3-0 2) (shl s2-0 4)) (the-as int arg1))))
(- (-> (the-as (pointer float) (+ (+ (shl s3-0 2) (shl s1-0 4)) (the-as int arg1)))))
)
)
)
(set! (-> arg0 data 2) f0-13)
)
)
(else
(set! (-> arg0 data 0)
(atan (- (-> (the-as (pointer float) (+ (+ (shl s1-0 2) (shl s2-0 4)) (the-as int arg1)))))
(-> (the-as (pointer float) (+ (+ (shl s2-0 2) (shl s2-0 4)) (the-as int arg1))))
)
)
(set! (-> arg0 data 1)
(atan
f30-0
(-> (the-as (pointer float) (+ (+ (shl s3-0 2) (shl s3-0 4)) (the-as int arg1))))
)
)
(let ((f0-20 0.0))
(set! (-> arg0 data 2) f0-20)
)
)
)
)
(let* ((f0-21 (-> (the-as (pointer float) (+ (+ (shl s3-0 2) (shl s3-0 4)) (the-as int arg1)))))
(f0-23 (* f0-21 f0-21))
(f1-3 (-> (the-as (pointer float) (+ (+ (shl s3-0 2) (shl s2-0 4)) (the-as int arg1)))))
(f30-1 (sqrtf (+ f0-23 (* f1-3 f1-3))))
)
(cond
((< 0.00001 f30-1)
(set! (-> arg0 data 0)
(atan
(-> (the-as (pointer float) (+ (+ (shl s2-0 2) (shl s1-0 4)) (the-as int arg1))))
(-> (the-as (pointer float) (+ (+ (shl s1-0 2) (shl s1-0 4)) (the-as int arg1))))
)
)
(set! (-> arg0 data 1)
(atan
(- (-> (the-as (pointer float) (+ (+ (shl s3-0 2) (shl s1-0 4)) (the-as int arg1)))))
f30-1
)
)
(let ((f0-34 (atan
(-> (the-as (pointer float) (+ (+ (shl s3-0 2) (shl s2-0 4)) (the-as int arg1))))
(-> (the-as (pointer float) (+ (+ (shl s3-0 2) (shl s3-0 4)) (the-as int arg1))))
)
)
)
(set! (-> arg0 data 2) f0-34)
)
)
(else
(set! (-> arg0 data 0)
(atan
(- (-> (the-as (pointer float) (+ (+ (shl s1-0 2) (shl s2-0 4)) (the-as int arg1)))))
(-> (the-as (pointer float) (+ (+ (shl s2-0 2) (shl s2-0 4)) (the-as int arg1))))
)
)
(set! (-> arg0 data 1)
(atan
(- (-> (the-as (pointer float) (+ (+ (shl s3-0 2) (shl s1-0 4)) (the-as int arg1)))))
f30-1
)
)
(let ((f0-42 0.0))
(set! (-> arg0 data 2) f0-42)
)
)
)
)
)
)
(when (= (logand (sar arg2 2) 1) 1)
(set! (-> arg0 data 0) (- (-> arg0 data 0)))
(set! (-> arg0 data 1) (- (-> arg0 data 1)))
(let ((f0-48 (- (-> arg0 data 2))))
(set! (-> arg0 data 2) f0-48)
)
)
(if (= (logand arg2 1) 1)
(let ((f0-49 (-> arg0 data 0)))
(set! (-> arg0 data 0) (-> arg0 data 2))
(set! (-> arg0 data 2) f0-49)
)
)
(set! (-> arg0 data 3) (the float arg2))
arg0
)
(defun eul->quat ((arg0 quaternion) (arg1 euler-angles))
"Convert euler angles to quaternion"
(let ((s5-0 (new 'stack-no-clear 'matrix)))
(eul->matrix s5-0 arg1)
(matrix->quaternion arg0 s5-0)
)
arg0
)
(defun quat->eul ((arg0 euler-angles) (arg1 quaternion) (arg2 int))
"Convert quaternion to euler angles. The last argument is euler flags"
(let ((s5-0 (new 'stack-no-clear 'matrix)))
(quaternion->matrix s5-0 arg1)
(matrix->eul arg0 s5-0 arg2)
)
arg0
)