diff --git a/decompiler/config/jak3/all-types.gc b/decompiler/config/jak3/all-types.gc index c2e71216cb..f0d8457885 100644 --- a/decompiler/config/jak3/all-types.gc +++ b/decompiler/config/jak3/all-types.gc @@ -132,18 +132,15 @@ ;; gcommon ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -#| (deftype vec4s (uint128) - ((UNKNOWN UNKNOWN :offset-assert -1) ;; field could not be read. - (UNKNOWN UNKNOWN :offset-assert -1) ;; field could not be read. - (UNKNOWN UNKNOWN :offset-assert -1) ;; field could not be read. - (UNKNOWN UNKNOWN :offset-assert -1) ;; field could not be read. - ) + ((x float :offset 0) + (y float :offset 32) + (z float :offset 64) + (w float :offset 96)) :method-count-assert 9 :size-assert #x10 :flag-assert #x900000010 ) -|# (deftype vector (structure) ((data float 4 :score -1 :offset-assert 0) ;; guessed by decompiler @@ -158,33 +155,33 @@ :flag-assert #x900000010 ) -#| (deftype bfloat (basic) - () + ((data float :offset-assert 4) + ) :method-count-assert 9 :size-assert #x8 :flag-assert #x900000008 - ;; Failed to read fields. ) -|# -#| (deftype inline-array-class (basic) - () + ((length int32 :offset-assert 4) + (allocated-length int32 :offset-assert 8) + ;; this is 16-byte aligned. + ;; children of inline-array-class should define their own data which overlays this one. + (_data uint8 :score -50 :dynamic :offset 16) + ) :method-count-assert 14 :size-assert #x10 :flag-assert #xe00000010 - ;; Failed to read fields. (:methods - ;; (new (symbol type int) _type_ 0) - (inline-array-class-method-9 () none) ;; 9 + (new (symbol type int) _type_) ;; 0 + (push-back (_type_ object) int);; 9 (inline-array-class-method-10 () none) ;; 10 - (inline-array-class-method-11 () none) ;; 11 - (inline-array-class-method-12 () none) ;; 12 - (inline-array-class-method-13 () none) ;; 13 + (clear-1 (_type_) symbol) ;; 11 + (clear-2 (_type_) none) ;; 12 + (pop-front (_type_ int) pointer) ;; 13 ) ) -|# #| (deftype inline-array-class-uint64 (inline-array-class) @@ -239,23 +236,23 @@ ;; (define-extern - function) ;; (function int int int) ;; (define-extern * function) ;; (function int int int) ;; (define-extern / function) ;; (function int int int) -;; (define-extern ash function) ;; (function int int int) -;; (define-extern mod function) ;; (function int int int) -;; (define-extern rem function) ;; (function int int int) -;; (define-extern abs function) ;; (function int int) -;; (define-extern min function) ;; (function int int int) -;; (define-extern max function) ;; (function int int int) -;; (define-extern logior function) ;; (function int int int) -;; (define-extern logand function) ;; (function int int int) -;; (define-extern lognor function) ;; (function int int int) -;; (define-extern logxor function) ;; (function int int int) -;; (define-extern lognot function) ;; (function int int) +(define-extern ash (function int int int)) +(define-extern mod (function int int int)) +(define-extern rem (function int int int)) +(define-extern abs (function int int)) +(define-extern min (function int int int)) +(define-extern max (function int int int)) +(define-extern logior (function int int int)) +(define-extern logand (function int int int)) +(define-extern lognor (function int int int)) +(define-extern logxor (function int int int)) +(define-extern lognot (function int int)) ;; (define-extern false-func function) ;; (function symbol) ;; (define-extern true-func function) ;; (function symbol) (define-extern format (function _varargs_ object)) ;; (define-extern basic-type? function) ;; (function basic type symbol) ;; (define-extern type-type? function) ;; (function type type symbol) -;; (define-extern type? function) ;; (function object type symbol) +(define-extern type? (function object type symbol)) ;; (define-extern find-parent-method function) ;; (function type int function) ;; (define-extern ref& function) ;; (define-extern ref function) ;; (function object int object) @@ -398,10 +395,9 @@ ) |# -;; (deftype time-frame (int64) -;; () -;; :flag-assert #x900000008 -;; ) +(deftype time-frame (int64) + () + ) (deftype clock (basic) ((index int16 :offset-assert 4) ;; int32 @@ -932,27 +928,22 @@ ;; math ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; (deftype float-type (uint32) -;; () -;; :flag-assert #x900000004 -;; ) +(deftype float-type (uint32) + () + ) -;; (deftype rgba (uint32) -;; () -;; :flag-assert #x900000004 -;; ) +(deftype rgba (uint32) + () + ) -;; (deftype xyzw (uint128) -;; () -;; :flag-assert #x900000010 -;; ) +(deftype xyzw (uint128) + () + ) -;; (deftype xyzwh (uint128) -;; () -;; :flag-assert #x900000010 -;; ) +(deftype xyzwh (uint128) + () + ) -#| (deftype random-generator (basic) ((seed uint32 :offset-assert 4) ) @@ -960,507 +951,505 @@ :size-assert #x8 :flag-assert #x900000008 ) -|# -;; (define-extern truncate function) ;; (function float float) -;; (define-extern round function) -;; (define-extern floor function) ;; (function float float) -;; (define-extern ceil function) ;; (function float float) -;; (define-extern integral? function) ;; (function float symbol) -;; (define-extern fractional-part function) ;; (function float float) -;; (define-extern odd? function) ;; (function int symbol) -;; (define-extern even? function) ;; (function int symbol) -;; (define-extern sawtooth-wave function) ;; (function float float) -;; (define-extern triangle-wave function) ;; (function float float) -;; (define-extern log-x-plus-1-order9 function) ;; (function float float) -;; (define-extern logf function) ;; (function float float) -;; (define-extern log2f function) ;; (function float float) -;; (define-extern exp-slead object) ;; (pointer float) -;; (define-extern exp-strail object) ;; (pointer float) -;; (define-extern exp function) ;; (function float float) -;; (define-extern pow function) ;; (function float float float) -;; (define-extern print-exp function) ;; (function float none) -;; (define-extern print-time function) ;; (function object time-frame none) -;; (define-extern log2 function) ;; (function int int) -;; (define-extern seek function) ;; (function float float float float) -;; (define-extern seek-ease function) ;; (function float float float float float float) -;; (define-extern seek-ease-in-out function) ;; (function float float float float float float float float) -;; (define-extern lerp function) ;; (function float float float float) -;; (define-extern lerp-scale-old function) ;; (function float float float float float float) -;; (define-extern lerp-scale function) ;; (function float float float float float float) -;; (define-extern lerp-scale-clamp function) -;; (define-extern lerp-clamp function) ;; (function float float float float) -;; (define-extern rgba-lerp function) ;; (function rgba rgba rgba rgba) -;; (define-extern seekl function) ;; (function int int int int) -;; (define-extern rand-vu-init function) ;; (function float float) -;; (define-extern rand-vu function) ;; (function float) -;; (define-extern rand-vu-nostep function) ;; (function float) -;; (define-extern rand-vu-float-range function) ;; (function float float float) -;; (define-extern rand-vu-percent? function) ;; (function float symbol) -;; (define-extern rand-vu-int-range function) ;; (function int int int) -;; (define-extern rand-vu-int-count function) ;; (function int int) -;; (define-extern rand-vu-int-count-excluding function) ;; (function int int int) -;; (define-extern rand-vu-int-range-exclude function) ;; (function int int int int) -;; (define-extern *random-generator* object) ;; random-generator -;; (define-extern rand-uint31-gen function) ;; (function random-generator uint) -;; (define-extern cube-root function) ;; (function float float) -;; (define-extern int-noise function) ;; (function int float) -;; (define-extern smooth-step function) ;; (function float float) -;; (define-extern smooth-interp function) ;; (function float float float float float float) +(define-extern truncate + "Round (toward zero) to an integer. + @param arg0 float to truncate" + (function float float)) +(define-extern round "Round to the nearest integer" (function float float)) +(define-extern floor "Round (down) to an integer" (function float float)) +(define-extern ceil "Round (up) to an integer" (function float float)) +(define-extern integral? "Is this number an integer?" (function float symbol)) +(define-extern fractional-part "Get the fractional part of a float." (function float float)) +(define-extern odd? "Is the number odd?" (function int symbol)) +(define-extern even? "Is the number even?" (function int symbol)) +(define-extern sawtooth-wave "Sample a sawtooth with period 1. In range (0, 1)" (function float float)) +(define-extern triangle-wave + "Sample a triangle wave. Period is 4, in range (-1, 1) (so slope is 1 or -1)." + (function float float)) +(define-extern log-x-plus-1-order9 + "Fast approximation of ln(x + 1). Probably only accurate for x in [0, 1]." + (function float float)) +(define-extern logf "Natural log." (function float float)) +(define-extern log2f "Log base 2." (function float float)) +(define-extern exp-slead (pointer float)) +(define-extern exp-strail (pointer float)) +(define-extern exp "Compute e^x." (function float float)) +(define-extern pow "Compute arg0^arg1" (function float float float)) +(define-extern print-exp "Print in the format AeB where A is in the range (1, 10)" (function float none)) +(define-extern print-time "Print a [[time-frame]] as h:mm:ss." (function object time-frame none)) +(define-extern log2 "Log base 2." (function int int)) +(define-extern seek "Move arg0 toward arg1 by at most arg2." (function float float float float)) +(define-extern seek-ease + "Move arg0 toward arg1, and slow down before reaching the end. + When farther than arg3 away, move by at most arg2. + When closer than arg3, linearly ramp down the movement amount from arg2 to 0 but no lower than arg4." + (function float float float float float float)) +(define-extern seek-ease-in-out + "Move arg0 toward arg2, and slow down at the start and end. + When within arg4 of arg1 (at the beginning of movement), ramp up speed, with a minimum speed of arg6 + When within arg5 of arg2 (at the end of movement), ramp down speed, with a minimum speed of arg5 + Normally, move at most arg3" + (function float float float float float float float float)) +(define-extern lerp "Linearly interpolate between arg0 and arg1." (function float float float float)) +(define-extern lerp-scale-old + "Linearly remap arg2 in [arg3, arg4] to [arg0, arg1]. + This is the jak 1 implementation, which I claimed was a bad implementation..." + (function float float float float float float)) +(define-extern lerp-scale + "Linearly remap arg2 in [arg3, arg4] to [arg0, arg1]. + More efficient than the -old version." + (function float float float float float float)) +(define-extern lerp-scale-clamp + "Clamp the input, then linearly remap arg2 in [arg3, arg4] to [arg0, arg1]." + (function float float float float float float)) +(define-extern lerp-clamp + "Linearly interpolate between arg0 and arg1. arg2 is clamped to [0, 1]" + (function float float float float)) +(define-extern rgba-lerp (function rgba rgba rgba rgba)) +(define-extern seekl "Move arg0 toward arg1, by at most arg2." (function int int int int)) +(define-extern rand-vu-init "Initialize the VU0 random generator." (function float float)) +(define-extern rand-vu "Get a random number in [0, 1) and advance the random generator." (function float)) +(define-extern rand-vu-nostep + "Get the number currently in the random generator. + This will be equal to the last call of (rand-vu). + This will not update the random generator." + (function float)) +(define-extern rand-vu-float-range "Get a random float in between arg0 and arg1." (function float float float)) +(define-extern rand-vu-percent? "Get a boolean that's true with the given probability (in 0, 1)." (function float symbol)) +(define-extern rand-vu-int-range "Get an integer in the given range (inclusive)." (function int int int)) +(define-extern rand-vu-int-count "Get an integer in the range [0, max)." (function int int)) +(define-extern rand-vu-int-count-excluding + "Get an integer in the range [0, arg0). + If bit n is set in arg1, exclude this value from being returned." + (function int int int)) +(define-extern rand-vu-int-range-exclude + "Get an integer in the range [0, arg0), excluding arg2. + Note that this doesn't use bits like rand-vu-int-count-excluding." + (function int int int int)) +(define-extern *random-generator* random-generator) +(define-extern rand-uint31-gen + "Generate a supposedly random integer. + Note, this might not quite be right. + But the highest bit is always zero, like it says + and it looks kinda random to me." + (function random-generator uint)) +(define-extern cube-root "Cube root with cool trick that I don't understand." (function float float)) +(define-extern int-noise "Generate random-ish floats in range -1, 1." (function int float)) +(define-extern smooth-step + "Interpolate between 0, 1 with a cubic polynomial. + These are picked so f(0) = 0, f(1) = 1, f'(0) = f'(1) = 0." + (function float float)) +(define-extern smooth-interp + "Remap arg2 from (arg3, arg4) to (arg0, arg1), using cubic interpolation. + Satisfies: + - f(arg3) = arg0 + - f(arg4) = arg1 + - f'(arg3) = f'(arg4) = 0" + (function float float float float float float)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; vector-h ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -#| (deftype bit-array (basic) ((length int32 :offset-assert 4) (allocated-length int32 :offset-assert 8) + (_pad uint8 :offset-assert 12) + (bytes uint8 :dynamic :offset 12) ) :method-count-assert 13 :size-assert #xd :flag-assert #xd0000000d (:methods - (new (symbol type) _type_) ;; 0 ;; (new (symbol type int) _type_) - (bit-array-method-9 () none) ;; 9 ;; (get-bit (_type_ int) symbol) - (bit-array-method-10 () none) ;; 10 ;; (clear-bit (_type_ int) int) - (bit-array-method-11 () none) ;; 11 ;; (set-bit (_type_ int) int) - (bit-array-method-12 () none) ;; 12 ;; (clear-all! (_type_) _type_) + (new "Allocate a new bit-array with room arg0 bits." (symbol type int) _type_) ;; 0 + (get-bit "Get the nth bit as a boolean." (_type_ int) symbol) ;; 9 + (clear-bit "Set the nth bit to 0." (_type_ int) int) ;; 10 + (set-bit "Set the nth bit to 1." (_type_ int) int) ;; 11 + (clear-all! "Set all bits to 0." (_type_) _type_) ;; 12 ) ) -|# -#| + (deftype vector16ub (structure) - ((data uint8 16 :offset-assert 0) ;; guessed by decompiler - (quad uint128 :offset-assert 0) + ((data uint8 16 :offset-assert 0) + (quad uint128 :offset 0) ) :method-count-assert 9 :size-assert #x10 :flag-assert #x900000010 ) -|# -#| (deftype vector4ub (structure) - ((data uint8 4 :offset-assert 0) ;; guessed by decompiler - (x uint8 :offset-assert 0) - (y uint8 :offset-assert 1) - (z uint8 :offset-assert 2) - (w uint8 :offset-assert 3) - (clr uint32 :offset-assert 0) + ((data uint8 4 :offset-assert 0) + (x uint8 :offset 0) + (y uint8 :offset 1) + (z uint8 :offset 2) + (w uint8 :offset 3) + (clr uint32 :offset 0) ) + :pack-me :method-count-assert 9 :size-assert #x4 :flag-assert #x900000004 ) -|# -#| (deftype vector4b (structure) - ((data int8 4 :offset-assert 0) ;; guessed by decompiler - (x int8 :offset-assert 0) - (y int8 :offset-assert 1) - (z int8 :offset-assert 2) - (w int8 :offset-assert 3) - (clr int32 :offset-assert 0) + ((data int8 4 :offset-assert 0) + (x int8 :offset 0) + (y int8 :offset 1) + (z int8 :offset 2) + (w int8 :offset 3) + (clr int32 :offset 0) ) + :pack-me :method-count-assert 9 :size-assert #x4 :flag-assert #x900000004 ) -|# -#| (deftype vector2ub (structure) - ((data uint8 2 :offset-assert 0) ;; guessed by decompiler - (x uint8 :offset-assert 0) - (y uint8 :offset-assert 1) - (clr uint16 :offset-assert 0) + ((data uint8 2 :offset-assert 0) + (x uint8 :offset 0) + (y uint8 :offset 1) + (clr uint16 :offset 0) ) + :pack-me :method-count-assert 9 :size-assert #x2 :flag-assert #x900000002 ) -|# -#| (deftype vector2b (structure) - ((data int8 2 :offset-assert 0) ;; guessed by decompiler - (x int8 :offset-assert 0) - (y int8 :offset-assert 1) - (clr int16 :offset-assert 0) + ((data int8 2 :offset-assert 0) + (x int8 :offset 0) + (y int8 :offset 1) + (clr int16 :offset 0) ) :method-count-assert 9 :size-assert #x2 :flag-assert #x900000002 ) -|# -#| (deftype vector2h (structure) - ((data int16 2 :offset-assert 0) ;; guessed by decompiler - (x int16 :offset-assert 0) - (y int16 :offset-assert 2) + ((data int16 2 :offset-assert 0) + (x int16 :offset 0) + (y int16 :offset 2) ) + :pack-me :method-count-assert 9 :size-assert #x4 :flag-assert #x900000004 ) -|# -#| (deftype vector2uh (structure) - ((data uint16 2 :offset-assert 0) ;; guessed by decompiler - (x uint16 :offset-assert 0) - (y uint16 :offset-assert 2) - (val uint32 :offset-assert 0) + ((data uint16 2 :offset-assert 0) + (x uint16 :offset 0) + (y uint16 :offset 2) + (val uint32 :offset 0) ) + :pack-me :method-count-assert 9 :size-assert #x4 :flag-assert #x900000004 ) -|# -#| (deftype vector3h (structure) - ((data int16 3 :offset-assert 0) ;; guessed by decompiler - (x int16 :offset-assert 0) - (y int16 :offset-assert 2) - (z int16 :offset-assert 4) + ((data int16 3 :offset-assert 0) + (x int16 :offset 0) + (y int16 :offset 2) + (z int16 :offset 4) ) :method-count-assert 9 :size-assert #x6 :flag-assert #x900000006 ) -|# -#| (deftype vector3uh (structure) - ((data uint16 3 :offset-assert 0) ;; guessed by decompiler - (x uint16 :offset-assert 0) - (y uint16 :offset-assert 2) - (z uint16 :offset-assert 4) + ((data uint16 3 :offset-assert 0) + (x uint16 :offset 0) + (y uint16 :offset 2) + (z uint16 :offset 4) ) :method-count-assert 9 :size-assert #x6 :flag-assert #x900000006 ) -|# -#| (deftype vector2w (structure) - ((data int32 2 :offset-assert 0) ;; guessed by decompiler - (x int32 :offset-assert 0) - (y int32 :offset-assert 4) + ((data int32 2 :offset-assert 0) + (x int32 :offset 0) + (y int32 :offset 4) ) :method-count-assert 9 :size-assert #x8 :flag-assert #x900000008 ) -|# -#| (deftype vector3w (structure) - ((data int32 3 :offset-assert 0) ;; guessed by decompiler - (x int32 :offset-assert 0) - (y int32 :offset-assert 4) - (z int32 :offset-assert 8) + ((data int32 3 :offset-assert 0) + (x int32 :offset 0) + (y int32 :offset 4) + (z int32 :offset 8) ) :method-count-assert 9 :size-assert #xc :flag-assert #x90000000c ) -|# -#| (deftype vector4w (structure) - ((data int32 4 :offset-assert 0) ;; guessed by decompiler - (x int32 :offset-assert 0) - (y int32 :offset-assert 4) - (z int32 :offset-assert 8) - (w int32 :offset-assert 12) - (dword uint64 2 :offset-assert 0) ;; guessed by decompiler - (quad uint128 :offset-assert 0) + ((data int32 4 :offset-assert 0 :score -1) + (x int32 :offset 0) + (y int32 :offset 4) + (z int32 :offset 8) + (w int32 :offset 12) + (dword uint64 2 :offset 0) + (quad uint128 :offset 0) ) :method-count-assert 9 :size-assert #x10 :flag-assert #x900000010 ) -|# -#| (deftype vector2 (structure) - ((data float 2 :offset-assert 0) ;; guessed by decompiler - (x float :offset-assert 0) - (y float :offset-assert 4) + ((data float 2 :offset-assert 0) + (x float :offset 0) + (y float :offset 4) ) + :allow-misaligned :method-count-assert 9 :size-assert #x8 :flag-assert #x900000008 ) -|# -#| (deftype vector3 (structure) - ((data float 3 :offset-assert 0) ;; guessed by decompiler - (x float :offset-assert 0) - (y float :offset-assert 4) - (z float :offset-assert 8) + ((data float 3 :offset-assert 0) + (x float :offset 0) + (y float :offset 4) + (z float :offset 8) ) :method-count-assert 9 :size-assert #xc :flag-assert #x90000000c ) -|# -#| (deftype vector4 (structure) - ((data float 4 :offset-assert 0) ;; guessed by decompiler - (x float :offset-assert 0) - (y float :offset-assert 4) - (z float :offset-assert 8) - (w float :offset-assert 12) - (dword uint64 2 :offset-assert 0) ;; guessed by decompiler - (quad uint128 :offset-assert 0) + ((data float 4 :offset-assert 0 :score -1) + (x float :offset 0) + (y float :offset 4) + (z float :offset 8) + (w float :offset 12) + (dword uint64 2 :offset 0) + (quad uint128 :offset 0) ) :method-count-assert 9 :size-assert #x10 :flag-assert #x900000010 ) -|# -#| (deftype vector4w-2 (structure) - ((data int32 8 :offset-assert 0) ;; guessed by decompiler - (quad uint128 2 :offset-assert 0) ;; guessed by decompiler - (vector vector4w 2 :offset-assert 0) ;; guessed by decompiler + ((data int32 8 :offset-assert 0 :score -2) + (quad uint128 2 :offset 0 :score -1) + (vector vector4w 2 :inline :offset 0) ) :method-count-assert 9 :size-assert #x20 :flag-assert #x900000020 ) -|# -#| (deftype vector4w-3 (structure) - ((data int32 12 :offset-assert 0) ;; guessed by decompiler - (quad uint128 3 :offset-assert 0) ;; guessed by decompiler - (vector vector4w 3 :offset-assert 0) ;; guessed by decompiler + ((data int32 12 :offset-assert 0 :score -2) + (quad uint128 3 :offset 0 :score -1) + (vector vector4w 3 :inline :offset 0) ) :method-count-assert 9 :size-assert #x30 :flag-assert #x900000030 ) -|# -#| (deftype vector4w-4 (structure) - ((data int32 16 :offset-assert 0) ;; guessed by decompiler - (quad uint128 4 :offset-assert 0) ;; guessed by decompiler - (vector vector4w 4 :offset-assert 0) ;; guessed by decompiler + ((data int32 16 :offset-assert 0) + (quad uint128 4 :offset 0) + (vector vector4w 4 :inline :offset 0 :score 999) ) :method-count-assert 9 :size-assert #x40 :flag-assert #x900000040 ) -|# -#| (deftype vector4h (structure) - ((data int16 4 :offset-assert 0) ;; guessed by decompiler - (x int16 :offset-assert 0) - (y int16 :offset-assert 2) - (z int16 :offset-assert 4) - (w int16 :offset-assert 6) - (long uint64 :offset-assert 0) + ((data int16 4 :offset-assert 0) + (x int16 :offset 0) + (y int16 :offset 2) + (z int16 :offset 4) + (w int16 :offset 6) + (long uint64 :offset 0) ) + :pack-me :method-count-assert 9 :size-assert #x8 :flag-assert #x900000008 ) -|# -#| (deftype vector8h (structure) - ((data int16 8 :offset-assert 0) ;; guessed by decompiler - (quad uint128 :offset-assert 0) + ((data int16 8 :offset-assert 0) + (quad uint128 :offset 0) ) :method-count-assert 9 :size-assert #x10 :flag-assert #x900000010 ) -|# -#| (deftype vector16b (structure) - ((data int8 16 :offset-assert 0) ;; guessed by decompiler - (quad uint128 :offset-assert 0) + ((data int8 16 :offset-assert 0) + (quad uint128 :offset 0) ) :method-count-assert 9 :size-assert #x10 :flag-assert #x900000010 ) -|# -#| (deftype vector4s-3 (structure) - ((data float 12 :offset-assert 0) ;; guessed by decompiler - (quad uint128 3 :offset-assert 0) ;; guessed by decompiler - (vector vector 3 :offset-assert 0) ;; guessed by decompiler + ((data float 12 :offset-assert 0) + (quad uint128 3 :offset 0) + (vector vector 3 :inline :offset 0) ) :method-count-assert 9 :size-assert #x30 :flag-assert #x900000030 ) -|# -#| (deftype vector-array (inline-array-class) - ((data vector :dynamic :offset-assert 16) ;; guessed by decompiler + ((data vector :inline :dynamic :offset-assert 16 :score 10) ) :method-count-assert 14 :size-assert #x10 :flag-assert #xe00000010 ) -|# -#| (deftype rgbaf (vector) - ((r float :offset-assert 0) - (g float :offset-assert 4) - (b float :offset-assert 8) - (a float :offset-assert 12) + ((r float :offset 0) + (g float :offset 4) + (b float :offset 8) + (a float :offset 12) ) :method-count-assert 9 :size-assert #x10 :flag-assert #x900000010 ) -|# -#| (deftype plane (vector) - ((a float :offset-assert 0) - (b float :offset-assert 4) - (c float :offset-assert 8) - (d float :offset-assert 12) + ((a float :offset 0) + (b float :offset 4) + (c float :offset 8) + (d float :offset 12) ) :method-count-assert 9 :size-assert #x10 :flag-assert #x900000010 ) -|# -#| (deftype sphere (vector) - ((r float :offset-assert 12) + ((r float :offset 12 :score 1) ) :method-count-assert 9 :size-assert #x10 :flag-assert #x900000010 ) -|# -;; (deftype isphere (vec4s) -;; () -;; :flag-assert #x900000010 -;; ) +(deftype isphere (vec4s) + () + ) -#| (deftype box8s (structure) - ((data float 8 :offset-assert 0) ;; guessed by decompiler - (quad uint128 2 :offset-assert 0) ;; guessed by decompiler - (vector vector 2 :offset-assert 0) ;; guessed by decompiler - (min vector :inline :offset-assert 0) - (max vector :inline :offset-assert 16) + ((data float 8 :offset-assert 0) + (quad uint128 2 :offset 0) + (vector vector 2 :offset 0) + (min vector :inline :offset 0) + (max vector :inline :offset 16) ) :method-count-assert 9 :size-assert #x20 :flag-assert #x900000020 ) -|# -#| (deftype box8s-array (inline-array-class) - ((data box8s :dynamic :offset-assert 16) ;; guessed by decompiler + ((data box8s :inline :dynamic :offset-assert 16) ) :method-count-assert 14 :size-assert #x10 :flag-assert #xe00000010 ) -|# -#| (deftype vertical-planes (structure) - ((data uint128 4 :offset-assert 0) ;; guessed by decompiler + ((data uint128 4 :offset-assert 0) ) :method-count-assert 9 :size-assert #x40 :flag-assert #x900000040 ) -|# -#| (deftype vertical-planes-array (basic) - ((length uint32 :offset-assert 4) - (data vertical-planes :dynamic :offset-assert 16) ;; guessed by decompiler + ((length uint32 :offset-assert 4) + (data vertical-planes :inline :dynamic :offset-assert 16) ) :method-count-assert 9 :size-assert #x10 :flag-assert #x900000010 ) -|# -#| (deftype qword (structure) - ((data uint32 4 :offset-assert 0) ;; guessed by decompiler - (byte uint8 16 :offset-assert 0) ;; guessed by decompiler - (hword uint16 8 :offset-assert 0) ;; guessed by decompiler - (word uint32 4 :offset-assert 0) ;; guessed by decompiler - (dword uint64 2 :offset-assert 0) ;; guessed by decompiler - (quad uint128 :offset-assert 0) - (vector vector :inline :offset-assert 0) - (vector4w vector4w :inline :offset-assert 0) + ((data uint32 4 :offset-assert 0) + (byte uint8 16 :offset 0) + (hword uint16 8 :offset 0) + (word uint32 4 :offset 0) + (dword uint64 2 :offset 0) + (quad uint128 :offset 0) + (vector vector :inline :offset 0 :score -100) + (vector4w vector4w :inline :offset 0) ) :method-count-assert 9 :size-assert #x10 :flag-assert #x900000010 ) -|# -#| (deftype vector3s (structure) - ((data float 3 :offset-assert 0) ;; guessed by decompiler - (x float :offset-assert 0) - (y float :offset-assert 4) - (z float :offset-assert 8) + ((data float 3 :offset-assert 0) + (x float :offset 0) + (y float :offset 4) + (z float :offset 8) ) + :pack-me :method-count-assert 9 :size-assert #xc :flag-assert #x90000000c ) -|# -;; vector is already defined! - -;; (define-extern *null-vector* object) ;; vector -;; (define-extern *identity-vector* object) ;; vector -;; (define-extern *x-vector* object) ;; vector -;; (define-extern *y-vector* object) ;; vector -;; (define-extern *z-vector* object) ;; vector -;; (define-extern *up-vector* object) ;; vector -;; (define-extern vector-dot function) ;; (function vector vector float) -;; (define-extern vector-dot-vu function) ;; (function vector vector float) -;; (define-extern vector4-dot function) ;; (function vector vector float) -;; (define-extern vector4-dot-vu function) ;; (function vector vector float) -;; (define-extern vector+! function) ;; (function vector vector vector vector) -;; (define-extern vector-! function) ;; (function vector vector vector vector) -;; (define-extern vector-zero! function) ;; (function vector vector) -;; (define-extern vector-reset! function) ;; (function vector vector) -;; (define-extern vector-copy! function) ;; (function vector vector vector) -;; (define-extern vector-length< function) ;; (function vector float symbol) -;; (define-extern vector-length> function) ;; (function vector float symbol) -;; (define-extern *zero-vector* object) ;; vector +(define-extern *null-vector* vector) +(define-extern *identity-vector* vector) +(define-extern *x-vector* vector) +(define-extern *y-vector* vector) +(define-extern *z-vector* vector) +(define-extern *up-vector* vector) +(define-extern vector-dot + "Take the dot product of two vectors. + Only does the x, y, z compoments. + Originally handwritten assembly to space out loads and use FPU accumulator" + (function vector vector float)) +(define-extern vector-dot-vu "Take the dot product (xyz only). Using VU0." (function vector vector float)) +(define-extern vector4-dot + "Take the dot product of two vectors. + Does the x, y, z, and w compoments" + (function vector vector float)) +(define-extern vector4-dot-vu "Take the dot product (xyzw). Using VU0." (function vector vector float)) +(define-extern vector+! "Set dst = a + b. The w component of dst is set to 0." (function vector vector vector vector)) +(define-extern vector-! "Set dst = a - b. The w componenent of dst is set to 0." (function vector vector vector vector)) +(define-extern vector-zero! "Set xyzw to 0." (function vector vector)) +(define-extern vector-reset! "Set vector to <0,0,0,1>." (function vector vector)) +(define-extern vector-copy! "Copy arg1 to arg0." (function vector vector vector)) +(define-extern vector-length< (function vector float symbol)) +(define-extern vector-length> (function vector float symbol)) +(define-extern *zero-vector* vector) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; gravity-h ;; @@ -1471,7 +1460,6 @@ ;; bounding-box-h ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -#| (deftype bounding-box (structure) ((min vector :inline :offset-assert 0) (max vector :inline :offset-assert 16) @@ -1480,23 +1468,27 @@ :size-assert #x20 :flag-assert #x1500000020 (:methods - (bounding-box-method-9 () none) ;; 9 ;; (add-spheres! (_type_ (inline-array sphere) int) int) - (bounding-box-method-10 () none) ;; 10 ;; (add-box! (_type_ bounding-box) int) - (bounding-box-method-11 () none) ;; 11 ;; (add-point! (_type_ vector) none) - (bounding-box-method-12 () none) ;; 12 ;; (intersects-line-segment? (_type_ vector vector) symbol) - (bounding-box-method-13 () none) ;; 13 ;; (set-from-point-offset! (_type_ vector vector) none) - (bounding-box-method-14 () none) ;; 14 ;; (set-from-point-offset-pad! (_type_ vector vector float) int) - (bounding-box-method-15 () none) ;; 15 ;; (set-to-point! (_type_ vector) none) - (bounding-box-method-16 () none) ;; 16 ;; (set-from-sphere! (_type_ sphere) none) - (bounding-box-method-17 () none) ;; 17 ;; (set-from-spheres! (_type_ (inline-array sphere) int) int) - (bounding-box-method-18 () none) ;; 18 ;; (get-bounding-sphere (_type_ vector) vector) - (bounding-box-method-19 () none) ;; 19 ;; (inside-xyz? (bounding-box vector) symbol) - (bounding-box-method-20 () none) ;; 20 ;; (inside-xz? (bounding-box vector) symbol) + (add-spheres! "Add count spheres." (_type_ (inline-array sphere) int) int) ;; 9 + (add-box! "Expand the box as needed to contain the given box." (_type_ bounding-box) int) ;; 10 + (add-point! "Expand the box as needed to contain the given point." (_type_ vector) none) ;; 11 + (intersects-line-segment? + "Check intersection in xz plane, using liang-barsky. Not sure if this actually + a useful check or not..." + (_type_ vector vector) symbol) ;; 12 + (set-from-point-offset! "Set to the smallest box containing arg0, (arg0 + arg1)" (_type_ vector vector) none) ;; 13 + (set-from-point-offset-pad! "Set the box to contain arg0, arg0 + offset, with some padding." (_type_ vector vector float) int) ;; 14 + (set-to-point! "Set the box to be a single point." (_type_ vector) none) ;; 15 + (set-from-sphere! "Set the box to contain a single sphere." (_type_ sphere) none) ;; 16 + (set-from-spheres! + "Reset box to hold the given spheres. + Note: this implementation could be optimized." + (_type_ (inline-array sphere) int) int) ;; 17 + (get-bounding-sphere "Get a bounding sphere for a bounding box." (_type_ vector) vector) ;; 18 + (inside-xyz? "Is the point in the box?" (bounding-box vector) symbol) ;; 19 + (inside-xz? "Is the point in the box? Check xz only." (bounding-box vector) symbol) ;; 20 ) ) -|# -#| (deftype bounding-box2 (structure) ((min vector2 :inline :offset-assert 0) (max vector2 :inline :offset-assert 8) @@ -1505,9 +1497,7 @@ :size-assert #x10 :flag-assert #x900000010 ) -|# -#| (deftype bounding-box4w (structure) ((min vector4w :inline :offset-assert 0) (max vector4w :inline :offset-assert 16) @@ -1516,9 +1506,7 @@ :size-assert #x20 :flag-assert #x900000020 ) -|# -#| (deftype bounding-box-both (structure) ((box bounding-box :inline :offset-assert 0) (box4w bounding-box4w :inline :offset-assert 32) @@ -1527,9 +1515,7 @@ :size-assert #x40 :flag-assert #x900000040 ) -|# -#| (deftype bounding-box-array (inline-array-class) ((data bounding-box :dynamic :offset-assert 16) ;; guessed by decompiler ) @@ -1537,105 +1523,118 @@ :size-assert #x10 :flag-assert #xe00000010 ) -|# - ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; matrix-h ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -#| (deftype matrix (structure) - ((data float 16 :offset-assert 0) ;; guessed by decompiler - (vector vector 4 :offset-assert 0) ;; guessed by decompiler - (quad uint128 4 :offset-assert 0) ;; guessed by decompiler - (rvec vector :inline :offset-assert 0) - (uvec vector :inline :offset-assert 16) - (fvec vector :inline :offset-assert 32) - (trans vector :inline :offset-assert 48) + "A 4x4 matrix, stored in row-major order. + some, but not all, functions assume that a matrix is an affine transform. + others assume that the rotation has no scale or shear (and that its inverse is its transpose)." + ((data float 16 :offset-assert 0 :score -2) ;; guessed by decompiler + (vector vector 4 :offset 0 :score -1) ;; guessed by decompiler + (quad uint128 4 :offset 0) ;; guessed by decompiler + (rvec vector :inline :offset 0 :score 1) + (uvec vector :inline :offset 16 :score 1) + (fvec vector :inline :offset 32 :score 1) + (trans vector :inline :offset 48 :score 1) ) :method-count-assert 10 :size-assert #x40 :flag-assert #xa00000040 (:methods - (matrix-method-9 () none) ;; 9 ;; (transform-vectors! (_type_ (inline-array vector) (inline-array vector) int) none) + (transform-vectors! + "Transform many vectors. This acts like w = 1, even if it isn't. The value of w is copied." + (_type_ (inline-array vector) (inline-array vector) int) none) ;; 9 ) ) -|# -#| (deftype matrix3 (structure) - ((data float 12 :offset-assert 0) ;; guessed by decompiler - (vector vector 3 :offset-assert 0) ;; guessed by decompiler - (quad uint128 3 :offset-assert 0) ;; guessed by decompiler + "A 3x3 matrix, stored in row-major order. + NOTE: the rows each have an extra 4-bytes of padding, + so this is really a 3x4 matrix. + This type is rarely used." + ((data float 12 :offset-assert 0 :score -1) ;; guessed by decompiler + (vector vector 3 :inline :offset 0) ;; guessed by decompiler + (quad uint128 3 :offset 0) ;; guessed by decompiler ) :method-count-assert 9 :size-assert #x30 :flag-assert #x900000030 ) -|# -#| (deftype matrix4h (structure) - ((data int16 16 :offset-assert 0) ;; guessed by decompiler - (vector4h vector4h 4 :offset-assert 0) ;; guessed by decompiler - (long int64 4 :offset-assert 0) ;; guessed by decompiler + "A matrix stored using 16-bit integers. + Note that these usually have different scaling for the 4th row which + contains the translation in an affine transform. + So you generally should not unpack these to floats without knowing where they came from + and how they were originally packed (for example, in tie/shrub)." + ((data int16 16 :offset-assert 0 :score -1) ;; guessed by decompiler + (vector4h vector4h 4 :offset 0) ;; guessed by decompiler + (long int64 4 :offset 0) ;; guessed by decompiler ) :method-count-assert 9 :size-assert #x20 :flag-assert #x900000020 ) -|# -;; (define-extern matrix-copy! function) ;; (function matrix matrix matrix) -;; (define-extern matrix<-vector-yz-exact! function) -;; (define-extern matrix<-vector-yz! function) -;; (define-extern matrix<-vector-z! function) +(define-extern matrix-copy! "Copy arg1 to arg0" (function matrix matrix matrix)) +(define-extern matrix<-vector-yz-exact! (function matrix vector vector matrix)) +(define-extern matrix<-vector-yz! (function matrix vector vector matrix)) +(define-extern matrix<-vector-z! (function matrix vector matrix)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; quaternion-h ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -#| (deftype quaternion (structure) - ((data float 4 :offset-assert 0) ;; guessed by decompiler - (x float :offset-assert 0) - (y float :offset-assert 4) - (z float :offset-assert 8) - (w float :offset-assert 12) - (vec vector :inline :offset-assert 0) - (quad uint128 :offset-assert 0) + "Quaternion. Stored in xyzw order." + ((data float 4 :offset-assert 0 :score -1) ;; guessed by decompiler + (x float :offset 0) + (y float :offset 4) + (z float :offset 8) + (w float :offset 12) + (vec vector :inline :offset 0) + (quad uint128 :offset 0) ) :method-count-assert 9 :size-assert #x10 :flag-assert #x900000010 ) -|# -;; (define-extern *unity-quaternion* object) ;; quaternion +(define-extern *unity-quaternion* quaternion) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; euler-h ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -#| (deftype euler-angles (vector) + "Just uses the same xyzw and data array as vector. + The `w` stores an integer that seems to have + bitfields for... something? Like maybe the order? + Euler angles are mostly unused, and the code is a bit of disaster." () :method-count-assert 9 :size-assert #x10 :flag-assert #x900000010 ) -|# -;; (define-extern EulSafe array) ;; (array int32) -;; (define-extern EulNext array) ;; (array int32) +(define-extern EulSafe + "Maybe euler angle storage orders? + What is this naming convention?" + (array int32)) +(define-extern EulNext (array int32)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; transform-h ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -#| (deftype transform (structure) + "Transformation. w components of vectors should be 1.0 + This can represent any rotation, translation, and scaling. + Note that the scaling is applied before rotation + (meaning it scales along the axes of the pre-transformed frame)." ((trans vector :inline :offset-assert 0) (rot vector :inline :offset-assert 16) (scale vector :inline :offset-assert 32) @@ -1644,26 +1643,27 @@ :size-assert #x30 :flag-assert #x900000030 ) -|# -#| (deftype trs (basic) + "Like transform, but it's a basic. + Note that the trsq child type overrides this rotation with a quaternion. + usage of the plain trs is very limited, at least in Jak 1." ((trans vector :inline :offset-assert 16) (rot vector :inline :offset-assert 32) (scale vector :inline :offset-assert 48) ) + (:methods + (new (symbol type) _type_) ;; 0 + ) :method-count-assert 9 :size-assert #x40 :flag-assert #x900000040 ) -|# - ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; geometry-h ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -#| (deftype curve (structure) ((cverts (inline-array vector) :offset-assert 0) ;; guessed by decompiler (num-cverts int32 :offset-assert 4) @@ -1675,9 +1675,7 @@ :size-assert #x14 :flag-assert #x900000014 ) -|# -#| (deftype line-intersection-val (structure) ((tt0 float :offset-assert 0) (tt1 float :offset-assert 4) @@ -1686,9 +1684,7 @@ :size-assert #x8 :flag-assert #x900000008 ) -|# -#| (deftype border-plane (basic) ((name symbol :offset-assert 4) ;; guessed by decompiler (action basic :offset-assert 8) @@ -1700,13 +1696,11 @@ :size-assert #x30 :flag-assert #xb00000030 (:methods - (border-plane-method-9 () none) ;; 9 ;; (debug-draw (_type_) int) - (border-plane-method-10 () none) ;; 10 ;; (point-past-plane? (_type_ vector) symbol) + (debug-draw (_type_) int) ;; 9 + (point-past-plane? (_type_ vector) symbol) ;; 10 ) ) -|# -#| (deftype lissajous (structure) ((x-mag float :offset-assert 0) (y-mag float :offset-assert 4) @@ -1716,16 +1710,15 @@ (period-shift float :offset-assert 20) (theta-rate float :offset-assert 24) ) + :pack-me :method-count-assert 10 :size-assert #x1c :flag-assert #xa0000001c (:methods - (lissajous-method-9 () none) ;; 9 + (lissajous-method-9 (_type_ vector) vector) ;; 9 ) ) -|# -#| (deftype lissajous-interp (structure) ((current lissajous :inline :offset-assert 0) (dest lissajous :inline :offset-assert 28) @@ -1735,12 +1728,10 @@ :size-assert #x54 :flag-assert #xb00000054 (:methods - (lissajous-interp-method-9 () none) ;; 9 - (lissajous-interp-method-10 () none) ;; 10 + (lissajous-interp-method-9 (_type_ vector) vector) ;; 9 + (lissajous-interp-method-10 (_type_) float) ;; 10 ) ) -|# - ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; trigonometry-h ;; @@ -1751,70 +1742,78 @@ ;; transformq-h ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -#| (deftype transformq (transform) - ((quat quaternion :inline :offset-assert 16) + ((quat quaternion :inline :offset 16) ) :method-count-assert 9 :size-assert #x30 :flag-assert #x900000030 ) -|# -#| (deftype trsq (trs) - ((quat quaternion :inline :offset-assert 32) + ((quat quaternion :inline :offset 32) ) :method-count-assert 9 :size-assert #x40 :flag-assert #x900000040 ) -|# -#| (deftype trsqv (trsq) - ((pause-adjust-distance meters :offset-assert 4) - (nav-radius meters :offset-assert 8) + "A transform with: + - type information (child of [[basic]]) + - rotation stored as quaternion + - velocity information. + This is a very commonly used type to represent the position of an in-game object. + The `root` of a process-drawable (the parent 'in-game object' type) is a [[trsqv]]. + Additionally, the collision system uses [[trsqv]] as the parent type for foreground + collision objects ([[collide-shape]], [[collide-shape-moving]]). + As a result, this type has a lot of weird methods and extra stuff hidden in it." + ((pause-adjust-distance meters :offset 4) + (nav-radius meters :offset 8) (transv vector :inline :offset-assert 64) (rotv vector :inline :offset-assert 80) (scalev vector :inline :offset-assert 96) (dir-targ quaternion :inline :offset-assert 112) - (angle-change-time uint64 :offset-assert 128) ;; time-frame + (angle-change-time time-frame :offset-assert 128) (old-y-angle-diff float :offset-assert 136) ) :method-count-assert 28 :size-assert #x8c :flag-assert #x1c0000008c (:methods - (trsqv-method-9 () none) ;; 9 ;; (seek-toward-heading-vec! (_type_ vector float time-frame) quaternion) - (trsqv-method-10 () none) ;; 10 ;; (set-heading-vec! (_type_ vector) quaternion) - (trsqv-method-11 () none) ;; 11 ;; (seek-to-point-toward-point! (_type_ vector float time-frame) quaternion) - (trsqv-method-12 () none) ;; 12 ;; (point-toward-point! (_type_ vector) quaternion) - (trsqv-method-13 () none) ;; 13 ;; (seek-toward-yaw-angle! (_type_ float float time-frame) quaternion) - (trsqv-method-14 () none) ;; 14 ;; (set-yaw-angle-clear-roll-pitch! (_type_ float) quaternion) - (trsqv-method-15 () none) ;; 15 ;; (set-roll-to-grav! (_type_ float) quaternion) - (trsqv-method-16 () none) ;; 16 ;; (set-roll-to-grav-2! (_type_ float) quaternion) - (trsqv-method-17 () none) ;; 17 ;; (rotate-toward-orientation! (_type_ quaternion float float int int float) quaternion) - (trsqv-method-18 () none) ;; 18 ;; (set-quaternion! (_type_ quaternion) quaternion) - (trsqv-method-19 () none) ;; 19 ;; (set-heading-vec-clear-roll-pitch! (_type_ vector) quaternion) - (trsqv-method-20 () none) ;; 20 ;; (point-toward-point-clear-roll-pitch! (_type_ vector) quaternion) - (trsqv-method-21 () none) ;; 21 ;; (rot->dir-targ! (_type_) quaternion) - (trsqv-method-22 () none) ;; 22 ;; (y-angle (_type_) float) - (trsqv-method-23 () none) ;; 23 ;; (global-y-angle-to-point (_type_ vector) float) - (trsqv-method-24 () none) ;; 24 ;; (relative-y-angle-to-point (_type_ vector) float) - (trsqv-method-25 () none) ;; 25 ;; (roll-relative-to-gravity (_type_) float) - (trsqv-method-26 () none) ;; 26 ;; (set-and-limit-velocity (_type_ int vector float) trsqv) - (trsqv-method-27 () none) ;; 27 ;; (get-quaternion (_type_) quaternion) + (seek-toward-heading-vec! (_type_ vector float time-frame) quaternion) ;; 9 + (set-heading-vec! (_type_ vector) quaternion) ;; 10 + (seek-to-point-toward-point! (_type_ vector float time-frame) quaternion) ;; 11 + (point-toward-point! (_type_ vector) quaternion) ;; 12 + (seek-toward-yaw-angle! (_type_ float float time-frame) quaternion) ;; 13 + (set-yaw-angle-clear-roll-pitch! (_type_ float) quaternion) ;; 14 + (set-roll-to-grav! (_type_ float) quaternion) ;; 15 + (set-roll-to-grav-2! (_type_ float) quaternion) ;; 16 + (rotate-toward-orientation! (_type_ quaternion float float int int float) quaternion) ;; 17 + (set-quaternion! (_type_ quaternion) quaternion) ;; 18 + (set-heading-vec-clear-roll-pitch! (_type_ vector) quaternion) ;; 19 + (point-toward-point-clear-roll-pitch! (_type_ vector) quaternion) ;; 20 + (rot->dir-targ! (_type_) quaternion) ;; 21 + (y-angle (_type_) float) ;; 22 + (global-y-angle-to-point + "Get the angle in the xz plane from the position of this trsqv to the point arg0 + (ignores our current yaw)." + (_type_ vector) float) ;; 23 + (relative-y-angle-to-point + "Get the y angle between the current orientation and arg0 + (how much we'd have to yaw to point at arg0)." + (_type_ vector) float) ;; 24 + (roll-relative-to-gravity (_type_) float) ;; 25 + (set-and-limit-velocity (_type_ int vector float) trsqv) ;; 26 + (get-quaternion (_type_) quaternion) ;; 27 ) ) -|# ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; bounding-box ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -#| (deftype liang-barsky-line-clip-params (structure) ((te float :offset-assert 0) (tl float :offset-assert 4) @@ -1823,99 +1822,178 @@ :size-assert #x8 :flag-assert #x900000008 ) -|# -;; (define-extern box-vector-enside? function) ;; (function bounding-box vector symbol) -;; (define-extern box-vector-inside? function) ;; (function bounding-box vector symbol) -;; (define-extern liang-barsky-line-clipt function) ;; (function liang-barsky-line-clip-params float float symbol) +(define-extern box-vector-enside? "Is the point in the box? On the edge doesn't count." (function bounding-box vector symbol)) +(define-extern box-vector-inside? "Is the point in the box? On the edge counts." (function bounding-box vector symbol)) +(define-extern liang-barsky-line-clipt "Clip test in 1 dimension. Is arg1 in arg2?" (function liang-barsky-line-clip-params float float symbol)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; matrix ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; matrix is already defined! - -;; matrix3 is already defined! - -;; (define-extern matrix-identity! function) ;; (function matrix matrix) -;; (define-extern *identity-matrix* object) ;; matrix -;; (define-extern *hermite-matrix* object) ;; matrix -;; (define-extern matrix+! function) ;; (function matrix matrix matrix matrix) -;; (define-extern matrix-! function) ;; (function matrix matrix matrix matrix) -;; (define-extern matrix*! function) ;; (function matrix matrix matrix matrix) -;; (define-extern matrixp*! function) ;; (function matrix matrix matrix matrix) -;; (define-extern vector-matrix*! function) ;; (function vector vector matrix vector) -;; (define-extern vector-norm-matrix*! function) -;; (define-extern vector-rotate*! function) ;; (function vector vector matrix vector) -;; (define-extern vector3s-matrix*! function) ;; (function vector3s vector3s matrix vector3s) -;; (define-extern vector3s-rotate*! function) ;; (function vector3s vector3s matrix vector3s) -;; (define-extern matrix-transpose! function) ;; (function matrix matrix matrix) -;; (define-extern matrix-inverse-of-rot-trans! function) ;; (function matrix matrix matrix) -;; (define-extern matrix-4x4-inverse! function) ;; (function matrix matrix matrix) -;; (define-extern matrix-translate! function) ;; (function matrix vector matrix) -;; (define-extern matrix-translate+! function) ;; (function matrix matrix vector matrix) -;; (define-extern matrix-scale! function) ;; (function matrix vector matrix) -;; (define-extern scale-matrix! function) ;; (function matrix vector matrix matrix) -;; (define-extern matrix-inv-scale! function) ;; (function matrix vector matrix) -;; (define-extern column-scale-matrix! function) ;; (function matrix vector matrix matrix) -;; (define-extern matrix-rotate-x! function) ;; (function matrix float matrix) -;; (define-extern matrix-rotate-y! function) ;; (function matrix float matrix) -;; (define-extern matrix-rotate-z! function) ;; (function matrix float matrix) -;; (define-extern matrix-rotate-zyx! function) ;; (function matrix vector matrix) -;; (define-extern matrix-rotate-xyz-2! function) ;; (function matrix vector matrix) -;; (define-extern matrix-rotate-xyz! function) ;; (function matrix vector matrix) -;; (define-extern matrix-rotate-zxy! function) ;; (function matrix vector matrix) -;; (define-extern matrix-rotate-yxz! function) ;; (function matrix vector matrix) -;; (define-extern matrix-rotate-yzx! function) ;; (function matrix vector matrix) -;; (define-extern matrix-rotate-yxy! function) ;; (function matrix vector matrix) -;; (define-extern matrix-rotate-yx! function) ;; (function matrix float float matrix) -;; (define-extern matrix-axis-sin-cos-vu! function) ;; (function matrix vector float float none) -;; (define-extern matrix-axis-sin-cos! function) ;; (function matrix vector float float matrix) -;; (define-extern matrix-axis-angle! function) ;; (function matrix vector float matrix) -;; (define-extern matrix-lerp! function) ;; (function matrix matrix matrix float matrix) -;; (define-extern matrix-3x3-determinant function) ;; (function matrix float) -;; (define-extern matrix3-determinant function) ;; (function matrix float) -;; (define-extern matrix-3x3-inverse! function) ;; (function matrix matrix matrix) -;; (define-extern matrix-3x3-inverse-transpose! function) ;; (function matrix matrix matrix) -;; (define-extern matrix3-inverse-transpose! function) ;; (function matrix matrix matrix) -;; (define-extern matrix-3x3-normalize! function) ;; (function matrix matrix matrix) -;; (define-extern matrix-4x4-determinant function) ;; (function matrix float) -;; (define-extern matrix-4x4-inverse-transpose! function) ;; (function matrix matrix matrix) -;; (define-extern matrix-y-angle function) ;; (function matrix float) -;; (define-extern matrix->trans function) ;; (function matrix vector vector) -;; (define-extern matrix<-trans function) ;; (function matrix vector matrix) -;; (define-extern matrix->scale function) ;; (function matrix vector vector) -;; (define-extern matrix<-scale function) ;; (function matrix vector matrix) -;; (define-extern matrix->quat function) ;; (function matrix quaternion quaternion) -;; (define-extern matrix<-quat function) ;; (function matrix quaternion matrix) -;; (define-extern matrix->transformq function) ;; (function transformq matrix transformq) -;; (define-extern matrix-mirror! function) ;; (function matrix vector vector matrix) +(define-extern matrix-identity! "Set dst to the identity matrix." (function matrix matrix)) +(define-extern *identity-matrix* matrix) +(define-extern *hermite-matrix* matrix) +(define-extern matrix+! + "Set dst = src1 + src2. It is okay for any arguments to be the same data. + This is not an efficient implementation." + (function matrix matrix matrix matrix)) +(define-extern matrix-! + "Set dst = src1 - src1. It is okay for any arugments to be the same data. + This is not an efficient implementation." + (function matrix matrix matrix matrix)) +(define-extern matrix*! + "Set dst = src1 * src2. It is okay for any arguments to be the same data. + This is a moderately efficient implementation." + (function matrix matrix matrix matrix)) +(define-extern matrixp*! + "Set dst = src1 * src2. NOTE: this function is a wrapper around matrix*! + that adds no additional functionality. It seems to be a leftover from + a time when matrix*! wasn't safe to use in place. This is unused." + (function matrix matrix matrix matrix)) +(define-extern vector-matrix*! "Set dst = vec * mat. dst may be equal to src." (function vector vector matrix vector)) +(define-extern vector-norm-matrix*! (function vector vector matrix vector)) +(define-extern vector-rotate*! + "Set dst to be the input vector rotated by the rotation part of mat. + The input matrix should be a homogeneous transform with a rotation matrix as its upper-left 3x3. + dst may be equal to src." + (function vector vector matrix vector)) +(define-extern vector3s-matrix*! + "Set dst to be ([src 1.0] * mat).xyz. Doesn't touch the w of dst. + dst and vec can be the same memory" + (function vector3s vector3s matrix vector3s)) +(define-extern vector3s-rotate*! + "Set dst to vec rotated by the rotation in the homogeneous transform mat. + mat should not have a scale/shear (the upper 3x3 should be a pure rotation)." + (function vector3s vector3s matrix vector3s)) +(define-extern matrix-transpose! "Set dst = src^T. src and dst can be the same." (function matrix matrix matrix)) +(define-extern matrix-inverse-of-rot-trans! + "Set dst = src^-1, assuming src is a homogeneous tranform with only rotation/translation. + NOTE: THIS FUNCTION REQUIRES dst != src" + (function matrix matrix matrix)) +(define-extern matrix-4x4-inverse! + "Invert a 4x4 matrix. This assumes that the input is a homogeneous transform. + Src and dst can be the same." + (function matrix matrix matrix)) +(define-extern matrix-translate! "Set dst to a homogeneous transform with only a translation of trans." (function matrix vector matrix)) +(define-extern matrix-translate+! + "Add the given translation to the translation of homogenous transform mat src + and store in dst. It is okay for dst = src." + (function matrix matrix vector matrix)) +(define-extern matrix-scale! + "Set dst to a homogenous transform with only a scale. The x,y,z components + of scale become the x,y,z scaling factors" + (function matrix vector matrix)) +(define-extern scale-matrix! + "Scale an existing matrix. Okay for dst = src. The scaling is applied per row. + This means the x component of scale is used to scale the first row of src. + The w component of scale is used." + (function matrix vector matrix matrix)) +(define-extern matrix-inv-scale! + "Set dst to a homogeneous transform with only a scale. + The x,y,z components of scale are inverted and used as the x,y,z scaling factors" + (function matrix vector matrix)) +(define-extern column-scale-matrix! + "Scale an existing matrix. Okay for dst = src. The scaling is applied column-wise. + Meaning the x component of scale will scale the first column of src." + (function matrix vector matrix matrix)) +(define-extern matrix-rotate-x! + "Set dst to a homogeneous transform matrix for a rotation around the x-axis (degrees)." + (function matrix float matrix)) +(define-extern matrix-rotate-y! + "Set dst to a homoegeneous transform matrix for a rotation around the y axis (degrees)." + (function matrix float matrix)) +(define-extern matrix-rotate-z! + "Set dst to a homogeneous transform matrix for a rotation around the z-axis (degrees)." + (function matrix float matrix)) +(define-extern matrix-rotate-zyx! "Rotate in z,y,x order." (function matrix vector matrix)) +(define-extern matrix-rotate-xyz-2! + "Jak 1 version of matrix-rotate-xyz. Slower than the one below." + (function matrix vector matrix)) +(define-extern matrix-rotate-xyz! "Rotate in x,y,z order." (function matrix vector matrix)) +(define-extern matrix-rotate-zxy! "Rotate in z,x,y order." (function matrix vector matrix)) +(define-extern matrix-rotate-yxz! "Rotate in y,x,z order." (function matrix vector matrix)) +(define-extern matrix-rotate-yzx! "Rotate in y,z,x order." (function matrix vector matrix)) +(define-extern matrix-rotate-yxy! + "Rotate. I believe in yxy order? Compared to the other rotations, this one + is quite a bit more optimized and avoid repeated trig operations." + (function matrix vector matrix)) +(define-extern matrix-rotate-yx! "Rotate by y then x." (function matrix float float matrix)) +(define-extern matrix-axis-sin-cos-vu! + "Create an axis-angle rotation matrix. But given the sin/cos of the angle. Uses the VU." + (function matrix vector float float none)) +(define-extern matrix-axis-sin-cos! + "Create an axis-angle rotation matrix. But given the sin/cos of the angle." + (function matrix vector float float matrix)) +(define-extern matrix-axis-angle! "Create an axis-angle rotation matrix." (function matrix vector float matrix)) +(define-extern matrix-lerp! "Lerp an entire matrix, coefficient-wise." (function matrix matrix matrix float matrix)) +(define-extern matrix-3x3-determinant "Compute the determinant of a 3x3 matrix." (function matrix float)) +(define-extern matrix3-determinant "Unused. Not sure if this has limitations compared to the above version." (function matrix float)) +(define-extern matrix-3x3-inverse! + "Compute the inverse of a 3x3 matrix. Not very efficient. + Requires src != dst." + (function matrix matrix matrix)) +(define-extern matrix-3x3-inverse-transpose! + "Invert and transpose. + Requires dst != src." + (function matrix matrix matrix)) +(define-extern matrix3-inverse-transpose! + "Unused. Not sure if this has limitations compared to other version." + (function matrix matrix matrix)) +(define-extern matrix-3x3-normalize! "Unused." (function matrix matrix matrix)) +(define-extern matrix-4x4-determinant + "Take the determinant of a 4x4 matrix, but this is wrong." + (function matrix float)) +(define-extern matrix-4x4-inverse-transpose! + "Invert and transpose an entire 4x4. I think has no restrictions, other than dst != src. Unused. + The answer is wrong. The determinant function is wrong." + (function matrix matrix matrix)) +(define-extern matrix-y-angle + "If mat has its upper 3x3 as a rotation, gets the y axis rotation." + (function matrix float)) +(define-extern matrix->trans "Multiply xyz by 1/w."(function matrix vector vector)) +(define-extern matrix<-trans "Set the translation." (function matrix vector matrix)) +(define-extern matrix->scale "Get the scale of a matrix." (function matrix vector vector)) +(define-extern matrix<-scale "Set the scale of a matrix by rescaling." (function matrix vector matrix)) +(define-extern matrix->quat + "Convert matrix to quaternion, works for matrix with scale. + unlike matrix->quaternion." + (function matrix quaternion quaternion)) +(define-extern matrix<-quat "Modify the rotation part of a transform." (function matrix quaternion matrix)) +(define-extern matrix->transformq + "Create a transformq from a matrix. Allowing scale, etc." + (function transformq matrix transformq)) +(define-extern matrix-mirror! "Make a matrix that mirrors. Arguments are unclear." (function matrix vector vector matrix)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; matrix-compose ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; (define-extern matrix-fur-compose function) -;; (define-extern matrix-fu-compose function) -;; (define-extern matrix-fr-compose function) -;; (define-extern matrix-ur-compose function) -;; (define-extern matrix-f-u-compose function) -;; (define-extern matrix-f-r-compose function) -;; (define-extern matrix-u-f-compose function) -;; (define-extern matrix-u-r-compose function) -;; (define-extern matrix-r-f-compose function) -;; (define-extern matrix-r-u-compose function) -;; (define-extern matrix-f-compose function) -;; (define-extern matrix-u-compose function) -;; (define-extern matrix-r-compose function) +(define-extern matrix-fur-compose (function matrix vector vector vector matrix)) +(define-extern matrix-fu-compose (function matrix vector vector vector matrix)) +(define-extern matrix-fr-compose (function matrix vector vector vector matrix)) +(define-extern matrix-ur-compose (function matrix vector vector vector matrix)) +(define-extern matrix-f-u-compose (function matrix vector vector vector matrix)) +(define-extern matrix-f-r-compose (function matrix vector vector vector matrix)) +(define-extern matrix-u-f-compose (function matrix vector vector vector matrix)) +(define-extern matrix-u-r-compose (function matrix vector vector vector matrix)) +(define-extern matrix-r-f-compose (function matrix vector vector vector matrix)) +(define-extern matrix-r-u-compose (function matrix vector vector vector matrix)) +(define-extern matrix-f-compose (function matrix vector vector vector matrix)) +(define-extern matrix-u-compose (function matrix vector vector vector matrix)) +(define-extern matrix-r-compose (function matrix vector vector vector matrix)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; transform ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; (define-extern transform-matrix-calc! function) ;; (function transform matrix matrix) -;; (define-extern transform-matrix-parent-calc! function) ;; (function transform matrix vector matrix) -;; (define-extern trs-matrix-calc! function) ;; (function trs matrix matrix) +(define-extern transform-matrix-calc! + "Convert a transform to matrix. Not efficient, and the output is the second arg." + (function transform matrix matrix)) +(define-extern transform-matrix-parent-calc! + "Convert a transform to a matrix, applying an inverse scaling." + (function transform matrix vector matrix)) +(define-extern trs-matrix-calc! "Convert a trs to a matrix." (function trs matrix matrix)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; quaternion ;; @@ -1923,125 +2001,265 @@ ;; quaternion is already defined! -;; (define-extern quaternion-axis-angle! function) ;; (function quaternion float float float float quaternion) -;; (define-extern quaternion-vector-angle! function) ;; (function quaternion vector float quaternion) -;; (define-extern vector-angle<-quaternion! function) ;; (function vector quaternion vector) -;; (define-extern quaternion-look-at! function) ;; (function quaternion vector vector quaternion) -;; (define-extern quaternion-zero! function) ;; (function quaternion quaternion) -;; (define-extern quaternion-identity! function) ;; (function quaternion quaternion) -;; (define-extern quaternion-i! function) ;; (function quaternion quaternion) -;; (define-extern quaternion-j! function) ;; (function quaternion quaternion) -;; (define-extern quaternion-k! function) ;; (function quaternion quaternion) -;; (define-extern quaternion-copy! function) ;; (function quaternion quaternion quaternion) -;; (define-extern quaternion-set! function) ;; (function quaternion float float float float quaternion) -;; (define-extern quaternion+! function) ;; (function quaternion quaternion quaternion quaternion) -;; (define-extern quaternion-! function) ;; (function quaternion quaternion quaternion quaternion) -;; (define-extern quaternion-negate! function) ;; (function quaternion quaternion quaternion) -;; (define-extern quaternion-conjugate! function) ;; (function quaternion quaternion quaternion) -;; (define-extern quaternion-float*! function) ;; (function quaternion quaternion float quaternion) -;; (define-extern quaternion-float/! function) ;; (function quaternion quaternion float quaternion) -;; (define-extern quaternion-norm2 function) ;; (function quaternion float) -;; (define-extern quaternion-norm function) ;; (function quaternion float) -;; (define-extern quaternion-normalize! function) ;; (function quaternion quaternion) -;; (define-extern quaternion-inverse! function) ;; (function quaternion quaternion quaternion) -;; (define-extern quaternion-dot function) ;; (function quaternion quaternion float) -;; (define-extern quaternion*! function) ;; (function quaternion quaternion quaternion quaternion) -;; (define-extern quaternion-right-mult-matrix! function) ;; (function matrix quaternion matrix) -;; (define-extern quaternion-left-mult-matrix! function) ;; (function matrix quaternion matrix) -;; (define-extern quaternion->matrix function) ;; (function matrix quaternion matrix) -;; (define-extern quaternion->matrix-2 function) ;; (function matrix quaternion matrix) -;; (define-extern matrix->quaternion function) ;; (function quaternion matrix quaternion) -;; (define-extern matrix-with-scale->quaternion function) ;; (function quaternion matrix quaternion) -;; (define-extern quaternion-vector-len function) ;; (function quaternion float) -;; (define-extern quaternion-log! function) ;; (function quaternion quaternion quaternion) -;; (define-extern quaternion-exp! function) ;; (function quaternion quaternion quaternion) -;; (define-extern quaternion-slerp! function) ;; (function quaternion quaternion quaternion float quaternion) -;; (define-extern quaternion-pseudo-slerp! function) ;; (function quaternion quaternion quaternion float quaternion) -;; (define-extern quaternion-pseudo-seek function) ;; (function quaternion quaternion quaternion float quaternion) -;; (define-extern quaternion-smooth-seek! function) ;; (function quaternion quaternion quaternion float quaternion) -;; (define-extern quaternion-zxy! function) ;; (function quaternion vector quaternion) -;; (define-extern vector-x-quaternion! function) ;; (function vector quaternion vector) -;; (define-extern vector-y-quaternion! function) ;; (function vector quaternion vector) -;; (define-extern vector-z-quaternion! function) ;; (function vector quaternion vector) -;; (define-extern quaternion-x-angle function) ;; (function quaternion float) -;; (define-extern quaternion-y-angle function) ;; (function quaternion float) -;; (define-extern quaternion-z-angle function) ;; (function quaternion float) -;; (define-extern quaternion-vector-y-angle function) ;; (function quaternion vector float) -;; (define-extern quaternion-rotate-local-x! function) ;; (function quaternion quaternion float quaternion) -;; (define-extern quaternion-rotate-local-y! function) ;; (function quaternion quaternion float quaternion) -;; (define-extern quaternion-rotate-local-z! function) ;; (function quaternion quaternion float quaternion) -;; (define-extern quaternion-rotate-y! function) ;; (function quaternion quaternion float quaternion) -;; (define-extern quaternion-rotate-x! function) ;; (function quaternion quaternion float quaternion) -;; (define-extern quaternion-rotate-z! function) ;; (function quaternion quaternion float quaternion) -;; (define-extern quaternion-delta-y function) ;; (function quaternion quaternion float) -;; (define-extern quaternion-rotate-y-to-vector! function) ;; (function quaternion quaternion quaternion float quaternion) -;; (define-extern vector-rotate-around-axis! function) -;; (define-extern vector-rotate-x! function) ;; (function vector vector float vector) -;; (define-extern vector-rotate-y! function) ;; (function vector vector float vector) -;; (define-extern vector-rotate-z! function) ;; (function vector vector float vector) -;; (define-extern vector-y-angle function) ;; (function vector float) -;; (define-extern vector-x-angle function) ;; (function vector float) -;; (define-extern quaternion<-rotate-y-vector function) ;; (function quaternion vector quaternion) -;; (define-extern quaternion-validate function) ;; (function quaternion none) -;; (define-extern quaternion-xz-angle function) ;; (function quaternion float) +(define-extern quaternion-axis-angle! + "Construct a quaternion from an axis and angle. The axis should be normalized." + (function quaternion float float float float quaternion)) +(define-extern quaternion-vector-angle! + "Construct a quaternion from an axis and angle. The axis should be normalized." + (function quaternion vector float quaternion)) +(define-extern vector-angle<-quaternion! + "Convert the quaternion arg1 to axis-angle form and store in arg0 (angle goes in w)" + (function vector quaternion vector)) +(define-extern quaternion-look-at! "Look along arg1, with arg2 as up." (function quaternion vector vector quaternion)) +(define-extern quaternion-zero! "Set quaternion to all 0's." (function quaternion quaternion)) +(define-extern quaternion-identity! "Set quaternion to 0,0,0,1 (identity)." (function quaternion quaternion)) +(define-extern quaternion-i! "Create unit i quaternion." (function quaternion quaternion)) +(define-extern quaternion-j! "Create unit j quaternion." (function quaternion quaternion)) +(define-extern quaternion-k! "Create unit k quaternion." (function quaternion quaternion)) +(define-extern quaternion-copy! "Set arg0 = arg1." (function quaternion quaternion quaternion)) +(define-extern quaternion-set! "Set arg0 = [arg1, arg2, arg3, arg4]." (function quaternion float float float float quaternion)) +(define-extern quaternion+! "Add quaternions as vectors." (function quaternion quaternion quaternion quaternion)) +(define-extern quaternion-! "Subtract quaternions as vectors." (function quaternion quaternion quaternion quaternion)) +(define-extern quaternion-negate! "Set arg0 = -arg1." (function quaternion quaternion quaternion)) +(define-extern quaternion-conjugate! + "Set arg0 to the conjugate of arg1 (negate only ijk). + If arg1 is normalized, this is equivalent to the inverse + NOTE: this gives you the inverse rotation." + (function quaternion quaternion quaternion)) +(define-extern quaternion-float*! "Multiply each element." (function quaternion quaternion float quaternion)) +(define-extern quaternion-float/! "Divide each element." (function quaternion quaternion float quaternion)) +(define-extern quaternion-norm2 "Get the squared norm of a quaternion." (function quaternion float)) +(define-extern quaternion-norm "Get the norm of a quaternion." (function quaternion float)) +(define-extern quaternion-normalize! "Normalize a quaternion." (function quaternion quaternion)) +(define-extern quaternion-inverse! + "Invert a quaternion. The inverse will satisfy q * q^-1 = identity, even if q is not normalized. + If your quaternion is normalized, it is faster/more accurate to do quaternion-conjugate!" + (function quaternion quaternion quaternion)) +(define-extern quaternion-dot + "Treat quaternions as vectors and take the dot product." + (function quaternion quaternion float)) +(define-extern quaternion*! "Real quaternion multiplication." (function quaternion quaternion quaternion quaternion)) +(define-extern quaternion-right-mult-matrix! + "Place quaternion coefficients into a matrix. + You can convert a quaternion to a matrix by taking the product of this + right-mult and left-mult matrix, but this method is not used. + Instead, quaternion->matrix is a more efficient implementation." + (function matrix quaternion matrix)) +(define-extern quaternion-left-mult-matrix! + "Place quaternion coefficients into a matrix. Unused." + (function matrix quaternion matrix)) +(define-extern quaternion->matrix "Convert quaternion to matrix." (function matrix quaternion matrix)) +(define-extern quaternion->matrix-2 "Unused alternate quaternion->matrix function." (function matrix quaternion matrix)) +(define-extern matrix->quaternion "Convert a rotation matrix to a quaternion." (function quaternion matrix quaternion)) +(define-extern matrix-with-scale->quaternion + "Convert a matrix with a rotation and scale into a quaternion (just the rotation)." + (function quaternion matrix quaternion)) +(define-extern quaternion-vector-len + "Assuming quaternion is normalized, get the length of the xyz part." + (function quaternion float)) +(define-extern quaternion-log! "Take the log of a quaternion. Unused." (function quaternion quaternion quaternion)) +(define-extern quaternion-exp! "Quaternion exponentiation. Unused." (function quaternion quaternion quaternion)) +(define-extern quaternion-slerp! + "Real quaternion slerp. Spherical-linear interpolation is a nice way to interpolate + between quaternions." + (function quaternion quaternion quaternion float quaternion)) +(define-extern quaternion-pseudo-slerp! + "This is a bad interpolation between quaternions. It lerps then normalizes. + It will behave extremely poorly for 180 rotations. + It is unused." + (function quaternion quaternion quaternion float quaternion)) +(define-extern quaternion-pseudo-seek + "Seek one quaternion toward another. Not using real slerp, so this is only good if the quaternions + are pretty similar." + (function quaternion quaternion quaternion float quaternion)) +(define-extern quaternion-smooth-seek! "Another hacky rotation interpolation." (function quaternion quaternion quaternion float quaternion)) +(define-extern quaternion-zxy! + "Make a quaternion from a sequence of z, x, y axis rotations." + (function quaternion vector quaternion)) +(define-extern vector-x-quaternion! + "Get the first row of the rotation matrix for this quaternion." + (function vector quaternion vector)) +(define-extern vector-y-quaternion! + "Get the second row of the rotation matrix for this quaternion." + (function vector quaternion vector)) +(define-extern vector-z-quaternion! + "Get the third row of the rotation matrix for this quaternion." + (function vector quaternion vector)) +(define-extern quaternion-x-angle + "Get the x rotation angle. Not very efficient." + (function quaternion float)) +(define-extern quaternion-y-angle + "Get the y rotation angle. Not very efficient." + (function quaternion float)) +(define-extern quaternion-z-angle + "Get the z rotation angle. Not very efficient." + (function quaternion float)) +(define-extern quaternion-vector-y-angle + "Not sure. Angle between quaternion and axis, projected in xz plane?" + (function quaternion vector float)) +(define-extern quaternion-rotate-local-x! + "Rotate existing quaternion along x axis." + (function quaternion quaternion float quaternion)) +(define-extern quaternion-rotate-local-y! + "Rotate existing quaternion along y axis." + (function quaternion quaternion float quaternion)) +(define-extern quaternion-rotate-local-z! + "Rotate existing quaternion along z axis." + (function quaternion quaternion float quaternion)) +(define-extern quaternion-rotate-y! + "Rotate existing quaternion along y axis (right multiply)." + (function quaternion quaternion float quaternion)) +(define-extern quaternion-rotate-x! + "Rotate existing quaternion along x axis (right multiply)." + (function quaternion quaternion float quaternion)) +(define-extern quaternion-rotate-z! + "Rotate existing quaternion along z axis (right multiply)." + (function quaternion quaternion float quaternion)) +(define-extern quaternion-delta-y "Difference in yaw between two quaternions." (function quaternion quaternion float)) +(define-extern quaternion-rotate-y-to-vector! (function quaternion quaternion quaternion float quaternion)) +(define-extern vector-rotate-around-axis! + "Rotate along y so z-axis points to match another. Use arg3 as the max rotation amount." + (function vector quaternion float vector vector)) +(define-extern vector-rotate-x! "Rotate vector along x axis." (function vector vector float vector)) +(define-extern vector-rotate-y! "Rotate vector along y axis." (function vector vector float vector)) +(define-extern vector-rotate-z! "Rotate vector along z axis." (function vector vector float vector)) +(define-extern vector-y-angle "Get the yaw angle of a vector." (function vector float)) +(define-extern vector-x-angle "Get the pitch angle of a vector." (function vector float)) +(define-extern quaternion<-rotate-y-vector "Create a quaternion representing only the yaw of the given vector." (function quaternion vector quaternion)) +(define-extern quaternion-validate + "Verify that a quaternion is valid, print an error if the length is off by more than 1%.." + (function quaternion none)) +(define-extern quaternion-xz-angle + "Yet another function to compute the yaw of a quaternion. This is a particularly inefficient version." + (function quaternion float)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; euler ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; (define-extern set-eul! function) ;; (function euler-angles float float float int euler-angles) -;; (define-extern eul->matrix function) ;; (function matrix euler-angles matrix) -;; (define-extern matrix->eul function) ;; (function euler-angles matrix int euler-angles) -;; (define-extern eul->quat function) ;; (function quaternion euler-angles quaternion) -;; (define-extern quat->eul function) ;; (function euler-angles quaternion int euler-angles) +(define-extern set-eul! "Set euler angles and the flag bits." (function euler-angles float float float int euler-angles)) +(define-extern eul->matrix "Convert from euler angles to 4x4 matrix." (function matrix euler-angles matrix)) +(define-extern matrix->eul + "Convert matrix to euler angles with given order flag. + Not clear how this works if the matrix has more than just a rotation." + (function euler-angles matrix int euler-angles)) +(define-extern eul->quat + "Convert euler angles to quaternion, not very efficient." + (function quaternion euler-angles quaternion)) +(define-extern quat->eul + "Convert quaternion to euler angles with given order, not very efficient." + (function euler-angles quaternion int euler-angles)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; trigonometry ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; (define-extern radmod function) ;; (function float float) -;; (define-extern deg- function) ;; (function float float float) -;; (define-extern deg-diff function) ;; (function float float float) -;; (define-extern deg-seek function) ;; (function float float float float) -;; (define-extern deg-seek-smooth function) ;; (function float float float float float) -;; (define-extern deg-lerp-clamp function) ;; (function float float float float) -;; (define-extern binary-table array) ;; (array float) -;; (define-extern sincos-table array) ;; (array float) -;; (define-extern sin function) ;; (function float float) -;; (define-extern sin-rad function) ;; (function float float) -;; (define-extern *sin-poly-vec* object) ;; vector -;; (define-extern *sin-poly-vec2* object) ;; vector -;; (define-extern vector-sin-rad! function) ;; (function vector vector vector) -;; (define-extern cos-rad function) ;; (function float float) -;; (define-extern *cos-poly-vec* object) ;; vector -;; (define-extern vector-cos-rad! function) ;; (function vector vector vector) -;; (define-extern vector-sincos-rad! function) ;; (function vector vector vector int) -;; (define-extern sincos-rad! function) ;; (function vector float int) -;; (define-extern sincos! function) ;; (function vector float int) -;; (define-extern vector-rad<-vector-deg! function) ;; (function vector vector none) -;; (define-extern vector-rad<-vector-deg/2! function) ;; (function vector vector int) -;; (define-extern vector-sincos! function) ;; (function vector vector vector int) -;; (define-extern tan-rad function) ;; (function float float) -;; (define-extern cos function) ;; (function float float) -;; (define-extern tan function) ;; (function float float) -;; (define-extern atan0 function) ;; (function float float float) -;; (define-extern atan-series-rad function) ;; (function float float) -;; (define-extern atan-rad function) ;; (function float float) -;; (define-extern sign-bit function) ;; (function int int) -;; (define-extern sign-float function) ;; (function float float) -;; (define-extern sign function) ;; (function float float) -;; (define-extern atan2-rad function) ;; (function float float float) -;; (define-extern atan function) ;; (function float float float) -;; (define-extern asin function) ;; (function float float) -;; (define-extern acos function) ;; (function float float) -;; (define-extern acos-rad function) ;; (function float float) -;; (define-extern sinerp function) ;; (function float float float float) -;; (define-extern sinerp-clamp function) ;; (function float float float float) -;; (define-extern coserp function) ;; (function float float float float) -;; (define-extern coserp-clamp function) ;; (function float float float float) -;; (define-extern coserp180 function) ;; (function float float float float) -;; (define-extern coserp180-clamp function) ;; (function float float float float) -;; (define-extern ease-in-out function) ;; (function int int float) +(define-extern radmod "Wrap arg0 to be within (-pi, pi)." (function float float)) +(define-extern deg- + "Compute arg0-arg1, unwrapped, using rotation units. + Result should be in the range (-180, 180)" + (function float float float)) +(define-extern deg-diff + "Very similar to the function above, but computes arg1 - arg0 instead." + (function float float float)) +(define-extern deg-seek + "Move in toward target by at most max-diff, using rotation units" + (function float float float float)) +(define-extern deg-seek-smooth + "Step amount of the way from in to target, by at most max-diff, using rotation units" + (function float float float float float)) +(define-extern deg-lerp-clamp + "Map [0, 1] to min-val, max-val, handling wrapping and saturating, using rotation units." + (function float float float float)) +(define-extern binary-table (array float)) +(define-extern sincos-table (array float)) +(define-extern sin + "Compute the sine of an angle in rotation units. Unwraps it." + (function float float)) +(define-extern sin-rad + "Compute the sine of an angle in radians. + No unwrap is done, should be in -pi, pi" + (function float float)) +(define-extern *sin-poly-vec* vector) +(define-extern *sin-poly-vec2* vector) +(define-extern vector-sin-rad! + "Taylor series approximation of sine on all 4 elements in a vector. + Inputs should be in radians, in -pi to pi. + Somehow their coefficients are a little bit off. + Like the first coefficient, which should obviously be 1, is not quite 1." + (function vector vector vector)) +(define-extern cos-rad + "Cosine with taylor series. Input is in radians, in -pi, pi. + - TODO constants" + (function float float)) +(define-extern *cos-poly-vec* vector) +(define-extern vector-cos-rad! + "Compute the cosine of all 4 vector elements. + Radians, with no wrapping. Uses taylor series with 4 coefficients." + (function vector vector vector)) +(define-extern vector-sincos-rad! + "Compute the sine and cosine of each element of src, storing it in dst-sin and dst-cos. + This is more efficient than separate calls to sin and cos. + Inputs should be radians in -pi to pi." + (function vector vector vector int)) +(define-extern sincos-rad! + "Compute the sine and cosine of x, store it in the output array. + Has the cosine bug." + (function vector float int)) +(define-extern sincos! + "Compute the sine and cosine of x, store it in the output array. + The input is in rotation units, and is unwrapped properly. + Also has the cosine bug" + (function vector float int)) +(define-extern vector-rad<-vector-deg! + "Convert a vector in rotation units to radians, and unwrap. + Input can be anything, output will be -2pi to pi." + (function vector vector none)) +(define-extern vector-rad<-vector-deg/2! + "Divide the input by two, and then convert from rotation units to radians, unwrapping. + Not sure why this really needs to be separate the from previous function..." + (function vector vector int)) +(define-extern vector-sincos! + "Compute sine and cosine of each element in a vector, in rotation units" + (function vector vector vector int)) +(define-extern tan-rad + "This function appears to be named wrong and actually operates on rotation units." + (function float float)) +(define-extern cos "Cosine of rotation units." (function float float)) +(define-extern tan "Correctly named tangent of rotation units." (function float float)) +(define-extern atan0 + "Inverse tangent, to rotation units. y,x order. Does not handle signs correctly. + Do not use this function directly, instead use atan2." + (function float float float)) +(define-extern atan-series-rad "A helper function for atan." (function float float)) +(define-extern atan-rad "Inverse tangent in radians." (function float float)) +(define-extern sign-bit "Return 1 if bit 31 is set, otherwise 0." (function int int)) +(define-extern sign-float + "Return 1 if arg0 is positive or zero, -1 otherwise. + Fast (no branching)." + (function float float)) +(define-extern sign + "Similar to above, but returns 0 if input is 0. + But is more complicated." + (function float float)) +(define-extern atan2-rad "Atan for radians." (function float float float)) +(define-extern atan "Atan for rotation units. Signs behave like atan.." (function float float float)) +(define-extern asin "Inverse sine, rotation units." (function float float)) +(define-extern acos "Inverse cosine. Returns rotation units." (function float float)) +(define-extern acos-rad "Inverse cosine, radians." (function float float)) +(define-extern sinerp + "Map amount to min,max using sine. Kinda weird, usually people use cosine." + (function float float float float)) +(define-extern sinerp-clamp "Like sinerp, but clamp to min,max." (function float float float float)) +(define-extern coserp "Weird lerp with cosine (over 90 degrees?)." (function float float float float)) +(define-extern coserp-clamp + "Weird 90 degree lerp with cosine, clamped to min,max." + (function float float float float)) +(define-extern coserp180 "Classic lerp with cosine." (function float float float float)) +(define-extern coserp180-clamp "Classic coserp with saturation." (function float float float float)) +(define-extern ease-in-out + "Weird coserp like mapping from 0 to 1 as progress goes from 0 to total." + (function int int float)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; gsound-h ;; @@ -3773,7 +3991,7 @@ ;; (define-extern vector-segment-overlap function) ;; (function vector vector vector float) ;; (define-extern line-sphere-intersection? function) ;; (function vector vector vector symbol) ;; (define-extern nearest-dist2-between-moving-points function) ;; (function vector vector vector vector float float) -;; (define-extern vector-orient-by-quat! function) ;; (function vector vector quaternion vector) +(define-extern vector-orient-by-quat! (function vector vector quaternion vector)) ;; (define-extern vector-inv-orient-by-quat! function) ;; (function vector vector quaternion vector) ;; (define-extern forward-down->inv-matrix function) ;; (function matrix vector vector matrix) ;; (define-extern forward-down-nopitch->inv-matrix function) ;; (function matrix vector vector matrix) @@ -3783,7 +4001,7 @@ ;; (define-extern forward-up->quaternion function) ;; (function quaternion vector vector quaternion) ;; (define-extern quaternion-from-two-vectors! function) ;; (function quaternion vector vector quaternion) ;; (define-extern quaternion-from-two-vectors-partial! function) ;; (function quaternion vector vector float quaternion) -;; (define-extern quaternion-from-two-vectors-max-angle! function) ;; (function quaternion vector vector float quaternion) +(define-extern quaternion-from-two-vectors-max-angle! (function quaternion vector vector float quaternion)) ;; (define-extern quaternion-from-two-vectors-max-angle-partial! function) ;; (function quaternion vector vector float float quaternion) ;; (define-extern matrix-from-two-vectors! function) ;; (function matrix vector vector matrix) ;; (define-extern matrix-from-two-vectors-max-angle! function) ;; (function matrix vector vector float matrix) @@ -3840,104 +4058,104 @@ ;; vector ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; (define-extern vector-cross! function) ;; (function vector vector vector vector) -;; (define-extern vector-xz-cross! function) ;; (function vector vector vector vector) -;; (define-extern vector+float! function) ;; (function vector vector float vector) -;; (define-extern vector*! function) ;; (function vector vector vector vector) -;; (define-extern vector+*! function) ;; (function vector vector vector float vector) -;; (define-extern vector-*! function) ;; (function vector vector vector float vector) -;; (define-extern vector/! function) ;; (function vector vector vector vector) -;; (define-extern vector-float*! function) ;; (function vector vector float vector) -;; (define-extern vector-average! function) ;; (function vector vector vector vector) -;; (define-extern vector+float*! function) ;; (function vector vector vector float vector) -;; (define-extern vector--float*! function) ;; (function vector vector vector float vector) -;; (define-extern vector-min! function) -;; (define-extern vector-max! function) -;; (define-extern vector-float/! function) ;; (function vector vector float vector) -;; (define-extern vector-negate! function) ;; (function vector vector vector) -;; (define-extern vector-negate-in-place! function) ;; (function vector vector) -;; (define-extern vector= function) ;; (function vector vector symbol) -;; (define-extern vector-delta function) ;; (function vector vector float) -;; (define-extern vector-seek! function) ;; (function vector vector float vector) -;; (define-extern vector-smooth-seek! function) ;; (function vector vector float vector) -;; (define-extern vector-seek-2d-xz-smooth! function) ;; (function vector vector float float vector) -;; (define-extern vector-seek-2d-yz-smooth! function) ;; (function vector vector float float vector) -;; (define-extern vector-seek-3d-smooth! function) ;; (function vector vector float float vector) -;; (define-extern seek-with-smooth function) ;; (function float float float float float float) -;; (define-extern vector-identity! function) ;; (function vector vector) -;; (define-extern vector-seconds function) ;; (function vector vector vector) -;; (define-extern vector-seconds! function) ;; (function vector vector) -;; (define-extern vector-v! function) ;; (function vector vector) -;; (define-extern vector-v+! function) ;; (function vector vector vector vector) -;; (define-extern vector-v*float+! function) ;; (function vector vector vector float vector) -;; (define-extern vector-v++! function) ;; (function vector vector vector) -;; (define-extern vector-v*float! function) ;; (function vector vector float vector) -;; (define-extern vector-v*float++! function) ;; (function vector vector float vector) -;; (define-extern vector-to-ups! function) ;; (function vector vector vector) -;; (define-extern vector-from-ups! function) ;; (function vector vector vector) -;; (define-extern vector-length function) ;; (function vector float) -;; (define-extern vector-length-squared function) ;; (function vector float) -;; (define-extern vector-xz-length-squared function) ;; (function vector float) -;; (define-extern vector-xz-length function) ;; (function vector float) -;; (define-extern vector-vector-distance function) ;; (function vector vector float) -;; (define-extern vector-vector-distance-squared function) ;; (function vector vector float) -;; (define-extern vector-vector-xz-distance function) ;; (function vector vector float) -;; (define-extern vector-vector-xy-distance function) ;; (function vector vector float) -;; (define-extern vector-vector-xz-distance-squared function) ;; (function vector vector float) -;; (define-extern vector-vector-planar-distance function) -;; (define-extern vector-normalize! function) ;; (function vector float vector) -;; (define-extern vector-normalize-ret-len! function) ;; (function vector float float) -;; (define-extern vector-normalize-copy! function) ;; (function vector vector float vector) -;; (define-extern vector-xz-normalize! function) ;; (function vector float vector) -;; (define-extern vector-xz-normalize-copy! function) ;; (function vector vector float vector) -;; (define-extern vector-length-max! function) ;; (function vector float vector) -;; (define-extern vector-xz-length-max! function) ;; (function vector float vector) -;; (define-extern vector-rotate-around-x! function) ;; (function vector vector float vector) -;; (define-extern vector-rotate-around-y! function) ;; (function vector vector float vector) -;; (define-extern vector-rotate90-around-y! function) ;; (function vector vector vector) -;; (define-extern vector-rotate-around-z! function) ;; (function vector vector float vector) -;; (define-extern rotate-y<-vector+vector function) ;; (function vector vector float) -;; (define-extern rotate-x<-vector+vector function) ;; (function vector vector float) -;; (define-extern rotate-z<-vector+vector function) ;; (function vector vector float) -;; (define-extern rotate-vector-to-vector function) -;; (define-extern vector-cvt.w.s! function) ;; (function vector vector vector) -;; (define-extern vector-cvt.s.w! function) ;; (function vector vector vector) -;; (define-extern rot-zxy-from-vector! function) ;; (function vector vector vector) -;; (define-extern rot-zyx-from-vector! function) ;; (function vector vector vector) -;; (define-extern vector-lerp! function) ;; (function vector vector vector float vector) -;; (define-extern vector-lerp-clamp! function) ;; (function vector vector vector float vector) -;; (define-extern vector4-lerp! function) ;; (function vector vector vector float vector) -;; (define-extern vector4-lerp-clamp! function) ;; (function vector vector vector float vector) -;; (define-extern vector-degi function) ;; (function vector vector vector) -;; (define-extern vector-degf function) ;; (function vector vector vector) -;; (define-extern vector-degmod function) ;; (function vector vector vector) -;; (define-extern vector-deg-diff function) ;; (function vector vector vector none) -;; (define-extern vector-deg-lerp-clamp! function) ;; (function vector vector vector float vector) -;; (define-extern vector3s-copy! function) ;; (function vector vector vector) -;; (define-extern vector3s+! function) ;; (function vector vector vector vector) -;; (define-extern vector3s*float! function) ;; (function vector vector float vector) -;; (define-extern vector3s-! function) ;; (function vector vector vector vector) -;; (define-extern vector4-add! function) ;; (function vector4 vector4 vector4 none) -;; (define-extern vector4-sub! function) ;; (function vector4 vector4 vector4 none) -;; (define-extern vector4-mul! function) ;; (function vector4 vector4 vector4 none) -;; (define-extern vector4-scale! function) ;; (function vector4 vector4 float none) -;; (define-extern vector4-madd! function) ;; (function vector4 vector4 vector4 float none) -;; (define-extern vector4-msub! function) ;; (function vector4 vector4 vector4 float none) -;; (define-extern vector4-array-add! function) ;; (function (inline-array vector4) (inline-array vector4) (inline-array vector4) int none) -;; (define-extern vector4-array-sub! function) ;; (function (inline-array vector4) (inline-array vector4) (inline-array vector4) int none) -;; (define-extern vector4-array-mul! function) ;; (function (inline-array vector4) (inline-array vector4) (inline-array vector4) int none) -;; (define-extern vector4-array-scale! function) ;; (function (inline-array vector4) (inline-array vector4) float int none) -;; (define-extern vector4-array-madd! function) ;; (function (inline-array vector4) (inline-array vector4) (inline-array vector4) float int none) -;; (define-extern vector4-array-msub! function) ;; (function (inline-array vector4) (inline-array vector4) (inline-array vector4) float int none) -;; (define-extern vector4-array-lerp! function) ;; (function (inline-array vector4) (inline-array vector4) (inline-array vector4) float int symbol) -;; (define-extern spheres-overlap? function) ;; (function sphere sphere symbol) -;; (define-extern sphere<-vector! function) ;; (function sphere vector sphere) -;; (define-extern sphere<-vector+r! function) ;; (function sphere vector float sphere) -;; (define-extern rand-vu-sphere-point! function) ;; (function vector float vector) -;; (define-extern rand-vu-sphere-point-uniform! function) -;; (define-extern vector-vector-angle-safe function) ;; (function vector vector float) -;; (define-extern vector-get-unique! function) -;; (define-extern vector-get-closest-perpendicular! function) +(define-extern vector-cross! (function vector vector vector vector)) +(define-extern vector-xz-cross! (function vector vector vector vector)) +(define-extern vector+float! (function vector vector float vector)) +(define-extern vector*! (function vector vector vector vector)) +(define-extern vector+*! (function vector vector vector float vector)) +(define-extern vector-*! (function vector vector vector float vector)) +(define-extern vector/! (function vector vector vector vector)) +(define-extern vector-float*! (function vector vector float vector)) +(define-extern vector-average! (function vector vector vector vector)) +(define-extern vector+float*! (function vector vector vector float vector)) +(define-extern vector--float*! (function vector vector vector float vector)) +(define-extern vector-min! function) +(define-extern vector-max! function) +(define-extern vector-float/! (function vector vector float vector)) +(define-extern vector-negate! (function vector vector vector)) +(define-extern vector-negate-in-place! (function vector vector)) +(define-extern vector= (function vector vector symbol)) +(define-extern vector-delta (function vector vector float)) +(define-extern vector-seek! (function vector vector float vector)) +(define-extern vector-smooth-seek! (function vector vector float vector)) +(define-extern vector-seek-2d-xz-smooth! (function vector vector float float vector)) +(define-extern vector-seek-2d-yz-smooth! (function vector vector float float vector)) +(define-extern vector-seek-3d-smooth! (function vector vector float float vector)) +(define-extern seek-with-smooth (function float float float float float float)) +(define-extern vector-identity! (function vector vector)) +(define-extern vector-seconds (function vector vector vector)) +(define-extern vector-seconds! (function vector vector)) +(define-extern vector-v! (function vector vector)) +(define-extern vector-v+! (function vector vector vector vector)) +(define-extern vector-v*float+! (function vector vector vector float vector)) +(define-extern vector-v++! (function vector vector vector)) +(define-extern vector-v*float! (function vector vector float vector)) +(define-extern vector-v*float++! (function vector vector float vector)) +(define-extern vector-to-ups! (function vector vector vector)) +(define-extern vector-from-ups! (function vector vector vector)) +(define-extern vector-length (function vector float)) +(define-extern vector-length-squared (function vector float)) +(define-extern vector-xz-length-squared (function vector float)) +(define-extern vector-xz-length (function vector float)) +(define-extern vector-vector-distance (function vector vector float)) +(define-extern vector-vector-distance-squared (function vector vector float)) +(define-extern vector-vector-xz-distance (function vector vector float)) +(define-extern vector-vector-xy-distance (function vector vector float)) +(define-extern vector-vector-xz-distance-squared (function vector vector float)) +(define-extern vector-vector-planar-distance function) +(define-extern vector-normalize! (function vector float vector)) +(define-extern vector-normalize-ret-len! (function vector float float)) +(define-extern vector-normalize-copy! (function vector vector float vector)) +(define-extern vector-xz-normalize! (function vector float vector)) +(define-extern vector-xz-normalize-copy! (function vector vector float vector)) +(define-extern vector-length-max! (function vector float vector)) +(define-extern vector-xz-length-max! (function vector float vector)) +(define-extern vector-rotate-around-x! (function vector vector float vector)) +(define-extern vector-rotate-around-y! (function vector vector float vector)) +(define-extern vector-rotate90-around-y! (function vector vector vector)) +(define-extern vector-rotate-around-z! (function vector vector float vector)) +(define-extern rotate-y<-vector+vector (function vector vector float)) +(define-extern rotate-x<-vector+vector (function vector vector float)) +(define-extern rotate-z<-vector+vector (function vector vector float)) +(define-extern rotate-vector-to-vector function) +(define-extern vector-cvt.w.s! (function vector vector vector)) +(define-extern vector-cvt.s.w! (function vector vector vector)) +(define-extern rot-zxy-from-vector! (function vector vector vector)) +(define-extern rot-zyx-from-vector! (function vector vector vector)) +(define-extern vector-lerp! (function vector vector vector float vector)) +(define-extern vector-lerp-clamp! (function vector vector vector float vector)) +(define-extern vector4-lerp! (function vector vector vector float vector)) +(define-extern vector4-lerp-clamp! (function vector vector vector float vector)) +(define-extern vector-degi (function vector vector vector)) +(define-extern vector-degf (function vector vector vector)) +(define-extern vector-degmod (function vector vector vector)) +(define-extern vector-deg-diff (function vector vector vector none)) +(define-extern vector-deg-lerp-clamp! (function vector vector vector float vector)) +(define-extern vector3s-copy! (function vector vector vector)) +(define-extern vector3s+! (function vector vector vector vector)) +(define-extern vector3s*float! (function vector vector float vector)) +(define-extern vector3s-! (function vector vector vector vector)) +(define-extern vector4-add! (function vector4 vector4 vector4 none)) +(define-extern vector4-sub! (function vector4 vector4 vector4 none)) +(define-extern vector4-mul! (function vector4 vector4 vector4 none)) +(define-extern vector4-scale! (function vector4 vector4 float none)) +(define-extern vector4-madd! (function vector4 vector4 vector4 float none)) +(define-extern vector4-msub! (function vector4 vector4 vector4 float none)) +(define-extern vector4-array-add! (function (inline-array vector4) (inline-array vector4) (inline-array vector4) int none)) +(define-extern vector4-array-sub! (function (inline-array vector4) (inline-array vector4) (inline-array vector4) int none)) +(define-extern vector4-array-mul! (function (inline-array vector4) (inline-array vector4) (inline-array vector4) int none)) +(define-extern vector4-array-scale! (function (inline-array vector4) (inline-array vector4) float int none)) +(define-extern vector4-array-madd! (function (inline-array vector4) (inline-array vector4) (inline-array vector4) float int none)) +(define-extern vector4-array-msub! (function (inline-array vector4) (inline-array vector4) (inline-array vector4) float int none)) +(define-extern vector4-array-lerp! (function (inline-array vector4) (inline-array vector4) (inline-array vector4) float int symbol)) +(define-extern spheres-overlap? (function sphere sphere symbol)) +(define-extern sphere<-vector! (function sphere vector sphere)) +(define-extern sphere<-vector+r! (function sphere vector float sphere)) +(define-extern rand-vu-sphere-point! (function vector float vector)) +(define-extern rand-vu-sphere-point-uniform! function) +(define-extern vector-vector-angle-safe (function vector vector float)) +(define-extern vector-get-unique! (function vector vector vector)) +(define-extern vector-get-closest-perpendicular! (function vector vector vector vector)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; file-io ;; diff --git a/decompiler/config/jak3/ntsc_v1/inputs.jsonc b/decompiler/config/jak3/ntsc_v1/inputs.jsonc index 413b438e3c..472258c465 100644 --- a/decompiler/config/jak3/ntsc_v1/inputs.jsonc +++ b/decompiler/config/jak3/ntsc_v1/inputs.jsonc @@ -11,280 +11,280 @@ //"CGO/ART.CGO", "CGO/KERNEL.CGO", // "CGO/ENGINE.CGO", - "CGO/GAME.CGO", + "CGO/GAME.CGO" // "CGO/COMMON.CGO", - "DGO/LJKDMPK.DGO", - "DGO/LBBSDRP1.DGO", - "DGO/LTNJXHIP.DGO", - "DGO/MIC.DGO", - "DGO/OASISCST.DGO", - "DGO/CTYPEPA.DGO", - "DGO/LPRENME.DGO", - "DGO/LFREEOUT.DGO", - "DGO/LGUNNORM.DGO", - "DGO/LTOWA.DGO", - "DGO/TEMA.DGO", - "DGO/CTA.DGO", - "DGO/LPRECC.DGO", - "DGO/LJKDXVIN.DGO", - "DGO/CTYPEPC.DGO", - "DGO/SEA.DGO", - "DGO/COMBE.DGO", - "DGO/CTYPESA.DGO", - "DGO/LBLOWCST.DGO", - "DGO/WSD.DGO", - "DGO/LBBRING3.DGO", - "DGO/LCTYPATK.DGO", - "DGO/WCB.DGO", - "DGO/DESRESC.DGO", - "DGO/LBBRING4.DGO", - "DGO/GRIDCST.DGO", - "DGO/RAILX.DGO", - "DGO/SEJ.DGO", - "DGO/LJAKC.DGO", - "DGO/CTB.DGO", - "DGO/CTYCARC.DGO", - "DGO/LMECH.DGO", - "DGO/LBBSDRP2.DGO", - "DGO/NSA.DGO", - "DGO/LBBTCHA3.DGO", - "DGO/GUNGAME2.DGO", - "DGO/CTC.DGO", - "DGO/LVINCST.DGO", - "DGO/COMBX.DGO", - "DGO/DESH.DGO", - "DGO/DESRACE2.DGO", - "DGO/RAILD.DGO", - "DGO/FACC.DGO", - "DGO/CTYPESC.DGO", - "DGO/LWASBBV.DGO", - "DGO/TOWB.DGO", - "DGO/HGA.DGO", - "DGO/SEH.DGO", - "DGO/MHCTYCST.DGO", - "DGO/GUNGAME1.DGO", - "DGO/INTROCST.DGO", - "DGO/DESJUMP.DGO", - "DGO/SEM.DGO", - "DGO/SEI.DGO", - "DGO/DESG.DGO", - "DGO/DESW.DGO", - "DGO/LOUTRO3.DGO", - "DGO/LDAMKLEV.DGO", - "DGO/DESERROL.DGO", - "DGO/RAILB2.DGO", - "DGO/LERROL.DGO", - "DGO/IPF.DGO", - "DGO/RAILB.DGO", - "DGO/LCTYHIJK.DGO", - "DGO/CTYPEPB.DGO", - "DGO/PRECB.DGO", - "DGO/LFORM.DGO", - "DGO/WASLEAPR.DGO", - "DGO/LKEIRA.DGO", - "DGO/LJAK.DGO", - "DGO/SLUMBSET.DGO", - "DGO/FACD.DGO", - "DGO/LWASSIG.DGO", - "DGO/LBIPED.DGO", - "DGO/DESD.DGO", - "DGO/CFB.DGO", - "DGO/FREECAST.DGO", - "DGO/SEG.DGO", - "DGO/FACTORYA.DGO", - "DGO/LPATK.DGO", - "DGO/FRSTX.DGO", - "DGO/SEB.DGO", - "DGO/DESBCST.DGO", - "DGO/DESE.DGO", - "DGO/DESOASIS.DGO", - "DGO/CTYCARA.DGO", - "DGO/LSIGKLV.DGO", - "DGO/CIB.DGO", - "DGO/LBBRING2.DGO", - "DGO/LTNFXHIP.DGO", - "DGO/MIA.DGO", - "DGO/MHCB.DGO", - "DGO/LNSTOBC.DGO", - "DGO/COMBD.DGO", - "DGO/RBCT.DGO", - "DGO/LTORNJNX.DGO", - "DGO/DESBATTL.DGO", - "DGO/SEK.DGO", - "DGO/LSNKWHLS.DGO", - "DGO/LMHCB.DGO", - "DGO/LBOMBBOT.DGO", - "DGO/OUTCAST3.DGO", - "DGO/LBLOWTMH.DGO", - "DGO/TEMD.DGO", - "DGO/LTOWCITY.DGO", - "DGO/OUTROCST.DGO", - "DGO/WASCAST.DGO", - "DGO/LFACRM2.DGO", - "DGO/WASPGAME.DGO", - "DGO/RAILE.DGO", - "DGO/CTYPESB.DGO", - "DGO/DESBOSS1.DGO", - "DGO/FREEHQ.DGO", - "DGO/LTORN.DGO", - "DGO/TOWERA.DGO", - "DGO/LSAMOS.DGO", - "DGO/LFORP.DGO", - "DGO/CFA.DGO", - "DGO/LJINX.DGO", - "DGO/SEO.DGO", - "DGO/PRECA.DGO", - "DGO/TOWERC.DGO", - "DGO/WCA.DGO", - "DGO/SEC.DGO", - "DGO/DESF.DGO", - "DGO/SEL.DGO", - "DGO/LCTYDEST.DGO", - "DGO/LTORNSAM.DGO", - "DGO/MUSEUM3B.DGO", - "DGO/SEE.DGO", - "DGO/DESHUNT.DGO", - "DGO/RAILA.DGO", - "DGO/TITLE.DGO", - "DGO/RUBC.DGO", - "DGO/DESB.DGO", - "DGO/LFACCAR.DGO", - "DGO/LNSTOA.DGO", - "DGO/MUSEUM3.DGO", - "DGO/ONINTENT.DGO", - "DGO/STA.DGO", - "DGO/WASSTADA.DGO", - "DGO/POWERGD.DGO", - "DGO/LKLEEVER.DGO", - "DGO/FACB.DGO", - "DGO/LCTYASS.DGO", - "DGO/MHCA.DGO", - "DGO/LTOWB.DGO", - "DGO/LNSTCST.DGO", - "DGO/DESRESCG.DGO", - "DGO/INTPALRF.DGO", - "DGO/LMHCA.DGO", - "DGO/TOWERCST.DGO", - "DGO/RAILF.DGO", - "DGO/CIA.DGO", - "DGO/CTYCARKG.DGO", - "DGO/WASCHASE.DGO", - "DGO/LFACO.DGO", - "DGO/WIN.DGO", - "DGO/TEMPLEE.DGO", - "DGO/LBBSPIRT.DGO", - "DGO/MUSEUM2.DGO", - "DGO/INTTITLE.DGO", - "DGO/STAA.DGO", - "DGO/MUSEUM4B.DGO", - "DGO/PRECD.DGO", - "DGO/SEF.DGO", - "DGO/CTYCARB.DGO", - "DGO/WASDEFEN.DGO", - "DGO/LBLOWTKG.DGO", - "DGO/DESA.DGO", - "DGO/COMBB.DGO", - "DGO/WASSTADC.DGO", - "DGO/DESC.DGO", - "DGO/LDAMPECK.DGO", - "DGO/LJAKSIG.DGO", - "DGO/HALFPIPE.DGO", - "DGO/DESRACE1.DGO", - "DGO/SEN.DGO", - "DGO/TEMP.DGO", - "DGO/SED.DGO", - "DGO/LFACB.DGO", - "DGO/LCTYSNPR.DGO", - "DGO/LBBSPID.DGO", - "DGO/FRSTA.DGO", - "DGO/LBBRING5.DGO", - "DGO/LBBSPRT3.DGO", - "DGO/HHG.DGO", - "DGO/LBBSPRT2.DGO", - "DGO/CGB.DGO", - "DGO/LDMPCKGN.DGO", - "DGO/LSEEMWCA.DGO", - "DGO/HGB.DGO", - "DGO/LONINSIM.DGO", - "DGO/RUBA.DGO", - "DGO/DESRALLY.DGO", - "DGO/WWD.DGO", - "DGO/STB.DGO", - "DGO/MIB.DGO", - "DGO/LCTYBLOW.DGO", - "DGO/LWSTDPCK.DGO", - "DGO/MUSEUM.DGO", - "DGO/LJAKCKLV.DGO", - "DGO/LBBRING1.DGO", - "DGO/MUSEUM4.DGO", - "DGO/LFACRM1.DGO", - "DGO/LJKCDMKL.DGO", - "DGO/LDAMSIG.DGO", - "DGO/DESTRACK.DGO", - "DGO/GGA.DGO", - "DGO/RAILC.DGO", - "DGO/LBBTCHA2.DGO", - "DGO/DESINTER.DGO", - "DGO/NSB.DGO", - "DGO/LOUTRO.DGO", - "DGO/VIN.DGO", - "DGO/LDESGCST.DGO", - "DGO/WARPCAST.DGO", - "DGO/LBBRING6.DGO", - "DGO/FRSTB.DGO", - "DGO/TEMC.DGO", - "DGO/COMBC.DGO", - "DGO/LTRTWHLS.DGO", - "DGO/PRECC.DGO", - "DGO/DESCHASE.DGO", - "DGO/CITYCAST.DGO", - "DGO/CPO.DGO", - "DGO/LFACCITY.DGO", - "DGO/RAILCST.DGO", - "DGO/LJNDKLEV.DGO", - "DGO/CWI.DGO", - "DGO/MINEE.DGO", - "DGO/LFORRING.DGO", - "DGO/LASHELIN.DGO", - "DGO/LJAKKLEV.DGO", - "DGO/LCTYPALT.DGO", - "DGO/LNSTOBB.DGO", - "DGO/LJKFEET.DGO", - "DGO/DST.DGO", - "DGO/LBBTCHA1.DGO", - "DGO/LGUNRNC.DGO", - "DGO/COMBN.DGO", - "DGO/DESRESCC.DGO", - "DGO/LSIGJAKC.DGO", - "DGO/DESLIZ.DGO", - "DGO/WASPALA.DGO", - "DGO/LJAKNDAX.DGO", - "DGO/WASSEEM.DGO", - "DGO/WASALL.DGO", - "DGO/WCASEEM.DGO", - "DGO/LSIG.DGO", - "DGO/LFACTORY.DGO", - "DGO/LWLANDM.DGO", - "DGO/LPTRL.DGO", - "DGO/MINED.DGO", - "DGO/LDAMPKSM.DGO", - "DGO/RUBB.DGO", - "DGO/LCITYSML.DGO", - "DGO/RUBA2.DGO", - "DGO/LOUTRO2.DGO", - "DGO/VOCX.DGO", - "DGO/TEMX.DGO", - "DGO/ARENACST.DGO", - "DGO/TEMB.DGO", - "DGO/COMBA.DGO", - "DGO/LBBSDRP3.DGO", - "DGO/LPATKCS.DGO", - "DGO/VOCA.DGO", - "DGO/WASSTADB.DGO", - "DGO/LDAX.DGO", - "DGO/LCTYPROT.DGO", - "DGO/DESHOVER.DGO", - "DGO/DESBOSS2.DGO" + // "DGO/LJKDMPK.DGO", + // "DGO/LBBSDRP1.DGO", + // "DGO/LTNJXHIP.DGO", + // "DGO/MIC.DGO", + // "DGO/OASISCST.DGO", + // "DGO/CTYPEPA.DGO", + // "DGO/LPRENME.DGO", + // "DGO/LFREEOUT.DGO", + // "DGO/LGUNNORM.DGO", + // "DGO/LTOWA.DGO", + // "DGO/TEMA.DGO", + // "DGO/CTA.DGO", + // "DGO/LPRECC.DGO", + // "DGO/LJKDXVIN.DGO", + // "DGO/CTYPEPC.DGO", + // "DGO/SEA.DGO", + // "DGO/COMBE.DGO", + // "DGO/CTYPESA.DGO", + // "DGO/LBLOWCST.DGO", + // "DGO/WSD.DGO", + // "DGO/LBBRING3.DGO", + // "DGO/LCTYPATK.DGO", + // "DGO/WCB.DGO", + // "DGO/DESRESC.DGO", + // "DGO/LBBRING4.DGO", + // "DGO/GRIDCST.DGO", + // "DGO/RAILX.DGO", + // "DGO/SEJ.DGO", + // "DGO/LJAKC.DGO", + // "DGO/CTB.DGO", + // "DGO/CTYCARC.DGO", + // "DGO/LMECH.DGO", + // "DGO/LBBSDRP2.DGO", + // "DGO/NSA.DGO", + // "DGO/LBBTCHA3.DGO", + // "DGO/GUNGAME2.DGO", + // "DGO/CTC.DGO", + // "DGO/LVINCST.DGO", + // "DGO/COMBX.DGO", + // "DGO/DESH.DGO", + // "DGO/DESRACE2.DGO", + // "DGO/RAILD.DGO", + // "DGO/FACC.DGO", + // "DGO/CTYPESC.DGO", + // "DGO/LWASBBV.DGO", + // "DGO/TOWB.DGO", + // "DGO/HGA.DGO", + // "DGO/SEH.DGO", + // "DGO/MHCTYCST.DGO", + // "DGO/GUNGAME1.DGO", + // "DGO/INTROCST.DGO", + // "DGO/DESJUMP.DGO", + // "DGO/SEM.DGO", + // "DGO/SEI.DGO", + // "DGO/DESG.DGO", + // "DGO/DESW.DGO", + // "DGO/LOUTRO3.DGO", + // "DGO/LDAMKLEV.DGO", + // "DGO/DESERROL.DGO", + // "DGO/RAILB2.DGO", + // "DGO/LERROL.DGO", + // "DGO/IPF.DGO", + // "DGO/RAILB.DGO", + // "DGO/LCTYHIJK.DGO", + // "DGO/CTYPEPB.DGO", + // "DGO/PRECB.DGO", + // "DGO/LFORM.DGO", + // "DGO/WASLEAPR.DGO", + // "DGO/LKEIRA.DGO", + // "DGO/LJAK.DGO", + // "DGO/SLUMBSET.DGO", + // "DGO/FACD.DGO", + // "DGO/LWASSIG.DGO", + // "DGO/LBIPED.DGO", + // "DGO/DESD.DGO", + // "DGO/CFB.DGO", + // "DGO/FREECAST.DGO", + // "DGO/SEG.DGO", + // "DGO/FACTORYA.DGO", + // "DGO/LPATK.DGO", + // "DGO/FRSTX.DGO", + // "DGO/SEB.DGO", + // "DGO/DESBCST.DGO", + // "DGO/DESE.DGO", + // "DGO/DESOASIS.DGO", + // "DGO/CTYCARA.DGO", + // "DGO/LSIGKLV.DGO", + // "DGO/CIB.DGO", + // "DGO/LBBRING2.DGO", + // "DGO/LTNFXHIP.DGO", + // "DGO/MIA.DGO", + // "DGO/MHCB.DGO", + // "DGO/LNSTOBC.DGO", + // "DGO/COMBD.DGO", + // "DGO/RBCT.DGO", + // "DGO/LTORNJNX.DGO", + // "DGO/DESBATTL.DGO", + // "DGO/SEK.DGO", + // "DGO/LSNKWHLS.DGO", + // "DGO/LMHCB.DGO", + // "DGO/LBOMBBOT.DGO", + // "DGO/OUTCAST3.DGO", + // "DGO/LBLOWTMH.DGO", + // "DGO/TEMD.DGO", + // "DGO/LTOWCITY.DGO", + // "DGO/OUTROCST.DGO", + // "DGO/WASCAST.DGO", + // "DGO/LFACRM2.DGO", + // "DGO/WASPGAME.DGO", + // "DGO/RAILE.DGO", + // "DGO/CTYPESB.DGO", + // "DGO/DESBOSS1.DGO", + // "DGO/FREEHQ.DGO", + // "DGO/LTORN.DGO", + // "DGO/TOWERA.DGO", + // "DGO/LSAMOS.DGO", + // "DGO/LFORP.DGO", + // "DGO/CFA.DGO", + // "DGO/LJINX.DGO", + // "DGO/SEO.DGO", + // "DGO/PRECA.DGO", + // "DGO/TOWERC.DGO", + // "DGO/WCA.DGO", + // "DGO/SEC.DGO", + // "DGO/DESF.DGO", + // "DGO/SEL.DGO", + // "DGO/LCTYDEST.DGO", + // "DGO/LTORNSAM.DGO", + // "DGO/MUSEUM3B.DGO", + // "DGO/SEE.DGO", + // "DGO/DESHUNT.DGO", + // "DGO/RAILA.DGO", + // "DGO/TITLE.DGO", + // "DGO/RUBC.DGO", + // "DGO/DESB.DGO", + // "DGO/LFACCAR.DGO", + // "DGO/LNSTOA.DGO", + // "DGO/MUSEUM3.DGO", + // "DGO/ONINTENT.DGO", + // "DGO/STA.DGO", + // "DGO/WASSTADA.DGO", + // "DGO/POWERGD.DGO", + // "DGO/LKLEEVER.DGO", + // "DGO/FACB.DGO", + // "DGO/LCTYASS.DGO", + // "DGO/MHCA.DGO", + // "DGO/LTOWB.DGO", + // "DGO/LNSTCST.DGO", + // "DGO/DESRESCG.DGO", + // "DGO/INTPALRF.DGO", + // "DGO/LMHCA.DGO", + // "DGO/TOWERCST.DGO", + // "DGO/RAILF.DGO", + // "DGO/CIA.DGO", + // "DGO/CTYCARKG.DGO", + // "DGO/WASCHASE.DGO", + // "DGO/LFACO.DGO", + // "DGO/WIN.DGO", + // "DGO/TEMPLEE.DGO", + // "DGO/LBBSPIRT.DGO", + // "DGO/MUSEUM2.DGO", + // "DGO/INTTITLE.DGO", + // "DGO/STAA.DGO", + // "DGO/MUSEUM4B.DGO", + // "DGO/PRECD.DGO", + // "DGO/SEF.DGO", + // "DGO/CTYCARB.DGO", + // "DGO/WASDEFEN.DGO", + // "DGO/LBLOWTKG.DGO", + // "DGO/DESA.DGO", + // "DGO/COMBB.DGO", + // "DGO/WASSTADC.DGO", + // "DGO/DESC.DGO", + // "DGO/LDAMPECK.DGO", + // "DGO/LJAKSIG.DGO", + // "DGO/HALFPIPE.DGO", + // "DGO/DESRACE1.DGO", + // "DGO/SEN.DGO", + // "DGO/TEMP.DGO", + // "DGO/SED.DGO", + // "DGO/LFACB.DGO", + // "DGO/LCTYSNPR.DGO", + // "DGO/LBBSPID.DGO", + // "DGO/FRSTA.DGO", + // "DGO/LBBRING5.DGO", + // "DGO/LBBSPRT3.DGO", + // "DGO/HHG.DGO", + // "DGO/LBBSPRT2.DGO", + // "DGO/CGB.DGO", + // "DGO/LDMPCKGN.DGO", + // "DGO/LSEEMWCA.DGO", + // "DGO/HGB.DGO", + // "DGO/LONINSIM.DGO", + // "DGO/RUBA.DGO", + // "DGO/DESRALLY.DGO", + // "DGO/WWD.DGO", + // "DGO/STB.DGO", + // "DGO/MIB.DGO", + // "DGO/LCTYBLOW.DGO", + // "DGO/LWSTDPCK.DGO", + // "DGO/MUSEUM.DGO", + // "DGO/LJAKCKLV.DGO", + // "DGO/LBBRING1.DGO", + // "DGO/MUSEUM4.DGO", + // "DGO/LFACRM1.DGO", + // "DGO/LJKCDMKL.DGO", + // "DGO/LDAMSIG.DGO", + // "DGO/DESTRACK.DGO", + // "DGO/GGA.DGO", + // "DGO/RAILC.DGO", + // "DGO/LBBTCHA2.DGO", + // "DGO/DESINTER.DGO", + // "DGO/NSB.DGO", + // "DGO/LOUTRO.DGO", + // "DGO/VIN.DGO", + // "DGO/LDESGCST.DGO", + // "DGO/WARPCAST.DGO", + // "DGO/LBBRING6.DGO", + // "DGO/FRSTB.DGO", + // "DGO/TEMC.DGO", + // "DGO/COMBC.DGO", + // "DGO/LTRTWHLS.DGO", + // "DGO/PRECC.DGO", + // "DGO/DESCHASE.DGO", + // "DGO/CITYCAST.DGO", + // "DGO/CPO.DGO", + // "DGO/LFACCITY.DGO", + // "DGO/RAILCST.DGO", + // "DGO/LJNDKLEV.DGO", + // "DGO/CWI.DGO", + // "DGO/MINEE.DGO", + // "DGO/LFORRING.DGO", + // "DGO/LASHELIN.DGO", + // "DGO/LJAKKLEV.DGO", + // "DGO/LCTYPALT.DGO", + // "DGO/LNSTOBB.DGO", + // "DGO/LJKFEET.DGO", + // "DGO/DST.DGO", + // "DGO/LBBTCHA1.DGO", + // "DGO/LGUNRNC.DGO", + // "DGO/COMBN.DGO", + // "DGO/DESRESCC.DGO", + // "DGO/LSIGJAKC.DGO", + // "DGO/DESLIZ.DGO", + // "DGO/WASPALA.DGO", + // "DGO/LJAKNDAX.DGO", + // "DGO/WASSEEM.DGO", + // "DGO/WASALL.DGO", + // "DGO/WCASEEM.DGO", + // "DGO/LSIG.DGO", + // "DGO/LFACTORY.DGO", + // "DGO/LWLANDM.DGO", + // "DGO/LPTRL.DGO", + // "DGO/MINED.DGO", + // "DGO/LDAMPKSM.DGO", + // "DGO/RUBB.DGO", + // "DGO/LCITYSML.DGO", + // "DGO/RUBA2.DGO", + // "DGO/LOUTRO2.DGO", + // "DGO/VOCX.DGO", + // "DGO/TEMX.DGO", + // "DGO/ARENACST.DGO", + // "DGO/TEMB.DGO", + // "DGO/COMBA.DGO", + // "DGO/LBBSDRP3.DGO", + // "DGO/LPATKCS.DGO", + // "DGO/VOCA.DGO", + // "DGO/WASSTADB.DGO", + // "DGO/LDAX.DGO", + // "DGO/LCTYPROT.DGO", + // "DGO/DESHOVER.DGO", + // "DGO/DESBOSS2.DGO" ], // some objects are part of STR files (streaming data). diff --git a/decompiler/config/jak3/ntsc_v1/label_types.jsonc b/decompiler/config/jak3/ntsc_v1/label_types.jsonc index 0967ef424b..93d44d5baa 100644 --- a/decompiler/config/jak3/ntsc_v1/label_types.jsonc +++ b/decompiler/config/jak3/ntsc_v1/label_types.jsonc @@ -1 +1,6 @@ -{} +{ + "math": [ + ["L108", "(pointer float)", 32], + ["L109", "(pointer float)", 32] + ] +} diff --git a/decompiler/config/jak3/ntsc_v1/stack_structures.jsonc b/decompiler/config/jak3/ntsc_v1/stack_structures.jsonc index 0967ef424b..5a9b6435ee 100644 --- a/decompiler/config/jak3/ntsc_v1/stack_structures.jsonc +++ b/decompiler/config/jak3/ntsc_v1/stack_structures.jsonc @@ -1 +1,4 @@ -{} +{ + "quaternion-smooth-seek!": [[16, "quaternion"]], + "eul->matrix": [[16, "vector"]] +} diff --git a/decompiler/config/jak3/ntsc_v1/type_casts.jsonc b/decompiler/config/jak3/ntsc_v1/type_casts.jsonc index 35ff179ab6..37815a5a7e 100644 --- a/decompiler/config/jak3/ntsc_v1/type_casts.jsonc +++ b/decompiler/config/jak3/ntsc_v1/type_casts.jsonc @@ -33,5 +33,24 @@ "(method 0 process)": [ // [11, "a0", "int"], // [[12, 45], "v0", "process"] + ], + "logf": [ + [12, "f0", "float"], + [12, "f1", "float"], + [19, "f0", "float"], + [19, "f1", "float"] + ], + "log2f": [ + [12, "f0", "float"], + [12, "f1", "float"], + [19, "f0", "float"], + [19, "f1", "float"] + ], + "cube-root": [ + [17, "f0", "float"], + [17, "f1", "float"], + [18, "f0", "float"], + [18, "f1", "float"], + [[23, 32], "f0", "float"] ] } diff --git a/decompiler/config/jak3/ntsc_v1/var_names.jsonc b/decompiler/config/jak3/ntsc_v1/var_names.jsonc index 0967ef424b..e72d67eb04 100644 --- a/decompiler/config/jak3/ntsc_v1/var_names.jsonc +++ b/decompiler/config/jak3/ntsc_v1/var_names.jsonc @@ -1 +1,28 @@ -{} +{ + "matrix-transpose!": { + "args": [ + "dst", + "src" + ] + }, + "matrix-axis-sin-cos!": { + "args": [ + "dst", + "axis", + "s", + "c" + ] + }, + "vector-rad<-vector-deg/2!": { + "args": [ + "out", + "in" + ] + }, + "vector-rad<-vector-deg!": { + "args": [ + "out", + "in" + ] + } +} \ No newline at end of file diff --git a/goal_src/jak3/build/all_objs.json b/goal_src/jak3/build/all_objs.json index 290d02e75b..917c7eced9 100644 --- a/goal_src/jak3/build/all_objs.json +++ b/goal_src/jak3/build/all_objs.json @@ -22,7 +22,7 @@ ["transformq-h", "transformq-h", 5, ["GAME"], "engine/math"], ["bounding-box", "bounding-box", 5, ["GAME"], "engine/geometry"], ["matrix", "matrix", 5, ["GAME"], "engine/math"], -["matrix-compose", "matrix-compose", 5, ["GAME"], "engine/common-obs"], +["matrix-compose", "matrix-compose", 5, ["GAME"], "engine/math"], ["transform", "transform", 5, ["GAME"], "engine/math"], ["quaternion", "quaternion", 5, ["GAME"], "engine/math"], ["euler", "euler", 5, ["GAME"], "engine/math"], diff --git a/goal_src/jak3/engine/common-obs/matrix-compose.gc b/goal_src/jak3/engine/common-obs/matrix-compose.gc deleted file mode 100644 index b17e2ac832..0000000000 --- a/goal_src/jak3/engine/common-obs/matrix-compose.gc +++ /dev/null @@ -1,9 +0,0 @@ -;;-*-Lisp-*- -(in-package goal) - -;; name: matrix-compose.gc -;; name in dgo: matrix-compose -;; dgos: GAME - -;; DECOMP BEGINS - diff --git a/goal_src/jak3/engine/geometry/bounding-box-h.gc b/goal_src/jak3/engine/geometry/bounding-box-h.gc index 1a1f7437ef..aadb4b65c0 100644 --- a/goal_src/jak3/engine/geometry/bounding-box-h.gc +++ b/goal_src/jak3/engine/geometry/bounding-box-h.gc @@ -7,3 +7,52 @@ ;; DECOMP BEGINS +(deftype bounding-box (structure) + ((min vector :inline) + (max vector :inline) + ) + (:methods + (add-spheres! (_type_ (inline-array sphere) int) int) + (add-box! (_type_ bounding-box) int) + (add-point! (_type_ vector) none) + (intersects-line-segment? (_type_ vector vector) symbol) + (set-from-point-offset! (_type_ vector vector) none) + (set-from-point-offset-pad! (_type_ vector vector float) int) + (set-to-point! (_type_ vector) none) + (set-from-sphere! (_type_ sphere) none) + (set-from-spheres! (_type_ (inline-array sphere) int) int) + (get-bounding-sphere (_type_ vector) vector) + (inside-xyz? (bounding-box vector) symbol) + (inside-xz? (bounding-box vector) symbol) + ) + ) + + +(deftype bounding-box2 (structure) + ((min vector2 :inline) + (max vector2 :inline) + ) + ) + + +(deftype bounding-box4w (structure) + ((min vector4w :inline) + (max vector4w :inline) + ) + ) + + +(deftype bounding-box-both (structure) + ((box bounding-box :inline) + (box4w bounding-box4w :inline) + ) + ) + + +(deftype bounding-box-array (inline-array-class) + ((data bounding-box :dynamic) + ) + ) + + +(set! (-> bounding-box-array heap-base) (the-as uint 32)) diff --git a/goal_src/jak3/engine/geometry/bounding-box.gc b/goal_src/jak3/engine/geometry/bounding-box.gc index 167a381ef7..e0d8dab58e 100644 --- a/goal_src/jak3/engine/geometry/bounding-box.gc +++ b/goal_src/jak3/engine/geometry/bounding-box.gc @@ -7,3 +7,314 @@ ;; DECOMP BEGINS +(defmethod inside-xyz? ((this bounding-box) (arg0 vector)) + "Is the point in the box?" + (and (< (-> this min x) (-> arg0 x)) + (< (-> this min y) (-> arg0 y)) + (< (-> this min z) (-> arg0 z)) + (< (-> arg0 x) (-> this max x)) + (< (-> arg0 y) (-> this max y)) + (< (-> arg0 z) (-> this max z)) + ) + ) + +(defmethod inside-xz? ((this bounding-box) (arg0 vector)) + "Is the point in the box? Check xz only." + (and (< (-> this min x) (-> arg0 x)) + (< (-> this min z) (-> arg0 z)) + (< (-> arg0 x) (-> this max x)) + (< (-> arg0 z) (-> this max z)) + ) + ) + +(defun box-vector-enside? ((arg0 bounding-box) (arg1 vector)) + "Is the point in the box? On the edge doesn't count." + (and (< (-> arg0 min x) (-> arg1 x)) + (< (-> arg0 min y) (-> arg1 y)) + (< (-> arg0 min z) (-> arg1 z)) + (< (-> arg1 x) (-> arg0 max x)) + (< (-> arg1 y) (-> arg0 max y)) + (< (-> arg1 z) (-> arg0 max z)) + ) + ) + +(defun box-vector-inside? ((arg0 bounding-box) (arg1 vector)) + "Is the point in the box? On the edge counts." + (and (>= (-> arg1 x) (-> arg0 min x)) + (>= (-> arg1 y) (-> arg0 min y)) + (>= (-> arg1 z) (-> arg0 min z)) + (>= (-> arg0 max x) (-> arg1 x)) + (>= (-> arg0 max y) (-> arg1 y)) + (>= (-> arg0 max z) (-> arg1 z)) + ) + ) + +(defmethod set-from-point-offset! ((this bounding-box) (arg0 vector) (arg1 vector)) + "Set to the smallest box containing arg0, (arg0 + arg1)" + (rlet ((vf0 :class vf) + (vf1 :class vf) + (vf2 :class vf) + (vf3 :class vf) + (vf4 :class vf) + (vf5 :class vf) + ) + (init-vf0-vector) + (.lvf vf3 (&-> arg1 quad)) + (.lvf vf4 (&-> arg0 quad)) + (.add.vf vf5 vf4 vf3) + (.min.vf vf1 vf4 vf5) + (.max.vf vf2 vf4 vf5) + (.mov.vf vf1 vf0 :mask #b1000) + (.mov.vf vf2 vf0 :mask #b1000) + (.svf (&-> this min quad) vf1) + (.svf (&-> this max quad) vf2) + 0 + (none) + ) + ) + +(defmethod add-point! ((this bounding-box) (arg0 vector)) + "Expand the box as needed to contain the given point." + (rlet ((vf1 :class vf) + (vf2 :class vf) + (vf3 :class vf) + ) + (.lvf vf1 (&-> this min quad)) + (.lvf vf2 (&-> this max quad)) + (.lvf vf3 (&-> arg0 quad)) + (.min.vf vf1 vf1 vf3) + (.max.vf vf2 vf2 vf3) + (.svf (&-> this min quad) vf1) + (.svf (&-> this max quad) vf2) + 0 + (none) + ) + ) + +(defmethod add-box! ((this bounding-box) (arg0 bounding-box)) + "Expand the box as needed to contain the given box." + (rlet ((vf1 :class vf) + (vf2 :class vf) + (vf3 :class vf) + (vf4 :class vf) + ) + (.lvf vf1 (&-> this min quad)) + (.lvf vf2 (&-> this max quad)) + (.lvf vf3 (&-> arg0 min quad)) + (.lvf vf4 (&-> arg0 max quad)) + (.min.vf vf1 vf1 vf3) + (.max.vf vf2 vf2 vf4) + (.svf (&-> this min quad) vf1) + (.svf (&-> this max quad) vf2) + 0 + ) + ) + +(defmethod set-to-point! ((this bounding-box) (arg0 vector)) + "Set the box to be a single point." + (set! (-> this min quad) (-> arg0 quad)) + (set! (-> this max quad) (-> arg0 quad)) + 0 + (none) + ) + +(defmethod set-from-point-offset-pad! ((this bounding-box) (arg0 vector) (arg1 vector) (arg2 float)) + "Set the box to contain arg0, arg0 + offset, with some padding." + (rlet ((vf0 :class vf) + (vf1 :class vf) + (vf2 :class vf) + (vf3 :class vf) + (vf4 :class vf) + (vf5 :class vf) + (vf6 :class vf) + ) + (init-vf0-vector) + (.lvf vf4 (&-> arg1 quad)) + (.lvf vf5 (&-> arg0 quad)) + (.mov vf1 arg2) + (.add.vf vf6 vf5 vf4) + (.min.vf vf2 vf5 vf6) + (.max.vf vf3 vf5 vf6) + (.add.x.vf vf3 vf3 vf1 :mask #b111) + (.sub.x.vf vf2 vf2 vf1 :mask #b111) + (.mov.vf vf2 vf0 :mask #b1000) + (.mov.vf vf3 vf0 :mask #b1000) + (.svf (&-> this min quad) vf2) + (.svf (&-> this max quad) vf3) + 0 + ) + ) + +(defmethod set-from-sphere! ((this bounding-box) (arg0 sphere)) + "Set the box to contain a single sphere." + (rlet ((vf0 :class vf) + (vf1 :class vf) + (vf2 :class vf) + (vf3 :class vf) + ) + (init-vf0-vector) + (.lvf vf1 (&-> arg0 quad)) + (.sub.w.vf vf2 vf1 vf1 :mask #b111) + (.add.w.vf vf3 vf1 vf1 :mask #b111) + (.mov.vf vf2 vf0 :mask #b1000) + (.mov.vf vf3 vf0 :mask #b1000) + (.svf (&-> this min quad) vf2) + (.svf (&-> this max quad) vf3) + 0 + (none) + ) + ) + +;;;;;;;;;;;;;;;;;;;;;;;;; +;; multi-sphere methods +;;;;;;;;;;;;;;;;;;;;;;;;; + +;; these are used in the collision system to build bounding boxes around collision geometries, so they are quite optimized. + +(defmethod add-spheres! ((this bounding-box) (spheres (inline-array sphere)) (count int)) + "Add count spheres." + ;; the PS2 implementation is very optimized + ;; It is unrolled and 'software pipelined' to do 4 at a time. + ;; This is slightly less optimized. + (rlet ((current-min :class vf) + (current-max :class vf) + (sph-min :class vf) + (sph-max :class vf) + (sph :class vf)) + + (when (nonzero? count) + ;; load these outside the loop + (.lvf current-min (-> this min)) + (.lvf current-max (-> this max)) + + (dotimes (i count) + (.lvf sph (-> spheres i)) + (.sub.w.vf sph-min sph sph :mask #b111) + (.add.w.vf sph-max sph sph :mask #b111) + (.min.vf current-min current-min sph-min :mask #b111) + (.max.vf current-max current-max sph-max :mask #b111) + ) + + (.svf (-> this min) current-min) + (.svf (-> this max) current-max) + ) + ) + 0 + ) + +(defmethod set-from-spheres! ((this bounding-box) (spheres (inline-array sphere)) (count int)) + "Reset box to hold the given spheres. Note: this implementation could be optimized." + ;; This is also unrolled, but does 7 at a time. + (rlet ((vf0 :class vf) + (current-min :class vf) + (current-max :class vf) + (sph-min :class vf) + (sph-max :class vf) + (sph :class vf)) + ;; init constant + (init-vf0-vector) + ;; init min/max. in the case we don't have any spheres, we should return (0,0,0,1) for min/max. + (set! current-min vf0) + (set! current-max vf0) + + (dotimes (i count) + (.lvf sph (-> spheres i)) + (.sub.w.vf sph-min sph sph :mask #b111) + (.add.w.vf sph-max sph sph :mask #b111) + (cond + ((zero? i) + (set! current-min sph-min) + (set! current-max sph-max) + ) + (else + (.min.vf current-min current-min sph-min :mask #b111) + (.max.vf current-max current-max sph-max :mask #b111) + ) + ) + ) + + (.svf (-> this min) current-min) + (.svf (-> this max) current-max) + ) + 0 + ) + +(defmethod get-bounding-sphere ((this bounding-box) (arg0 vector)) + "Get a bounding sphere for a bounding box." + (let* ((a1-2 (vector-! (new 'stack-no-clear 'vector) (-> this max) (-> this min))) + (a0-3 (vector-float*! (new 'stack-no-clear 'vector) a1-2 0.5)) + ) + (vector+! arg0 (-> this min) a0-3) + (set! (-> arg0 w) (vector-length a0-3)) + ) + arg0 + ) + +(deftype liang-barsky-line-clip-params (structure) + ((te float) + (tl float) + ) + ) + + +(defun liang-barsky-line-clipt ((arg0 liang-barsky-line-clip-params) (arg1 float) (arg2 float)) + "Clip test in 1 dimension. Is arg1 in arg2?" + (cond + ((< 0.0 arg1) + (let ((f0-2 (/ arg2 arg1))) + (if (< (-> arg0 tl) f0-2) + (return #f) + ) + (if (< (-> arg0 te) f0-2) + (set! (-> arg0 te) f0-2) + ) + ) + ) + ((< arg1 0.0) + (let ((f0-5 (/ arg2 arg1))) + (if (< f0-5 (-> arg0 te)) + (return #f) + ) + (if (< f0-5 (-> arg0 tl)) + (set! (-> arg0 tl) f0-5) + ) + ) + ) + (else + (if (< 0.0 arg2) + (return #f) + ) + ) + ) + #t + ) + +;; WARN: disable def twice: 23. This may happen when a cond (no else) is nested inside of another conditional, but it should be rare. +(defmethod intersects-line-segment? ((this bounding-box) (arg0 vector) (arg1 vector)) + "Check intersection in xz plane, using liang-barsky. Not sure if this actually +a useful check or not..." + (let ((f28-0 (- (-> arg1 x) (-> arg0 x))) + (f30-0 (- (-> arg1 z) (-> arg0 z))) + ) + (cond + ((and (= f28-0 0.0) (= f30-0 0.0)) + (let ((f1-2 (-> arg0 x)) + (f0-4 (-> arg0 z)) + ) + (and (>= f1-2 (-> this min x)) (>= (-> this max x) f1-2) (>= f0-4 (-> this min z)) (>= (-> this max z) f0-4)) + ) + ) + (else + (let ((s4-0 (new 'stack-no-clear 'liang-barsky-line-clip-params))) + (set! (-> s4-0 te) 0.0) + (set! (-> s4-0 tl) 1.0) + (and (liang-barsky-line-clipt s4-0 f28-0 (- (-> this min x) (-> arg0 x))) + (liang-barsky-line-clipt s4-0 (- f28-0) (- (-> arg0 x) (-> this max x))) + (liang-barsky-line-clipt s4-0 f30-0 (- (-> this min z) (-> arg0 z))) + (liang-barsky-line-clipt s4-0 (- f30-0) (- (-> arg0 z) (-> this max z))) + ) + ) + ) + ) + ) + ) diff --git a/goal_src/jak3/engine/geometry/geometry-h.gc b/goal_src/jak3/engine/geometry/geometry-h.gc index 4a1da90df5..47aff72fe1 100644 --- a/goal_src/jak3/engine/geometry/geometry-h.gc +++ b/goal_src/jak3/engine/geometry/geometry-h.gc @@ -5,5 +5,65 @@ ;; name in dgo: geometry-h ;; dgos: GAME +(define-extern quaternion-from-two-vectors-max-angle! (function quaternion vector vector float quaternion)) +(define-extern vector-orient-by-quat! (function vector vector quaternion vector)) + ;; DECOMP BEGINS +(deftype curve (structure) + ((cverts (inline-array vector)) + (num-cverts int32) + (knots (pointer float)) + (num-knots int32) + (length float) + ) + ) + + +(deftype line-intersection-val (structure) + ((tt0 float) + (tt1 float) + ) + ) + + +(deftype border-plane (basic) + ((name symbol) + (action basic) + (slot int8) + (trans vector :inline) + (normal vector :inline) + ) + (:methods + (debug-draw (_type_) int) + (point-past-plane? (_type_ vector) symbol) + ) + ) + + +(deftype lissajous (structure) + ((x-mag float) + (y-mag float) + (theta float) + (wx float) + (wy float) + (period-shift float) + (theta-rate float) + ) + :pack-me + (:methods + (lissajous-method-9 (_type_ vector) vector) + ) + ) + + +(deftype lissajous-interp (structure) + ((current lissajous :inline) + (dest lissajous :inline) + (rate lissajous :inline) + ) + (:methods + (lissajous-interp-method-9 (_type_ vector) vector) + (lissajous-interp-method-10 (_type_) float) + ) + ) diff --git a/goal_src/jak3/engine/math/euler-h.gc b/goal_src/jak3/engine/math/euler-h.gc index b510493495..327dc1684e 100644 --- a/goal_src/jak3/engine/math/euler-h.gc +++ b/goal_src/jak3/engine/math/euler-h.gc @@ -7,3 +7,18 @@ ;; DECOMP BEGINS +(define EulSafe + "Maybe euler angle storage orders? +What is this naming convention?" + (new 'static 'boxed-array :type int32 0 1 2 0) + ) + +(define EulNext (new 'static 'boxed-array :type int32 1 2 0 1)) + +(deftype euler-angles (vector) + "Just uses the same xyzw and data array as vector. +The `w` stores an integer that seems to have +bitfields for... something? Like maybe the order? +Euler angles are mostly unused, and the code is a bit of disaster." + () + ) diff --git a/goal_src/jak3/engine/math/euler.gc b/goal_src/jak3/engine/math/euler.gc index 256d53387b..54eb813642 100644 --- a/goal_src/jak3/engine/math/euler.gc +++ b/goal_src/jak3/engine/math/euler.gc @@ -7,3 +7,209 @@ ;; DECOMP BEGINS +(defun set-eul! ((arg0 euler-angles) (arg1 float) (arg2 float) (arg3 float) (arg4 int)) + "Set euler angles and the flag bits." + (set! (-> arg0 x) arg1) + (set! (-> arg0 y) arg2) + (set! (-> arg0 z) arg3) + (set! (-> arg0 w) (the float arg4)) + arg0 + ) + +(defun eul->matrix ((arg0 matrix) (arg1 euler-angles)) + "Convert from euler angles to 4x4 matrix." + (matrix-identity! arg0) + (let ((s5-0 (new 'stack-no-clear 'vector))) + (set! (-> s5-0 quad) (-> arg1 quad)) + (when (= (logand (the int (-> s5-0 w)) 1) 1) + (let ((f0-2 (-> s5-0 x))) + (set! (-> s5-0 x) (-> s5-0 z)) + (set! (-> s5-0 z) f0-2) + ) + ) + (when (= (logand (/ (the int (-> s5-0 w)) 4) 1) 1) + (set! (-> s5-0 x) (- (-> s5-0 x))) + (set! (-> s5-0 y) (- (-> s5-0 y))) + (set! (-> s5-0 z) (- (-> s5-0 z))) + ) + (let* ((f26-0 (cos (-> s5-0 x))) + (f30-0 (cos (-> s5-0 y))) + (f22-0 (cos (-> s5-0 z))) + (f24-0 (sin (-> s5-0 x))) + (f28-0 (sin (-> s5-0 y))) + (f4-0 (sin (-> s5-0 z))) + (f0-17 (* f26-0 f22-0)) + (f1-1 (* f26-0 f4-0)) + (f2-0 (* f24-0 f22-0)) + (f3-0 (* f24-0 f4-0)) + ) + 0 + 0 + 0 + (let* ((v1-12 (logand (/ (the int (-> s5-0 w)) 4) 1)) + (a1-2 (-> EulSafe (logand (/ (the int (-> s5-0 w)) 8) 3))) + (a0-21 (-> EulNext (+ a1-2 v1-12))) + (v1-17 (-> EulNext (+ (- 1 v1-12) a1-2))) + ) + (cond + ((= (logand (/ (the int (-> s5-0 w)) 2) 1) 1) + (set! (-> (the-as (pointer float) (+ (+ (* a1-2 16) (* a1-2 4)) (the-as int arg0)))) f30-0) + (set! (-> (the-as (pointer float) (+ (+ (* a1-2 16) (* a0-21 4)) (the-as int arg0)))) (* f28-0 f24-0)) + (set! (-> (the-as (pointer float) (+ (+ (* a1-2 16) (* v1-17 4)) (the-as int arg0)))) (* f28-0 f26-0)) + (set! (-> (the-as (pointer float) (+ (+ (* a0-21 16) (* a1-2 4)) (the-as int arg0)))) (* f28-0 f4-0)) + (set! (-> (the-as (pointer float) (+ (+ (* a0-21 16) (* a0-21 4)) (the-as int arg0)))) + (- f0-17 (* f30-0 f3-0)) + ) + (set! (-> (the-as (pointer float) (+ (+ (* a0-21 16) (* v1-17 4)) (the-as int arg0)))) + (- (- f2-0) (* f30-0 f1-1)) + ) + (set! (-> (the-as (pointer float) (+ (+ (* v1-17 16) (* a1-2 4)) (the-as int arg0)))) (- (* f28-0 f22-0))) + (set! (-> (the-as (pointer float) (+ (+ (* v1-17 16) (* a0-21 4)) (the-as int arg0)))) + (+ f1-1 (* f30-0 f2-0)) + ) + (set! (-> (the-as (pointer float) (+ (+ (* v1-17 16) (* v1-17 4)) (the-as int arg0)))) + (+ (- f3-0) (* f30-0 f0-17)) + ) + ) + (else + (set! (-> (the-as (pointer float) (+ (+ (* a1-2 16) (* a1-2 4)) (the-as int arg0)))) (* f30-0 f22-0)) + (set! (-> (the-as (pointer float) (+ (+ (* a1-2 16) (* a0-21 4)) (the-as int arg0)))) + (+ (- f1-1) (* f28-0 f2-0)) + ) + (set! (-> (the-as (pointer float) (+ (+ (* a1-2 16) (* v1-17 4)) (the-as int arg0)))) + (+ f3-0 (* f28-0 f0-17)) + ) + (set! (-> (the-as (pointer float) (+ (+ (* a0-21 16) (* a1-2 4)) (the-as int arg0)))) (* f30-0 f4-0)) + (set! (-> (the-as (pointer float) (+ (+ (* a0-21 16) (* a0-21 4)) (the-as int arg0)))) + (+ f0-17 (* f28-0 f3-0)) + ) + (set! (-> (the-as (pointer float) (+ (+ (* a0-21 16) (* v1-17 4)) (the-as int arg0)))) + (+ (- f2-0) (* f28-0 f1-1)) + ) + (set! (-> (the-as (pointer float) (+ (+ (* v1-17 16) (* a1-2 4)) (the-as int arg0)))) (- f28-0)) + (set! (-> (the-as (pointer float) (+ (+ (* v1-17 16) (* a0-21 4)) (the-as int arg0)))) (* f30-0 f24-0)) + (set! (-> (the-as (pointer float) (+ (+ (* v1-17 16) (* v1-17 4)) (the-as int arg0)))) (* f30-0 f26-0)) + ) + ) + ) + ) + ) + arg0 + ) + +(defun matrix->eul ((arg0 euler-angles) (arg1 matrix) (arg2 int)) + "Convert matrix to euler angles with given order flag. +Not clear how this works if the matrix has more than just a rotation." + 0 + 0 + 0 + (let* ((v1-4 (logand (/ arg2 4) 1)) + (s3-0 (-> EulSafe (logand (/ arg2 8) 3))) + (s2-0 (-> EulNext (+ s3-0 v1-4))) + (s1-0 (-> EulNext (+ (- 1 v1-4) s3-0))) + ) + (cond + ((= (logand (/ arg2 2) 1) 1) + (let* ((f0-0 (-> (the-as (pointer float) (+ (+ (* s2-0 4) (* s3-0 16)) (the-as int arg1))))) + (f0-2 (* f0-0 f0-0)) + (f1-0 (-> (the-as (pointer float) (+ (+ (* s1-0 4) (* s3-0 16)) (the-as int arg1))))) + (f30-0 (sqrtf (+ f0-2 (* f1-0 f1-0)))) + ) + (cond + ((< 0.00000000001 f30-0) + (set! (-> arg0 x) (atan + (-> (the-as (pointer float) (+ (+ (* s2-0 4) (* s3-0 16)) (the-as int arg1)))) + (-> (the-as (pointer float) (+ (+ (* s1-0 4) (* s3-0 16)) (the-as int arg1)))) + ) + ) + (set! (-> arg0 y) (atan f30-0 (-> (the-as (pointer float) (+ (+ (* s3-0 4) (* s3-0 16)) (the-as int arg1)))))) + (set! (-> arg0 z) (atan + (-> (the-as (pointer float) (+ (+ (* s3-0 4) (* s2-0 16)) (the-as int arg1)))) + (- (-> (the-as (pointer float) (+ (+ (* s3-0 4) (* s1-0 16)) (the-as int arg1))))) + ) + ) + ) + (else + (set! (-> arg0 x) (atan + (- (-> (the-as (pointer float) (+ (+ (* s1-0 4) (* s2-0 16)) (the-as int arg1))))) + (-> (the-as (pointer float) (+ (+ (* s2-0 4) (* s2-0 16)) (the-as int arg1)))) + ) + ) + (set! (-> arg0 y) (atan f30-0 (-> (the-as (pointer float) (+ (+ (* s3-0 4) (* s3-0 16)) (the-as int arg1)))))) + (set! (-> arg0 z) 0.0) + ) + ) + ) + ) + (else + (let* ((f0-21 (-> (the-as (pointer float) (+ (+ (* s3-0 4) (* s3-0 16)) (the-as int arg1))))) + (f0-23 (* f0-21 f0-21)) + (f1-3 (-> (the-as (pointer float) (+ (+ (* s3-0 4) (* s2-0 16)) (the-as int arg1))))) + (f30-1 (sqrtf (+ f0-23 (* f1-3 f1-3)))) + ) + (cond + ((< 0.00000000001 f30-1) + (set! (-> arg0 x) + (atan + (-> (the-as (pointer float) (+ (+ (* s2-0 4) (* s1-0 16)) (the-as int arg1)))) + (-> (the-as (pointer float) (+ (+ (* s1-0 4) (* s1-0 16)) (the-as int arg1)))) + ) + ) + (set! (-> arg0 y) + (atan (- (-> (the-as (pointer float) (+ (+ (* s3-0 4) (* s1-0 16)) (the-as int arg1))))) f30-1) + ) + (set! (-> arg0 z) (atan + (-> (the-as (pointer float) (+ (+ (* s3-0 4) (* s2-0 16)) (the-as int arg1)))) + (-> (the-as (pointer float) (+ (+ (* s3-0 4) (* s3-0 16)) (the-as int arg1)))) + ) + ) + ) + (else + (set! (-> arg0 x) + (atan + (- (-> (the-as (pointer float) (+ (+ (* s1-0 4) (* s2-0 16)) (the-as int arg1))))) + (-> (the-as (pointer float) (+ (+ (* s2-0 4) (* s2-0 16)) (the-as int arg1)))) + ) + ) + (set! (-> arg0 y) + (atan (- (-> (the-as (pointer float) (+ (+ (* s3-0 4) (* s1-0 16)) (the-as int arg1))))) f30-1) + ) + (set! (-> arg0 z) 0.0) + ) + ) + ) + ) + ) + ) + (when (= (logand (/ arg2 4) 1) 1) + (set! (-> arg0 x) (- (-> arg0 x))) + (set! (-> arg0 y) (- (-> arg0 y))) + (set! (-> arg0 z) (- (-> arg0 z))) + ) + (when (= (logand arg2 1) 1) + (let ((f0-49 (-> arg0 x))) + (set! (-> arg0 x) (-> arg0 z)) + (set! (-> arg0 z) f0-49) + ) + ) + (set! (-> arg0 w) (the float arg2)) + arg0 + ) + +(defun eul->quat ((arg0 quaternion) (arg1 euler-angles)) + "Convert euler angles to quaternion, not very efficient." + (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 with given order, not very efficient." + (let ((s5-0 (new 'stack-no-clear 'matrix))) + (quaternion->matrix s5-0 arg1) + (matrix->eul arg0 s5-0 arg2) + ) + arg0 + ) diff --git a/goal_src/jak3/engine/math/math.gc b/goal_src/jak3/engine/math/math.gc index ff628b938d..53a8ecc86b 100644 --- a/goal_src/jak3/engine/math/math.gc +++ b/goal_src/jak3/engine/math/math.gc @@ -5,5 +5,907 @@ ;; name in dgo: math ;; dgos: GAME +(defmacro init-vf0-vector () + "Initializes the VF0 vector which is a constant vector in the VU set to <0,0,0,1>" + `(.lvf vf0 (new 'static 'vector :x 0.0 :y 0.0 :z 0.0 :w 1.0)) + ) + ;; DECOMP BEGINS +(defun truncate ((arg0 float)) + "Round (toward zero) to an integer. +@param arg0 float to truncate" + (the float (the int arg0)) + ) + +(defun round ((arg0 float)) + "Round to the nearest integer" + (the float (the int (+ 0.5 arg0))) + ) + +(defun floor ((arg0 float)) + "Round (down) to an integer" + (let ((f0-3 (the float (the int arg0)))) + (if (or (>= arg0 0.0) (= arg0 f0-3)) + f0-3 + (+ -1.0 f0-3) + ) + ) + ) + +(defun ceil ((arg0 float)) + "Round (up) to an integer" + (let ((f0-3 (the float (the int arg0)))) + (if (or (>= 0.0 arg0) (= arg0 f0-3)) + f0-3 + (+ 1.0 f0-3) + ) + ) + ) + +(defun integral? ((arg0 float)) + "Is this number an integer?" + (= (the float (the int arg0)) arg0) + ) + +(defun fractional-part ((arg0 float)) + "Get the fractional part of a float." + (- arg0 (the float (the int arg0))) + ) + +(defun odd? ((arg0 int)) + "Is the number odd?" + (= (logand arg0 1) 1) + ) + +(defun even? ((arg0 int)) + "Is the number even?" + (not (odd? arg0)) + ) + +(defun sawtooth-wave ((arg0 float)) + "Sample a sawtooth with period 1. In range (0, 1)" + (let ((f0-2 (- arg0 (the float (the int arg0))))) + (if (< f0-2 0.0) + (set! f0-2 (+ 1.0 f0-2)) + ) + f0-2 + ) + ) + +(defun triangle-wave ((arg0 float)) + "Sample a triangle wave. Period is 4, in range (-1, 1) (so slope is 1 or -1)." + (let* ((f0-1 (* 0.25 (+ -1.0 arg0))) + (f0-3 (- f0-1 (the float (the int f0-1)))) + ) + (if (< f0-3 0.0) + (set! f0-3 (+ 1.0 f0-3)) + ) + (+ -1.0 (fabs (+ -2.0 (* 4.0 f0-3)))) + ) + ) + +(defun log-x-plus-1-order9 ((arg0 float)) + "Fast approximation of ln(x + 1). Probably only accurate for x in [0, 1]." + (* arg0 + (+ 1.0 + (* arg0 + (+ -0.5 + (* arg0 + (+ 0.33333334 + (* arg0 + (+ -0.25 + (* arg0 (+ 0.2 (* arg0 (+ -0.16666666 (* arg0 (+ 0.14285715 (* arg0 (+ -0.125 (* 0.11111111 arg0))))))))) + ) + ) + ) + ) + ) + ) + ) + ) + ) + +(defun logf ((arg0 float)) + "Natural log." + (let ((v1-1 (the-as int (+ (shr (the-as int arg0) 23) -126))) + (a0-2 (the-as number (logior #x3f000000 (logand (the-as uint #x807fffff) (the-as uint arg0))))) + ) + ;; og:preserve-this + (when (< (the-as float a0-2) 0.70710677) + (set! a0-2 (+ (the-as float a0-2) (the-as float a0-2))) + (set! v1-1 (the-as int (+ (the-as uint v1-1) -1))) + ) + (let ((f0-5 (+ -1.0 (the-as float a0-2)))) + (+ (* f0-5 + (+ 1.0 + (* f0-5 + (+ -0.5 + (* f0-5 + (+ 0.33333334 + (* f0-5 + (+ -0.25 + (* f0-5 (+ 0.2 (* f0-5 (+ -0.16666666 (* f0-5 (+ 0.14285715 (* f0-5 (+ -0.125 (* 0.11111111 f0-5))))))))) + ) + ) + ) + ) + ) + ) + ) + ) + (* 0.6931472 (the float v1-1)) + ) + ) + ) + ) + +(defun log2f ((arg0 float)) + "Log base 2." + (let ((v1-1 (the-as int (+ (shr (the-as int arg0) 23) -126))) + (a0-2 (the-as number (logior #x3f000000 (logand (the-as uint #x807fffff) (the-as uint arg0))))) + ) + ;; og:preserve-this + (when (< (the-as float a0-2) 0.70710677) + (set! a0-2 (+ (the-as float a0-2) (the-as float a0-2))) + (set! v1-1 (the-as int (+ (the-as uint v1-1) -1))) + ) + (let* ((f0-5 (+ -1.0 (the-as float a0-2))) + (f0-7 + (* f0-5 + (+ 1.0 + (* f0-5 + (+ -0.5 + (* f0-5 + (+ 0.33333334 + (* f0-5 + (+ -0.25 + (* f0-5 (+ 0.2 (* f0-5 (+ -0.16666666 (* f0-5 (+ 0.14285715 (* f0-5 (+ -0.125 (* 0.11111111 f0-5))))))))) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + (+ (* 1.442695 f0-7) (the float v1-1)) + ) + ) + ) + +(deftype float-type (uint32) + () + ) + +(define exp-slead (new 'static 'array float 32 + 1.0 + 1.0218964 + 1.0442734 + 1.0671387 + 1.0905075 + 1.1143799 + 1.1387863 + 1.1637192 + 1.1892014 + 1.2152405 + 1.2418518 + 1.2690506 + 1.2968369 + 1.3252335 + 1.354248 + 1.3839035 + 1.4142075 + 1.4451752 + 1.4768219 + 1.5091629 + 1.5422058 + 1.5759735 + 1.6104889 + 1.645752 + 1.6817856 + 1.7186127 + 1.7562485 + 1.7947083 + 1.8340073 + 1.8741608 + 1.9151993 + 1.9571381 + ) + ) + +(define exp-strail (new 'static 'array float 32 + 0.0 + 0.0000007863494 + 0.00000040596257 + 0.0000017288019 + 0.00000022534104 + 0.0000068597833 + 0.0000023188388 + 0.0000056815315 + 0.0000057600223 + 0.0000068814647 + 0.000006005433 + 0.0000003590472 + 0.0000027016238 + 0.000003183687 + 0.000007500062 + 0.000006378546 + 0.000006103877 + 0.0000056360786 + 0.0000042465254 + 0.0000015247614 + 0.000005014861 + 0.000007334366 + 0.0000014403477 + 0.000003525029 + 0.000007247011 + 0.000006627224 + 0.0000036862523 + 0.00000082304996 + 0.0000008232258 + 0.0000068675085 + 0.000007281612 + 0.000006062652 + ) + ) + +(defun exp ((arg float)) + "Compute e^x." + (local-vars + (f0 float) + (f1 float) + (f2 float) + (f3 float) + (f4 float) + (f5 float) + (f6 float) + (f7 float) + (f8 float) + (f10 float) + (f11 float) + (f12 float) + (f13 float) + (f14 float) + (f15 float) + (f16 float) + (f17 float) + (f18 float) + (a2 int) + (v0 float) + (v1 int) + (a1 int) + (a3 int) + (t0 int) + (a0-2 int) + ) + + (set! f0 arg) + (set! f0 (fabs f0)) + (set! f1 (the-as float #x435c6bba)) + ;;(b! (>=.s f1 f0) L44 (nop!)) + (when-goto (>= f1 f0) L44) + + (set! f0 0.0) + (set! f1 arg) + ;;(b! (>=.s f0 f1) L42 (nop!)) + (when-goto (>= f0 f1) L42) + + (set! v0 (the-as float #x7f7fffff)) + ;;(b! #t L43 (nop!)) + (goto L43) + + (label L42) + (set! v0 (the-as float #x0)) + + (label L43) + ;;(b! #t L49 (nop!)) + (goto L49) + + + (label L44) + (set! f1 (the-as float #x33000000)) + ;;(b! (>=.s f0 f1) L45 (nop!)) + (when-goto (>= f0 f1) L45) + + (set! f0 (the-as float #x3f800000)) + (set! f1 arg) + (set! f0 (+ f0 f1)) + (set! v0 f0) + ;;(b! #t L49 (nop!)) + (goto L49) + + (label L45) + (set! f16 (the-as float #x4238aa3b)) + (set! f12 (the-as float #x3cb17200)) + (set! f13 (the-as float #x333fbe8e)) + (set! f14 (the-as float #x3f000044)) + (set! f15 (the-as float #x3e2aaaec)) + (set! f0 arg) + (set! f0 (* f0 f16)) + ;;(set! f0 (f2i f0)) + ;;(set! a2 (fpr->gpr f0)) + (set! a2 (the int f0)) + (set! v1 (logand a2 31)) + (set! a1 (- a2 v1)) + (set! a3 512) + (set! t0 a2) + ;;(bl! (<0.si t0) L46 (no-delay!)) + ;;(set! t0 (- t0)) + (set! t0 (abs t0)) + + ;;(label L46) + ;;(b! (>=.si a3 t0) L47 (nop!)) + (when-goto (>= a3 t0) L47) + ;;(set! f17 a1) + ;;(set! f18 v1) + ;;(set! f17 (i2f f17)) + ;;(set! f18 (i2f f18)) + (set! f17 (the float a1)) + (set! f18 (the float v1)) + (set! f17 (* f17 f12)) + (set! f18 (* f18 f12)) + (set! f0 arg) + (set! f17 (- f0 f17)) + ;;(b! #t L48 (set! f2 (-.s f17 f18))) + (set! f2 (- f17 f18)) + (goto L48) + + (label L47) + ;;(set! f17 (gpr->fpr a2)) + ;;(set! f17 (i2f f17)) + (set! f17 (the float a2)) + (set! f17 (* f17 f12)) + (set! f0 arg) + (set! f2 (- f0 f17)) + + (label L48) + (set! a0-2 (- a2)) + ;;(set! f17 (gpr->fpr a0)) + ;;(set! f17 (i2f f17)) + (set! f17 (the float a0-2)) + (set! f3 (* f17 f13)) + (set! a0-2 (sar a1 5)) + (set! f4 (+ f2 f3)) + (set! f6 (* f4 f15)) + (set! f6 (+ f14 f6)) + (set! f6 (* f4 f6)) + (set! f6 (* f4 f6)) + (set! f5 (+ f3 f6)) + (set! f5 (+ f2 f5)) + ;;(set! a1 exp-slead) + ;;(set! a2 (sll v1 2)) + ;;(set! a1 (+ a1 a2)) + ;;(set! f10 (l.f a1)) + (set! f10 (-> exp-slead v1)) + ;;(set! a1 exp-strail) + ;;(set! v1 (sll v1 2)) + ;;(set! v1 (+ a1 v1)) + ;;(set! f11 (l.f v1)) + (set! f11 (-> exp-strail v1)) + (set! f7 (+ f10 f11)) + (set! f8 (* f7 f5)) + (set! f8 (+ f11 f8)) + (set! f8 (+ f8 f10)) + (set! v1 (the-as int f8)) + (set! a0-2 (logand a0-2 511)) + (set! a0-2 (shl a0-2 23)) + (set! v0 (the-as float (+ v1 a0-2))) + (label L49) + v0 + ) + +(defun pow ((arg0 float) (arg1 float)) + "Compute arg0^arg1" + (exp (* arg1 (logf arg0))) + ) + +(defun print-exp ((arg0 float)) + "Print in the format AeB where A is in the range (1, 10)" + (let* ((f30-1 (floor (/ (logf (fabs arg0)) (logf 10.0)))) + (f0-4 (pow 10.0 f30-1)) + ) + (format #t "~fe~d" (/ arg0 f0-4) (the int f30-1)) + ) + 0 + (none) + ) + +(deftype rgba (uint32) + () + ) + +(defmacro static-rgba (r g b a) + "make a new static rgba" + `(new 'static 'rgba :r ,r :g ,g :b ,b :a ,a) + ) + +(defmacro static-rgba-uint (col) + "make a new static rgba" + `(the-as rgba ,col) + ) + +(deftype xyzw (uint128) + () + ) + +(deftype xyzwh (uint128) + () + ) + +(defun print-time ((arg0 object) (arg1 time-frame)) + "Print a [[time-frame]] as h:mm:ss." + 0 + 0 + 0 + (let* ((f0-1 (* 0.0033333334 (the float arg1))) + (a2-0 (the int (* 0.016666668 f0-1))) + (f0-2 (- f0-1 (* 60.0 (the float a2-0)))) + (a3-0 (the int f0-2)) + (f0-3 (- f0-2 (the float a3-0))) + (t0-0 (the int (* 100.0 f0-3))) + ) + (format arg0 "~d:~2,'0,d:~2,'0,d" a2-0 a3-0 t0-0) + ) + 0 + (none) + ) + +;; WARN: Return type mismatch uint vs int. +(defun log2 ((arg0 int)) + "Log base 2." + (the-as int (+ (sar (the-as int (the float arg0)) 23) -127)) + ) + +(defun seek ((arg0 float) (arg1 float) (arg2 float)) + "Move arg0 toward arg1 by at most arg2." + (let ((f2-0 (- arg1 arg0))) + (cond + ((>= arg2 (fabs f2-0)) + arg1 + ) + ((>= f2-0 0.0) + (+ arg0 arg2) + ) + (else + (- arg0 arg2) + ) + ) + ) + ) + +(defun seek-ease ((arg0 float) (arg1 float) (arg2 float) (arg3 float) (arg4 float)) + "Move arg0 toward arg1, and slow down before reaching the end. +When farther than arg3 away, move by at most arg2. +When closer than arg3, linearly ramp down the movement amount from arg2 to 0 but no lower than arg4." + (let ((f2-0 (- arg1 arg0))) + (when (>= arg3 (fabs f2-0)) + (set! arg2 (* arg2 (- 1.0 (/ (- arg3 (fabs f2-0)) arg3)))) + (if (< arg2 arg4) + (set! arg2 arg4) + ) + ) + (cond + ((>= arg2 (fabs f2-0)) + arg1 + ) + ((>= f2-0 0.0) + (+ arg0 arg2) + ) + (else + (- arg0 arg2) + ) + ) + ) + ) + +(defun seek-ease-in-out ((arg0 float) (arg1 float) (arg2 float) (arg3 float) (arg4 float) (arg5 float) (arg6 float)) + "Move arg0 toward arg2, and slow down at the start and end. +When within arg4 of arg1 (at the beginning of movement), ramp up speed, with a minimum speed of arg6 +When within arg5 of arg2 (at the end of movement), ramp down speed, with a minimum speed of arg5 +Normally, move at most arg3" + (let ((f2-0 (- arg2 arg0))) + (let ((f4-1 (- arg0 arg1))) + (when (>= arg4 (fabs f4-1)) + (set! arg3 (* arg3 (- 1.0 (/ (- arg4 (fabs f4-1)) arg4)))) + (if (< arg3 arg6) + (set! arg3 arg6) + ) + ) + ) + (when (>= arg5 (fabs f2-0)) + (set! arg3 (* arg3 (- 1.0 (/ (- arg5 (fabs f2-0)) arg5)))) + (if (< arg3 arg6) + (set! arg3 arg6) + ) + ) + (cond + ((>= arg3 (fabs f2-0)) + arg2 + ) + ((>= f2-0 0.0) + (+ arg0 arg3) + ) + (else + (- arg0 arg3) + ) + ) + ) + ) + +(defun lerp ((arg0 float) (arg1 float) (arg2 float)) + "Linearly interpolate between arg0 and arg1." + (+ arg0 (* arg2 (- arg1 arg0))) + ) + +(defun-debug lerp-scale-old ((arg0 float) (arg1 float) (arg2 float) (arg3 float) (arg4 float)) + "Linearly remap arg2 in [arg3, arg4] to [arg0, arg1]. +This is the jak 1 implementation, which I claimed was a bad implementation..." + (let ((f0-1 (fmax 0.0 (fmin 1.0 (/ (- arg2 arg3) (- arg4 arg3)))))) + (+ (* (- 1.0 f0-1) arg0) (* f0-1 arg1)) + ) + ) + +;; ERROR: Unsupported inline assembly instruction kind - [mula.s f0, f2] +;; ERROR: Unsupported inline assembly instruction kind - [madd.s f0, f1, f3] +(defun lerp-scale ((arg0 float) (arg1 float) (arg2 float) (arg3 float) (arg4 float)) + "Linearly remap arg2 in [arg3, arg4] to [arg0, arg1]. +More efficient than the -old version." + (local-vars (f0-2 float)) + (let* ((v1-0 1.0) + (f1-0 0.0) + (f0-0 v1-0) + (f4-0 arg2) + (f2-0 arg3) + (f3-0 arg4) + (f1-2 (fmin (fmax (/ (- f4-0 f2-0) (- f3-0 f2-0)) f1-0) f0-0)) + (f0-1 (- f0-0 f1-2)) + (f2-3 arg0) + (f3-1 arg1) + ) + ;; og:preserve-this + ; (.mula.s f0-1 f2-3) + ; (.madd.s f0-2 f1-2 f3-1) + (+ (* f0-1 f2-3) (* f1-2 f3-1)) + ) + f0-2 + ) + +(defun lerp-scale-clamp ((arg0 float) (arg1 float) (arg2 float) (arg3 float) (arg4 float)) + "Clamp the input, then linearly remap arg2 in [arg3, arg4] to [arg0, arg1]." + (let ((a2-1 (fmax (fmin arg2 arg4) arg3))) + (lerp-scale arg0 arg1 a2-1 arg3 arg4) + ) + ) + +(defun lerp-clamp ((arg0 float) (arg1 float) (arg2 float)) + "Linearly interpolate between arg0 and arg1. arg2 is clamped to [0, 1]" + (cond + ((>= 0.0 arg2) + arg0 + ) + ((>= arg2 1.0) + arg1 + ) + (else + (+ (* (- 1.0 arg2) arg0) (* arg2 arg1)) + ) + ) + ) + +;; WARN: Return type mismatch int vs rgba. +(defun rgba-lerp ((arg0 rgba) (arg1 rgba) (arg2 rgba)) + (local-vars + (v0-0 uint128) + (v1-0 uint128) + (v1-1 uint128) + (a0-1 uint128) + (a0-2 uint128) + (a1-1 uint128) + (a2-1 uint128) + ) + (rlet ((acc :class vf) + (vf0 :class vf) + (vf1 :class vf) + (vf2 :class vf) + (vf3 :class vf) + ) + (init-vf0-vector) + (.pextlb v1-0 0 arg0) + (.pextlb a0-1 0 arg1) + (.pextlh v1-1 0 v1-0) + (.pextlh a0-2 0 a0-1) + (.mov vf1 v1-1) + (.mov vf2 a0-2) + (.mov vf3 arg2) + (.itof.vf vf1 vf1) + (.itof.vf vf2 vf2) + (.mul.w.vf acc vf1 vf0) + (.add.mul.x.vf acc vf2 vf3 acc) + (.sub.mul.x.vf vf1 vf1 vf3 acc) + (.ftoi.vf vf3 vf1) + (.mov a1-1 vf3) + (.ppach a2-1 (the-as uint128 0) a1-1) + (.ppacb v0-0 (the-as uint128 0) a2-1) + (the-as rgba v0-0) + ) + ) + +(defun seekl ((arg0 int) (arg1 int) (arg2 int)) + "Move arg0 toward arg1, by at most arg2." + (let* ((v1-0 (- arg1 arg0)) + (a3-0 (abs v1-0)) + ) + (cond + ((>= arg2 a3-0) + arg1 + ) + ((>= v1-0 0) + (+ arg0 arg2) + ) + (else + (- arg0 arg2) + ) + ) + ) + ) + +(defmacro seek! (place target rate) + "Macro to use seek in-place. place is the base, and where the result is stored." + `(set! ,place (seek ,place ,target ,rate)) + ) + +(defmacro seekl! (place target rate) + "Macro to use seekl in-place. place is the base, and where the result is stored." + `(set! ,place (seekl ,place ,target ,rate)) + ) + +(defmacro seek-ease! (place target rate min-threshold rate-min) + "Macro to use seek-ease in-place. place is the base, and where the result is stored." + `(set! ,place (seek-ease ,place ,target ,rate ,min-threshold ,rate-min)) + ) + +;; in the PS2 there is a R register for generating random numbers +;; it is a "32-bit" register, but the upper bits are fixed so it always +;; represents a float in (1, 2). +;; we don't have this register on x86, so we add a special global: *_vu-reg-R_* +(define *_vu-reg-R_* 0) + +(defun rand-vu-init ((seed float)) + "Initialize the VU0 random generator." + ;; (.ctc2.i R arg0) + ;; (.cfc2.i v0 R) + (set! *_vu-reg-R_* + (logior #x3F800000 (logand (the-as int seed) #x007FFFFF)) + ) + (the-as float *_vu-reg-R_*) + ) + +(rand-vu-init 1.418091) + +(defun rand-vu () + "Get a random number in [0, 1) and advance the random generator." + ;; (.vrget.xyzw vf1) - get current random + (let ((current-random *_vu-reg-R_*)) + ;; here they update the random generate with some junk + ;; for now, we don't do this in OpenGOAL. + ;; (.vsqrty Q vf1) + ;; (.vaddq.x vf2 vf0 Q) ;; you're not allowed to do this! + ;; (.vrxorw vf2) + + ;; and advance + ;; (.vrnext.xyzw vf1) + (let ((x (logand 1 (shr current-random 4))) + (y (logand 1 (shr current-random 22))) + ) + (set! current-random (shl current-random 1)) + (set! current-random (logxor current-random (logxor x y))) + (logxor! current-random (pc-rand)) + (set! *_vu-reg-R_* (logior #x3f800000 (logand current-random #x7fffff))) + ) + ) + + ;; (.vsubw.xyzw vf1 vf1 vf0) + ;; (.qmfc2.i v0 vf1) + (- (the-as float *_vu-reg-R_*) 1.0) + ) + +(defun rand-vu-nostep () + "Get the number currently in the random generator. + This will be equal to the last call of (rand-vu) + This will not update the random generator" + (- (the-as float *_vu-reg-R_*) 1.0) + ) + +(defun rand-vu-float-range ((arg0 float) (arg1 float)) + "Get a random float in between arg0 and arg1." + (+ arg0 (* (rand-vu) (- arg1 arg0))) + ) + +(defun rand-vu-percent? ((arg0 float)) + "Get a boolean that's true with the given probability (in 0, 1)." + (>= arg0 (rand-vu)) + ) + +(defun rand-vu-int-range ((arg0 int) (arg1 int)) + "Get an integer in the given range (inclusive)." + (if (< arg0 arg1) + (set! arg1 (+ arg1 1)) + (set! arg0 (+ arg0 1)) + ) + (let ((f0-4 (rand-vu-float-range (the float arg0) (the float arg1)))) + (if (< f0-4 0.0) + (set! f0-4 (+ -1.0 f0-4)) + ) + (the int f0-4) + ) + ) + +(defun rand-vu-int-count ((arg0 int)) + "Get an integer in the range [0, max)." + (the int (* (rand-vu) (the float arg0))) + ) + +;; WARN: new jak 2 until loop case, check carefully +(defun rand-vu-int-count-excluding ((arg0 int) (arg1 int)) + "Get an integer in the range [0, arg0). +If bit n is set in arg1, exclude this value from being returned." + (let ((s4-0 0) + (s5-0 0) + ) + (let ((v1-0 1)) + (while (nonzero? arg0) + (+! arg0 -1) + (if (not (logtest? arg1 v1-0)) + (+! s4-0 1) + ) + (set! v1-0 (* v1-0 2)) + ) + ) + (when (> s4-0 0) + (let ((v1-4 (the int (* (rand-vu) (the float s4-0)))) + (a0-1 1) + ) + (until #f + (while (logtest? arg1 a0-1) + (nop!) + (nop!) + (+! s5-0 1) + (set! a0-1 (* a0-1 2)) + ) + (if (zero? v1-4) + (goto cfg-14) + ) + (+! v1-4 -1) + (+! s5-0 1) + (set! a0-1 (* a0-1 2)) + ) + ) + #f + ) + (label cfg-14) + s5-0 + ) + ) + +;; WARN: new jak 2 until loop case, check carefully +(defun rand-vu-int-range-exclude ((arg0 int) (arg1 int) (arg2 int)) + "Get an integer in the range [0, arg0), excluding arg2. +Note that this doesn't use bits like rand-vu-int-count-excluding." + (until #f + (let ((v1-0 (rand-vu-int-range arg0 arg1))) + (if (!= v1-0 arg2) + (return v1-0) + ) + ) + ) + (the-as int #f) + ) + +(deftype random-generator (basic) + ((seed uint32) + ) + ) + + +(define *random-generator* (new 'global 'random-generator)) + +(set! (-> *random-generator* seed) (the-as uint #x666edd1e)) + +(defmacro sext32-64 (x) + "Sign extend a 32-bit value to 64-bits" + `(sar (shl ,x 32) 32) + ) + +(defun rand-uint31-gen ((gen random-generator)) + "Generate a supposedly random integer. + Note, this might not quite be right. + But the highest bit is always zero, like it says + and it looks kinda random to me." + (let* ((sd (-> gen seed)) + ;; addiu v1, r0, 16807 + ;; mult3 v0, v1, a1 + (prod (imul64 16807 sd)) + ;; mfhi v1 + (hi (shr prod 32)) ;; sign extend this? + (lo (sar (shl prod 32) 32)) + ;; daddu v1, v1, v1 + (v1 (+ hi hi)) + ;; srl a1, v0, 31 + (a1 (logand #xffffffff (shr lo 31))) + ;; or v1, v1, a1 + ;; daddu v0, v0 v1 + (result (+ lo (logior v1 a1))) + ) + (set! result (shr (logand #xffffffff (shl result 1)) 1)) + (set! (-> gen seed) result) + (the uint result) + ) + ) + +(defun cube-root ((arg0 float)) + "Cube root with cool trick that I don't understand." + (cond + ((!= arg0 0.0) + (let* ((v1-0 arg0) + (a1-2 (+ (logand (shr (the-as int v1-0) 23) 255) -127)) + (f0-1 (the-as float + (logior (logand (the-as uint #x807fffff) (the-as uint v1-0)) (shl (+ (/ (the-as int a1-2) 3) 127) 23)) + ) + ) + ) + ;; somehow f0-1 is a reasonable approximation of cube-root. + ;; then we do 6 iterations of newton's method to get a more accurate answer. + (dotimes (v1-3 6) + (set! f0-1 (- f0-1 + (/ (- (* (* f0-1 f0-1) f0-1) arg0) + (* 3.0 f0-1 f0-1) + ) + ) + ) + ) + f0-1 + ) + ) + (else + 0.0 + ) + ) + ) + +(defun int-noise ((arg0 int)) + "Generate random-ish floats in range -1, 1." + (let ((v1-1 (logxor (shl arg0 13) arg0))) + (- 1.0 (* 0.0000000009313226 + (the float (logand #x7fffffff (+ #x5208dd0d (* v1-1 (+ #xc0ae5 (* (* #x3d73 v1-1) v1-1)))))) + ) + ) + ) + ) + +(defun smooth-step ((arg0 float)) + "Interpolate between 0, 1 with a cubic polynomial. +These are picked so f(0) = 0, f(1) = 1, f'(0) = f'(1) = 0." + (cond + ((>= 0.0 arg0) + 0.0 + ) + ((>= arg0 1.0) + 1.0 + ) + (else + (* arg0 arg0 (+ 3.0 (* -2.0 arg0))) + ) + ) + ) + +(defun smooth-interp ((arg0 float) (arg1 float) (arg2 float) (arg3 float) (arg4 float)) + "Remap arg2 from (arg3, arg4) to (arg0, arg1), using cubic interpolation. +Satisfies: +- f(arg3) = arg0 +- f(arg4) = arg1 +- f'(arg3) = f'(arg4) = 0" + (+ arg0 (* (- arg1 arg0) (smooth-step (/ (- arg2 arg3) (- arg4 arg3))))) + ) diff --git a/goal_src/jak3/engine/math/matrix-compose.gc b/goal_src/jak3/engine/math/matrix-compose.gc new file mode 100644 index 0000000000..f9bcacbd3e --- /dev/null +++ b/goal_src/jak3/engine/math/matrix-compose.gc @@ -0,0 +1,108 @@ +;;-*-Lisp-*- +(in-package goal) + +;; name: matrix-compose.gc +;; name in dgo: matrix-compose +;; dgos: GAME + +;; DECOMP BEGINS + +(defun matrix-fur-compose ((arg0 matrix) (arg1 vector) (arg2 vector) (arg3 vector)) + (set! (-> arg0 rvec quad) (-> arg3 quad)) + (set! (-> arg0 uvec quad) (-> arg2 quad)) + (set! (-> arg0 fvec quad) (-> arg1 quad)) + arg0 + ) + +(defun matrix-fu-compose ((arg0 matrix) (arg1 vector) (arg2 vector) (arg3 vector)) + (set! (-> arg0 fvec quad) (-> arg1 quad)) + (set! (-> arg0 uvec quad) (-> arg2 quad)) + (vector-cross! (-> arg0 rvec) arg2 arg1) + arg0 + ) + +(defun matrix-fr-compose ((arg0 matrix) (arg1 vector) (arg2 vector) (arg3 vector)) + (set! (-> arg0 fvec quad) (-> arg1 quad)) + (set! (-> arg0 rvec quad) (-> arg2 quad)) + (vector-cross! (-> arg0 uvec) arg1 arg2) + arg0 + ) + +(defun matrix-ur-compose ((arg0 matrix) (arg1 vector) (arg2 vector) (arg3 vector)) + (set! (-> arg0 rvec quad) (-> arg2 quad)) + (set! (-> arg0 uvec quad) (-> arg1 quad)) + (vector-cross! (-> arg0 fvec) arg1 arg2) + arg0 + ) + +(defun matrix-f-u-compose ((arg0 matrix) (arg1 vector) (arg2 vector) (arg3 vector)) + (set! (-> arg0 fvec quad) (-> arg1 quad)) + (vector-cross! (-> arg0 rvec) arg2 arg1) + (vector-normalize! (-> arg0 rvec) 1.0) + (vector-cross! (-> arg0 uvec) arg1 (-> arg0 rvec)) + arg0 + ) + +(defun matrix-f-r-compose ((arg0 matrix) (arg1 vector) (arg2 vector) (arg3 vector)) + (set! (-> arg0 fvec quad) (-> arg1 quad)) + (vector-cross! (-> arg0 uvec) arg1 arg2) + (vector-normalize! (-> arg0 uvec) 1.0) + (vector-cross! (-> arg0 rvec) (-> arg0 uvec) arg1) + arg0 + ) + +(defun matrix-u-f-compose ((arg0 matrix) (arg1 vector) (arg2 vector) (arg3 vector)) + (set! (-> arg0 uvec quad) (-> arg1 quad)) + (vector-cross! (-> arg0 rvec) arg1 arg2) + (vector-normalize! (-> arg0 rvec) 1.0) + (vector-cross! (-> arg0 fvec) (-> arg0 rvec) arg1) + arg0 + ) + +(defun matrix-u-r-compose ((arg0 matrix) (arg1 vector) (arg2 vector) (arg3 vector)) + (set! (-> arg0 uvec quad) (-> arg1 quad)) + (vector-cross! (-> arg0 fvec) arg2 arg1) + (vector-normalize! (-> arg0 fvec) 1.0) + (vector-cross! (-> arg0 rvec) arg1 (-> arg0 fvec)) + arg0 + ) + +(defun matrix-r-f-compose ((arg0 matrix) (arg1 vector) (arg2 vector) (arg3 vector)) + (set! (-> arg0 rvec quad) (-> arg1 quad)) + (vector-cross! (-> arg0 uvec) arg2 arg1) + (vector-normalize! (-> arg0 uvec) 1.0) + (vector-cross! (-> arg0 fvec) arg1 (-> arg0 uvec)) + arg0 + ) + +(defun matrix-r-u-compose ((arg0 matrix) (arg1 vector) (arg2 vector) (arg3 vector)) + (set! (-> arg0 rvec quad) (-> arg1 quad)) + (vector-cross! (-> arg0 fvec) arg1 arg2) + (vector-normalize! (-> arg0 fvec) 1.0) + (vector-cross! (-> arg0 uvec) (-> arg0 fvec) arg1) + arg0 + ) + +(defun matrix-f-compose ((arg0 matrix) (arg1 vector) (arg2 vector) (arg3 vector)) + (set! (-> arg0 fvec quad) (-> arg1 quad)) + (let ((a2-1 (vector-get-unique! (new 'stack-no-clear 'vector) arg1))) + (matrix-f-u-compose arg0 arg1 a2-1 arg3) + ) + arg0 + ) + +(defun matrix-u-compose ((arg0 matrix) (arg1 vector) (arg2 vector) (arg3 vector)) + (set! (-> arg0 uvec quad) (-> arg1 quad)) + (let ((a2-1 (vector-get-unique! (new 'stack-no-clear 'vector) arg1))) + (matrix-u-f-compose arg0 arg1 a2-1 arg3) + ) + arg0 + ) + +(defun matrix-r-compose ((arg0 matrix) (arg1 vector) (arg2 vector) (arg3 vector)) + (set! (-> arg0 rvec quad) (-> arg1 quad)) + (let ((a2-1 (vector-get-unique! (new 'stack-no-clear 'vector) arg1))) + (matrix-r-f-compose arg0 arg1 a2-1 arg3) + ) + arg0 + ) diff --git a/goal_src/jak3/engine/math/matrix-h.gc b/goal_src/jak3/engine/math/matrix-h.gc index dd54b24f1c..a228a001e4 100644 --- a/goal_src/jak3/engine/math/matrix-h.gc +++ b/goal_src/jak3/engine/math/matrix-h.gc @@ -5,5 +5,103 @@ ;; name in dgo: matrix-h ;; dgos: GAME +(defmacro new-stack-matrix0 () + "Get a new matrix on the stack that's set to zero." + `(let ((mat (new 'stack-no-clear 'matrix))) + (set! (-> mat quad 0) (the-as uint128 0)) + (set! (-> mat quad 1) (the-as uint128 0)) + (set! (-> mat quad 2) (the-as uint128 0)) + (set! (-> mat quad 3) (the-as uint128 0)) + mat + ) + ) + ;; DECOMP BEGINS +(deftype matrix (structure) + "A 4x4 matrix, stored in row-major order. +some, but not all, functions assume that a matrix is an affine transform. +others assume that the rotation has no scale or shear (and that its inverse is its transpose)." + ((data float 16) + (vector vector 4 :overlay-at (-> data 0)) + (quad uint128 4 :overlay-at (-> data 0)) + (rvec vector :inline :overlay-at (-> data 0)) + (uvec vector :inline :overlay-at (-> data 4)) + (fvec vector :inline :overlay-at (-> data 8)) + (trans vector :inline :overlay-at (-> data 12)) + ) + (:methods + (transform-vectors! (_type_ (inline-array vector) (inline-array vector) int) none) + ) + ) + + +(deftype matrix3 (structure) + "A 3x3 matrix, stored in row-major order. +NOTE: the rows each have an extra 4-bytes of padding, +so this is really a 3x4 matrix. +This type is rarely used." + ((data float 12) + (vector vector 3 :inline :overlay-at (-> data 0)) + (quad uint128 3 :overlay-at (-> data 0)) + ) + ) + + +(deftype matrix4h (structure) + "A matrix stored using 16-bit integers. +Note that these usually have different scaling for the 4th row which +contains the translation in an affine transform. +So you generally should not unpack these to floats without knowing where they came from +and how they were originally packed (for example, in tie/shrub)." + ((data int16 16) + (vector4h vector4h 4 :overlay-at (-> data 0)) + (long int64 4 :overlay-at (-> data 0)) + ) + ) + + +(defun matrix-copy! ((arg0 matrix) (arg1 matrix)) + "Copy arg1 to arg0" + (let ((v1-0 (-> arg1 rvec quad)) + (a2-0 (-> arg1 uvec quad)) + (a3-0 (-> arg1 fvec quad)) + (a1-1 (-> arg1 trans quad)) + ) + (set! (-> arg0 rvec quad) v1-0) + (set! (-> arg0 uvec quad) a2-0) + (set! (-> arg0 fvec quad) a3-0) + (set! (-> arg0 trans quad) a1-1) + ) + arg0 + ) + +(defun matrix<-vector-yz-exact! ((arg0 matrix) (arg1 vector) (arg2 vector)) + (set! (-> arg0 fvec quad) (-> arg1 quad)) + (set! (-> arg0 uvec quad) (-> arg2 quad)) + (vector-cross! (-> arg0 rvec) (-> arg0 uvec) arg1) + arg0 + ) + +(defun matrix<-vector-yz! ((arg0 matrix) (arg1 vector) (arg2 vector)) + (set! (-> arg0 fvec quad) (-> arg1 quad)) + (vector-cross! (-> arg0 rvec) arg2 arg1) + (vector-normalize! (-> arg0 rvec) 1.0) + (vector-cross! (-> arg0 uvec) arg1 (-> arg0 rvec)) + (set! (-> arg0 rvec w) 1.0) + (set! (-> arg0 uvec w) 1.0) + (set! (-> arg0 fvec w) 1.0) + arg0 + ) + +(defun matrix<-vector-z! ((arg0 matrix) (arg1 vector)) + (let* ((s3-0 (new 'stack-no-clear 'vector)) + (v1-0 (vector-get-closest-perpendicular! s3-0 arg1 (vector-get-unique! (new 'stack-no-clear 'vector) arg1))) + (s4-1 arg0) + ) + (set! (-> s4-1 fvec quad) (-> arg1 quad)) + (set! (-> s4-1 uvec quad) (-> v1-0 quad)) + (vector-cross! (-> s4-1 rvec) (-> s4-1 uvec) arg1) + ) + arg0 + ) diff --git a/goal_src/jak3/engine/math/matrix.gc b/goal_src/jak3/engine/math/matrix.gc index aba4d78cb0..7ecec3aa8d 100644 --- a/goal_src/jak3/engine/math/matrix.gc +++ b/goal_src/jak3/engine/math/matrix.gc @@ -5,5 +5,1906 @@ ;; name in dgo: matrix ;; dgos: GAME +#|@file +This file implements the GOAL matrix library. + +In general, a vector is always treated as a row vector. +Chaining transformation is done like v_row * T1_goal * T2_goal, which means do T1 before T2. +This is the opposite of the usual convention: +T2_normal * T1_normal * v_col +However, there is good news: + T1_normal = T1_goal ^ T + T2_normal = T2_goal ^ T +This is due to the property + (A * B)^T = B^T * A^T + +So a homogeneous transformation is: +R_xx R_xy R_xz 0 +R_yx R_yy R_yz 0 +R_zx R_zy R_zz 0 +T_x T_y T_z 1 + +which is probably the transpose of what you're used to. + +note that they also used row-major storage, so the 3rd qword of a matrix is the translation +part of the affine transform. + +In general, be careful with using these functions as they often have strange +requirements for the form of the input matrix or if the input/output matrix are +allowed to be the same memory. +|# + ;; DECOMP BEGINS +(defun matrix-identity! ((arg0 matrix)) + "Set dst to the identity matrix." + (set! (-> arg0 rvec quad) (the-as uint128 0)) + (set! (-> arg0 uvec quad) (the-as uint128 0)) + (set! (-> arg0 fvec quad) (the-as uint128 0)) + (set! (-> arg0 trans quad) (the-as uint128 0)) + (let ((f0-0 1.0)) + (set! (-> arg0 trans w) f0-0) + (set! (-> arg0 fvec z) f0-0) + (set! (-> arg0 uvec y) f0-0) + (set! (-> arg0 rvec x) f0-0) + ) + arg0 + ) + +(define *identity-matrix* (matrix-identity! (new 'global 'matrix))) + +(define *hermite-matrix* (new 'static 'matrix + :rvec (new 'static 'vector :x 2.0 :y -2.0 :z 1.0 :w 1.0) + :uvec (new 'static 'vector :x -3.0 :y 3.0 :z -2.0 :w -1.0) + :fvec (new 'static 'vector :z 1.0) + :trans (new 'static 'vector :x 1.0) + ) + ) + +(defun matrix+! ((arg0 matrix) (arg1 matrix) (arg2 matrix)) + "Set dst = src1 + src2. It is okay for any arguments to be the same data. +This is not an efficient implementation." + (dotimes (v1-0 16) + (set! (-> arg0 rvec data v1-0) (+ (-> arg1 rvec data v1-0) (-> arg2 rvec data v1-0))) + ) + arg0 + ) + +(defun matrix-! ((arg0 matrix) (arg1 matrix) (arg2 matrix)) + "Set dst = src1 - src1. It is okay for any arugments to be the same data. +This is not an efficient implementation." + (dotimes (v1-0 16) + (set! (-> arg0 rvec data v1-0) (- (-> arg1 rvec data v1-0) (-> arg2 rvec data v1-0))) + ) + arg0 + ) + +(defun matrix*! ((arg0 matrix) (arg1 matrix) (arg2 matrix)) + "Set dst = src1 * src2. It is okay for any arguments to be the same data. +This is a moderately efficient implementation." + (rlet ((acc :class vf) + (vf10 :class vf) + (vf11 :class vf) + (vf12 :class vf) + (vf13 :class vf) + (vf14 :class vf) + (vf15 :class vf) + (vf16 :class vf) + (vf17 :class vf) + (vf18 :class vf) + (vf19 :class vf) + (vf20 :class vf) + (vf21 :class vf) + ) + (.lvf vf10 (&-> arg1 rvec quad)) + (.lvf vf14 (&-> arg2 rvec quad)) + (.lvf vf15 (&-> arg2 uvec quad)) + (.lvf vf16 (&-> arg2 fvec quad)) + (.lvf vf17 (&-> arg2 trans quad)) + (.lvf vf11 (&-> arg1 uvec quad)) + (.lvf vf12 (&-> arg1 fvec quad)) + (.lvf vf13 (&-> arg1 trans quad)) + (.mul.x.vf acc vf14 vf10) + (.add.mul.y.vf acc vf15 vf10 acc) + (.add.mul.z.vf acc vf16 vf10 acc) + (.add.mul.w.vf vf18 vf17 vf10 acc) + (.mul.x.vf acc vf14 vf11) + (.add.mul.y.vf acc vf15 vf11 acc) + (.add.mul.z.vf acc vf16 vf11 acc) + (.add.mul.w.vf vf19 vf17 vf11 acc) + (.mul.x.vf acc vf14 vf12) + (.add.mul.y.vf acc vf15 vf12 acc) + (.add.mul.z.vf acc vf16 vf12 acc) + (.add.mul.w.vf vf20 vf17 vf12 acc) + (.mul.x.vf acc vf14 vf13) + (.add.mul.y.vf acc vf15 vf13 acc) + (.add.mul.z.vf acc vf16 vf13 acc) + (.add.mul.w.vf vf21 vf17 vf13 acc) + (.svf (&-> arg0 rvec quad) vf18) + (.svf (&-> arg0 uvec quad) vf19) + (.svf (&-> arg0 fvec quad) vf20) + (.svf (&-> arg0 trans quad) vf21) + arg0 + ) + ) + +(defun matrixp*! ((arg0 matrix) (arg1 matrix) (arg2 matrix)) + "Set dst = src1 * src2. NOTE: this function is a wrapper around matrix*! +that adds no additional functionality. It seems to be a leftover from +a time when matrix*! wasn't safe to use in place. This is unused." + (let ((s5-0 (new-stack-matrix0))) + (matrix*! s5-0 arg1 arg2) + (set! (-> arg0 rvec quad) (-> s5-0 rvec quad)) + (set! (-> arg0 uvec quad) (-> s5-0 uvec quad)) + (set! (-> arg0 fvec quad) (-> s5-0 fvec quad)) + (set! (-> arg0 trans quad) (-> s5-0 trans quad)) + ) + arg0 + ) + +(defun vector-matrix*! ((arg0 vector) (arg1 vector) (arg2 matrix)) + "Set dst = vec * mat. dst may be equal to src." + (rlet ((acc :class vf) + (vf1 :class vf) + (vf2 :class vf) + (vf3 :class vf) + (vf4 :class vf) + (vf5 :class vf) + ) + (.lvf vf1 (&-> arg2 rvec quad)) + (.lvf vf2 (&-> arg2 uvec quad)) + (.lvf vf3 (&-> arg2 fvec quad)) + (.lvf vf4 (&-> arg2 trans quad)) + (.lvf vf5 (&-> arg1 quad)) + (.mul.x.vf acc vf1 vf5) + (.add.mul.y.vf acc vf2 vf5 acc) + (.add.mul.z.vf acc vf3 vf5 acc) + (.add.mul.w.vf vf5 vf4 vf5 acc) + (.svf (&-> arg0 quad) vf5) + arg0 + ) + ) + +(defun vector-norm-matrix*! ((arg0 vector) (arg1 vector) (arg2 matrix)) + (rlet ((acc :class vf) + (Q :class vf) + (vf0 :class vf) + (vf1 :class vf) + (vf2 :class vf) + (vf3 :class vf) + (vf4 :class vf) + (vf5 :class vf) + ) + (init-vf0-vector) + (.lvf vf1 (&-> arg2 rvec quad)) + (.lvf vf2 (&-> arg2 uvec quad)) + (.lvf vf3 (&-> arg2 fvec quad)) + (.lvf vf4 (&-> arg2 trans quad)) + (.lvf vf5 (&-> arg1 quad)) + (.mul.x.vf acc vf1 vf5) + (.add.mul.y.vf acc vf2 vf5 acc) + (.add.mul.z.vf acc vf3 vf5 acc) + (.add.mul.w.vf vf5 vf4 vf5 acc) + (.div.vf Q vf0 vf5 :fsf #b11 :ftf #b11) + (.wait.vf) + (.mul.vf vf5 vf5 Q :mask #b111) + (.nop.vf) + (.nop.vf) + (.mov.vf vf5 vf0 :mask #b1000) + (.svf (&-> arg0 quad) vf5) + arg0 + ) + ) + +(defun vector-rotate*! ((arg0 vector) (arg1 vector) (arg2 matrix)) + "Set dst to be the input vector rotated by the rotation part of mat. +The input matrix should be a homogeneous transform with a rotation matrix as its upper-left 3x3. +dst may be equal to src." + (rlet ((acc :class vf) + (vf1 :class vf) + (vf2 :class vf) + (vf3 :class vf) + (vf4 :class vf) + (vf5 :class vf) + ) + (nop!) + (nop!) + (.lvf vf5 (&-> arg1 quad)) + (nop!) + (.lvf vf1 (&-> arg2 rvec quad)) + (nop!) + (.lvf vf2 (&-> arg2 uvec quad)) + (.mul.x.vf acc vf1 vf5) + (.lvf vf3 (&-> arg2 fvec quad)) + (.add.mul.y.vf acc vf2 vf5 acc) + (.lvf vf4 (&-> arg2 trans quad)) + (.add.mul.z.vf vf5 vf3 vf5 acc) + (nop!) + (nop!) + (.svf (&-> arg0 quad) vf5) + arg0 + ) + ) + +(defun vector3s-matrix*! ((arg0 vector3s) (arg1 vector3s) (arg2 matrix)) + "Set dst to be ([src 1.0] * mat).xyz. Doesn't touch the w of dst. +dst and vec can be the same memory" + (let ((s5-0 (new-stack-vector0))) + (set-vector! s5-0 (-> arg1 x) (-> arg1 y) (-> arg1 z) 1.0) + (vector-matrix*! s5-0 s5-0 arg2) + (set! (-> arg0 x) (-> s5-0 x)) + (set! (-> arg0 y) (-> s5-0 y)) + (set! (-> arg0 z) (-> s5-0 z)) + ) + arg0 + ) + +(defun vector3s-rotate*! ((arg0 vector3s) (arg1 vector3s) (arg2 matrix)) + "Set dst to vec rotated by the rotation in the homogeneous transform mat. +mat should not have a scale/shear (the upper 3x3 should be a pure rotation)." + (let ((s5-0 (new-stack-vector0))) + (set-vector! s5-0 (-> arg1 x) (-> arg1 y) (-> arg1 z) 1.0) + (vector-rotate*! s5-0 s5-0 arg2) + (set! (-> arg0 x) (-> s5-0 x)) + (set! (-> arg0 y) (-> s5-0 y)) + (set! (-> arg0 z) (-> s5-0 z)) + ) + arg0 + ) + +(defun matrix-transpose! ((dst matrix) (src matrix)) + "Set dst = src^T. src and dst can be the same." + (local-vars + (v1-0 uint128) + (v1-1 uint128) + (v1-2 uint128) + (a1-1 uint128) + (a2-1 uint128) + (a3-1 uint128) + (a3-2 uint128) + (t0-1 uint128) + ) + (let ((t0-0 (-> src vector 0 quad))) + (let ((t1-0 (-> src vector 1 quad))) + (let ((a2-0 (-> src vector 2 quad))) + (.pextlw v1-0 t1-0 t0-0) + (let ((a3-0 (-> src vector 3 quad))) + (.pextuw a1-1 t1-0 t0-0) + ;; (.mov r0-0 f31-0) not sure what this weird thing is. + ;; it has no effect, but they use it instead of nop sometimes? + (.pextlw t0-1 a3-0 a2-0) + ;; (.mov r0-1 f31-0) + (.pextuw a2-1 a3-0 a2-0) + ) + ) + ) + ) + ;; (.mov r0-2 f31-0) + (.pcpyld a3-1 t0-1 v1-0) + ;; (.mov r0-3 f31-0) + (.pcpyud v1-1 v1-0 t0-1) + (set! (-> dst vector 0 quad) a3-1) + (.pcpyld a3-2 a2-1 a1-1) + (set! (-> dst vector 1 quad) v1-1) + (.pcpyud v1-2 a1-1 a2-1) + (set! (-> dst vector 2 quad) a3-2) + (set! (-> dst vector 3 quad) v1-2) + dst + ) + +(defun matrix-inverse-of-rot-trans! ((arg0 matrix) (arg1 matrix)) + "Set dst = src^-1, assuming src is a homogeneous tranform with only rotation/translation. +NOTE: THIS FUNCTION REQUIRES dst != src" + (rlet ((acc :class vf) + (vf0 :class vf) + (vf1 :class vf) + (vf2 :class vf) + (vf3 :class vf) + (vf4 :class vf) + (vf8 :class vf) + ) + (init-vf0-vector) + (matrix-transpose! arg0 arg1) + (.lvf vf1 (&-> arg0 rvec quad)) + (.lvf vf2 (&-> arg0 uvec quad)) + (.lvf vf3 (&-> arg0 fvec quad)) + (.sub.vf vf1 vf1 vf1 :mask #b1000) + (.sub.vf vf2 vf2 vf2 :mask #b1000) + (.sub.vf vf3 vf3 vf3 :mask #b1000) + (.lvf vf8 (&-> arg1 trans quad)) + (.mul.x.vf acc vf1 vf8) + (.add.mul.y.vf acc vf2 vf8 acc) + (.add.mul.z.vf vf4 vf3 vf8 acc) + (.sub.vf vf4 vf0 vf4) + (.mov.vf vf4 vf0 :mask #b1000) + (.svf (&-> arg0 rvec quad) vf1) + (.svf (&-> arg0 uvec quad) vf2) + (.svf (&-> arg0 fvec quad) vf3) + (.svf (&-> arg0 trans quad) vf4) + arg0 + ) + ) + +;; ERROR: Bad vector register dependency: vf3 +;; ERROR: Bad vector register dependency: vf4 +;; ERROR: Bad vector register dependency: vf5 +(defun matrix-4x4-inverse! ((arg0 matrix) (arg1 matrix)) + "Invert a 4x4 matrix. This assumes that the input is a homogeneous transform. +Src and dst can be the same." + (rlet ((acc :class vf) + (Q :class vf) + (vf0 :class vf) + (vf1 :class vf) + (vf10 :class vf) + (vf11 :class vf) + (vf12 :class vf) + (vf13 :class vf) + (vf14 :class vf) + (vf15 :class vf) + (vf16 :class vf) + (vf17 :class vf) + (vf18 :class vf) + (vf19 :class vf) + (vf2 :class vf) + (vf20 :class vf) + (vf23 :class vf) + (vf24 :class vf) + (vf25 :class vf) + (vf26 :class vf) + (vf27 :class vf) + (vf28 :class vf) + (vf29 :class vf) + (vf3 :class vf) + (vf30 :class vf) + (vf31 :class vf) + (vf4 :class vf) + (vf5 :class vf) + (vf6 :class vf) + (vf7 :class vf) + (vf8 :class vf) + (vf9 :class vf) + ) + + ;; og:preserve-this + ;; ADDED: the original implementation does math on vectors where some values are + ;; uninitialized. It doesn't use the result, so there's no problem, but this + ;; may cause strange slowdowns on x86 where doing math on NaNs can be extremely slow. + ;; ideally we should find a better solution. + (.xor.vf vf26 vf26 vf26) + (.xor.vf vf27 vf27 vf27) + (.xor.vf vf28 vf28 vf28) + (.xor.vf vf29 vf29 vf29) + (.xor.vf vf30 vf30 vf30) + (.xor.vf vf31 vf31 vf31) + (.xor.vf vf16 vf16 vf16) + (.xor.vf vf17 vf17 vf17) + (.xor.vf vf18 vf18 vf18) + (.xor.vf vf23 vf23 vf23) + (.xor.vf vf19 vf19 vf19) + (.xor.vf vf3 vf3 vf3) + (.xor.vf vf4 vf4 vf4) + (.xor.vf vf5 vf5 vf5) + + (init-vf0-vector) + (nop!) + (nop!) + (.lvf vf23 (&-> arg1 quad 0)) + (nop!) + (.lvf vf24 (&-> arg1 quad 1)) + (nop!) + (.lvf vf25 (&-> arg1 quad 2)) + (nop!) + (.lvf vf1 (&-> arg1 trans quad)) + (.mul.x.vf vf7 vf24 vf23) + (nop!) + (.mul.y.vf vf8 vf24 vf23) + (nop!) + (.mul.z.vf vf9 vf24 vf23) + (nop!) + (.mul.x.vf vf10 vf25 vf23) + (nop!) + (.mul.y.vf vf11 vf25 vf23) + (nop!) + (.mul.z.vf vf12 vf25 vf23) + (nop!) + (.mul.x.vf vf13 vf25 vf24) + (nop!) + (.mul.y.vf vf14 vf25 vf24) + (nop!) + (.mul.z.vf vf15 vf25 vf24) + (nop!) + (.mul.z.vf vf26 vf7 vf25 :mask #b10) + (nop!) + (.mul.z.vf vf27 vf11 vf24 :mask #b1) + (nop!) + (.mul.y.vf vf28 vf9 vf25 :mask #b1) + (nop!) + (.mul.z.vf vf29 vf14 vf23 :mask #b1) + (nop!) + (.mul.z.vf vf30 vf8 vf25 :mask #b1) + (nop!) + (.mul.y.vf vf31 vf7 vf25 :mask #b100) + (nop!) + (.add.y.vf vf16 vf27 vf26 :mask #b1) + (nop!) + (.sub.vf vf1 vf0 vf1) + (nop!) + (.add.x.vf vf17 vf29 vf30 :mask #b1) + (nop!) + (.sub.z.vf vf18 vf28 vf31 :mask #b1) + (nop!) + (.sub.y.vf vf23 vf14 vf15 :mask #b100) + (nop!) + (.sub.z.vf vf26 vf15 vf13 :mask #b1) + (nop!) + (.sub.x.vf vf29 vf13 vf14 :mask #b10) + (nop!) + (.sub.vf vf19 vf16 vf17 :mask #b1) + (nop!) + (.sub.z.vf vf24 vf12 vf11 :mask #b10) + (nop!) + (.sub.x.vf vf27 vf10 vf12 :mask #b100) + (nop!) + (.sub.y.vf vf30 vf11 vf10 :mask #b1) + (nop!) + (.add.vf vf20 vf19 vf18 :mask #b1) + (nop!) + (.sub.y.vf vf25 vf8 vf9 :mask #b100) + (nop!) + (.sub.z.vf vf28 vf9 vf7 :mask #b1) + (nop!) + (.sub.x.vf vf31 vf7 vf8 :mask #b10) + (nop!) + (.div.vf Q vf0 vf20 :fsf #b11 :ftf #b0) + (nop!) + (.sub.w.vf vf3 vf3 vf3 :mask #b1000) + (nop!) + (.sub.w.vf vf4 vf4 vf4 :mask #b1000) + (nop!) + (.sub.w.vf vf5 vf5 vf5 :mask #b1000) + (nop!) + (.mov.vf vf6 vf0 :mask #b1000) + (nop!) + (.wait.vf) + (nop!) + (.add.vf vf2 vf0 Q :mask #b1) + (nop!) + (.add.x.vf vf2 vf0 vf2 :mask #b111) + (nop!) + (.mul.z.vf vf3 vf2 vf23 :mask #b1) + (nop!) + (.mul.x.vf vf4 vf2 vf26 :mask #b1) + (nop!) + (.mul.y.vf vf5 vf2 vf29 :mask #b1) + (nop!) + (.mul.y.vf vf3 vf2 vf24 :mask #b10) + (nop!) + (.mul.z.vf vf4 vf2 vf27 :mask #b10) + (nop!) + (.mul.x.vf vf5 vf2 vf30 :mask #b10) + (nop!) + (.mul.z.vf vf3 vf2 vf25 :mask #b100) + (nop!) + (.mul.x.vf vf4 vf2 vf28 :mask #b100) + (nop!) + (.mul.y.vf vf5 vf2 vf31 :mask #b100) + (nop!) + (.mul.x.vf acc vf3 vf1) + (.svf (&-> arg0 quad 0) vf3) + (.add.mul.y.vf acc vf4 vf1 acc) + (.svf (&-> arg0 quad 1) vf4) + (.add.mul.z.vf vf6 vf5 vf1 acc :mask #b111) + (.svf (&-> arg0 quad 2) vf5) + (nop!) + (.svf (&-> arg0 trans quad) vf6) + arg0 + ) + ) + +(defun matrix-translate! ((arg0 matrix) (arg1 vector)) + "Set dst to a homogeneous transform with only a translation of trans." + (matrix-identity! arg0) + (set! (-> arg0 trans x) (-> arg1 x)) + (set! (-> arg0 trans y) (-> arg1 y)) + (set! (-> arg0 trans z) (-> arg1 z)) + arg0 + ) + +(defun matrix-translate+! ((arg0 matrix) (arg1 matrix) (arg2 vector)) + "Add the given translation to the translation of homogenous transform mat src +and store in dst. It is okay for dst = src." + (set! (-> arg0 trans x) (+ (-> arg1 trans x) (-> arg2 x))) + (set! (-> arg0 trans y) (+ (-> arg1 trans y) (-> arg2 y))) + (set! (-> arg0 trans z) (+ (-> arg1 trans z) (-> arg2 z))) + (when (!= arg0 arg1) + (set! (-> arg0 rvec quad) (-> arg1 rvec quad)) + (set! (-> arg0 uvec quad) (-> arg1 uvec quad)) + (set! (-> arg0 fvec quad) (-> arg1 fvec quad)) + ) + arg0 + ) + +(defun matrix-scale! ((arg0 matrix) (arg1 vector)) + "Set dst to a homogenous transform with only a scale. The x,y,z components +of scale become the x,y,z scaling factors" + (set! (-> arg0 rvec quad) (the-as uint128 0)) + (set! (-> arg0 uvec quad) (the-as uint128 0)) + (set! (-> arg0 fvec quad) (the-as uint128 0)) + (set! (-> arg0 trans quad) (the-as uint128 0)) + (set! (-> arg0 rvec x) (-> arg1 x)) + (set! (-> arg0 uvec y) (-> arg1 y)) + (set! (-> arg0 fvec z) (-> arg1 z)) + (set! (-> arg0 trans w) 1.0) + arg0 + ) + +(defun scale-matrix! ((arg0 matrix) (arg1 vector) (arg2 matrix)) + "Scale an existing matrix. Okay for dst = src. The scaling is applied per row. +This means the x component of scale is used to scale the first row of src. +The w component of scale is used." + (rlet ((vf4 :class vf) + (vf5 :class vf) + (vf6 :class vf) + (vf7 :class vf) + (vf8 :class vf) + ) + (.lvf vf4 (&-> arg1 quad)) + (.lvf vf5 (&-> arg2 rvec quad)) + (.lvf vf6 (&-> arg2 uvec quad)) + (.lvf vf7 (&-> arg2 fvec quad)) + (.lvf vf8 (&-> arg2 trans quad)) + (.mul.x.vf vf5 vf5 vf4) + (.mul.y.vf vf6 vf6 vf4) + (.mul.z.vf vf7 vf7 vf4) + (.mul.w.vf vf8 vf8 vf4) + (.svf (&-> arg0 rvec quad) vf5) + (.svf (&-> arg0 uvec quad) vf6) + (.svf (&-> arg0 fvec quad) vf7) + (.svf (&-> arg0 trans quad) vf8) + arg0 + ) + ) + +(defun matrix-inv-scale! ((arg0 matrix) (arg1 vector)) + "Set dst to a homogeneous transform with only a scale. +The x,y,z components of scale are inverted and used as the x,y,z scaling factors" + (set! (-> arg0 rvec quad) (the-as uint128 0)) + (set! (-> arg0 uvec quad) (the-as uint128 0)) + (set! (-> arg0 fvec quad) (the-as uint128 0)) + (set! (-> arg0 trans quad) (the-as uint128 0)) + (set! (-> arg0 rvec x) (/ 1.0 (-> arg1 x))) + (set! (-> arg0 uvec y) (/ 1.0 (-> arg1 y))) + (set! (-> arg0 fvec z) (/ 1.0 (-> arg1 z))) + (set! (-> arg0 trans w) 1.0) + arg0 + ) + +(defun column-scale-matrix! ((arg0 matrix) (arg1 vector) (arg2 matrix)) + "Scale an existing matrix. Okay for dst = src. The scaling is applied column-wise. +Meaning the x component of scale will scale the first column of src." + (rlet ((vf4 :class vf) + (vf5 :class vf) + (vf6 :class vf) + (vf7 :class vf) + (vf8 :class vf) + ) + (.lvf vf4 (&-> arg1 quad)) + (.lvf vf5 (&-> arg2 rvec quad)) + (.lvf vf6 (&-> arg2 uvec quad)) + (.lvf vf7 (&-> arg2 fvec quad)) + (.lvf vf8 (&-> arg2 trans quad)) + (.mul.vf vf5 vf5 vf4) + (.mul.vf vf6 vf6 vf4) + (.mul.vf vf7 vf7 vf4) + (.mul.vf vf8 vf8 vf4) + (.svf (&-> arg0 rvec quad) vf5) + (.svf (&-> arg0 uvec quad) vf6) + (.svf (&-> arg0 fvec quad) vf7) + (.svf (&-> arg0 trans quad) vf8) + arg0 + ) + ) + +(defun matrix-rotate-x! ((arg0 matrix) (arg1 float)) + "Set dst to a homogeneous transform matrix for a rotation around the x-axis (degrees)." + (let ((f30-0 (sin arg1)) + (f0-0 (cos arg1)) + ) + (set! (-> arg0 rvec quad) (the-as uint128 0)) + (set! (-> arg0 uvec quad) (the-as uint128 0)) + (set! (-> arg0 fvec quad) (the-as uint128 0)) + (set! (-> arg0 trans quad) (the-as uint128 0)) + (set! (-> arg0 rvec x) 1.0) + (set! (-> arg0 uvec y) f0-0) + (set! (-> arg0 uvec z) f30-0) + (set! (-> arg0 fvec y) (- f30-0)) + (set! (-> arg0 fvec z) f0-0) + ) + (set! (-> arg0 trans w) 1.0) + arg0 + ) + +(defun matrix-rotate-y! ((arg0 matrix) (arg1 float)) + "Set dst to a homoegeneous transform matrix for a rotation around the y axis (degrees)." + (let ((f30-0 (sin arg1)) + (f0-0 (cos arg1)) + ) + (set! (-> arg0 rvec quad) (the-as uint128 0)) + (set! (-> arg0 uvec quad) (the-as uint128 0)) + (set! (-> arg0 fvec quad) (the-as uint128 0)) + (set! (-> arg0 trans quad) (the-as uint128 0)) + (set! (-> arg0 rvec x) f0-0) + (set! (-> arg0 rvec z) (- f30-0)) + (set! (-> arg0 uvec y) 1.0) + (set! (-> arg0 fvec x) f30-0) + (set! (-> arg0 fvec z) f0-0) + ) + (set! (-> arg0 trans w) 1.0) + arg0 + ) + +(defun matrix-rotate-z! ((arg0 matrix) (arg1 float)) + "Set dst to a homogeneous transform matrix for a rotation around the z-axis (degrees)." + (let ((f30-0 (sin arg1)) + (f0-0 (cos arg1)) + ) + (set! (-> arg0 rvec quad) (the-as uint128 0)) + (set! (-> arg0 uvec quad) (the-as uint128 0)) + (set! (-> arg0 fvec quad) (the-as uint128 0)) + (set! (-> arg0 trans quad) (the-as uint128 0)) + (set! (-> arg0 rvec x) f0-0) + (set! (-> arg0 rvec y) f30-0) + (set! (-> arg0 uvec x) (- f30-0)) + (set! (-> arg0 uvec y) f0-0) + ) + (set! (-> arg0 fvec z) 1.0) + (set! (-> arg0 trans w) 1.0) + arg0 + ) + +(defun matrix-rotate-zyx! ((arg0 matrix) (arg1 vector)) + "Rotate in z,y,x order." + (let ((gp-0 (new-stack-matrix0)) + (s5-0 (new-stack-matrix0)) + ) + (matrix-rotate-x! arg0 (-> arg1 x)) + (matrix-rotate-y! gp-0 (-> arg1 y)) + (matrix*! s5-0 gp-0 arg0) + (matrix-rotate-z! gp-0 (-> arg1 z)) + (matrix*! arg0 gp-0 s5-0) + ) + arg0 + ) + +(defun-debug matrix-rotate-xyz-2! ((arg0 matrix) (arg1 vector)) + "Jak 1 version of matrix-rotate-xyz. Slower than the one below." + (let ((gp-0 (new 'stack-no-clear 'matrix)) + (s5-0 (new 'stack-no-clear 'matrix)) + ) + (matrix-rotate-z! arg0 (-> arg1 z)) + (matrix-rotate-y! gp-0 (-> arg1 y)) + (matrix*! s5-0 gp-0 arg0) + (matrix-rotate-x! gp-0 (-> arg1 x)) + (matrix*! arg0 gp-0 s5-0) + ) + arg0 + ) + +(defun matrix-rotate-xyz! ((arg0 matrix) (arg1 vector)) + "Rotate in x,y,z order." + (rlet ((vf0 :class vf)) + (init-vf0-vector) + (let ((s4-0 (new 'stack-no-clear 'vector)) + (s5-0 (new 'stack-no-clear 'vector)) + ) + (vector-sincos! s4-0 s5-0 arg1) + (let ((f2-0 (-> s4-0 x)) + (f5-0 (-> s4-0 y)) + (f3-0 (-> s4-0 z)) + (f0-0 (-> s5-0 x)) + (f1-0 (-> s5-0 y)) + ) + (let ((f4-0 (-> s5-0 z))) + (set! (-> arg0 rvec x) (* f1-0 f4-0)) + (set! (-> arg0 rvec y) (* f1-0 f3-0)) + (set! (-> arg0 rvec z) (- f5-0)) + (set! (-> arg0 rvec w) 0.0) + (let ((f6-4 (* f2-0 f5-0)) + (f5-1 (* f0-0 f5-0)) + ) + (set! (-> arg0 uvec x) (- (* f6-4 f4-0) (* f0-0 f3-0))) + (set! (-> arg0 uvec y) (+ (* f6-4 f3-0) (* f0-0 f4-0))) + (set! (-> arg0 uvec z) (* f2-0 f1-0)) + (set! (-> arg0 uvec w) 0.0) + (set! (-> arg0 fvec x) (+ (* f2-0 f3-0) (* f5-1 f4-0))) + (set! (-> arg0 fvec y) (- (* f5-1 f3-0) (* f2-0 f4-0))) + ) + ) + (set! (-> arg0 fvec z) (* f0-0 f1-0)) + ) + ) + (set! (-> arg0 fvec w) 0.0) + (.svf (&-> arg0 trans quad) vf0) + arg0 + ) + ) + +(defun matrix-rotate-zxy! ((arg0 matrix) (arg1 vector)) + "Rotate in z,x,y order." + (let ((gp-0 (new-stack-matrix0)) + (s5-0 (new-stack-matrix0)) + ) + (matrix-rotate-y! arg0 (-> arg1 y)) + (matrix-rotate-x! gp-0 (-> arg1 x)) + (matrix*! s5-0 gp-0 arg0) + (matrix-rotate-z! gp-0 (-> arg1 z)) + (matrix*! arg0 gp-0 s5-0) + ) + arg0 + ) + +(defun matrix-rotate-yxz! ((arg0 matrix) (arg1 vector)) + "Rotate in y,x,z order." + (let ((gp-0 (new-stack-matrix0)) + (s5-0 (new-stack-matrix0)) + ) + (matrix-rotate-z! arg0 (-> arg1 z)) + (matrix-rotate-x! gp-0 (-> arg1 x)) + (matrix*! s5-0 gp-0 arg0) + (matrix-rotate-y! gp-0 (-> arg1 y)) + (matrix*! arg0 gp-0 s5-0) + ) + arg0 + ) + +(defun matrix-rotate-yzx! ((arg0 matrix) (arg1 vector)) + "Rotate in y,z,x order." + (let ((gp-0 (new-stack-matrix0)) + (s5-0 (new-stack-matrix0)) + ) + (matrix-rotate-z! arg0 (-> arg1 x)) + (matrix-rotate-x! gp-0 (-> arg1 z)) + (matrix*! s5-0 gp-0 arg0) + (matrix-rotate-y! gp-0 (-> arg1 y)) + (matrix*! arg0 gp-0 s5-0) + ) + arg0 + ) + +(defun matrix-rotate-yxy! ((arg0 matrix) (arg1 vector)) + "Rotate. I believe in yxy order? Compared to the other rotations, this one +is quite a bit more optimized and avoid repeated trig operations." + (let ((a2-0 (new 'stack-no-clear 'vector)) + (s5-0 (new 'stack-no-clear 'vector)) + (s4-0 (new 'stack-no-clear 'vector)) + ) + (set-vector! a2-0 (-> arg1 x) (- (-> arg1 y) (-> arg1 z)) (-> arg1 z) 1.0) + (vector-sincos! s5-0 s4-0 a2-0) + (let ((f1-1 (-> s4-0 y)) + (f0-5 (-> s5-0 y)) + (f2-0 (-> s4-0 x)) + (f5-0 (-> s5-0 x)) + (f3-0 (-> s4-0 z)) + (f4-0 (-> s5-0 z)) + ) + (set! (-> arg0 rvec x) (- (* f1-1 f3-0) (* f0-5 f2-0 f4-0))) + (set! (-> arg0 rvec y) (* f0-5 f5-0)) + (set! (-> arg0 rvec z) (- (+ (* f1-1 f4-0) (* f0-5 f2-0 f3-0)))) + (set! (-> arg0 rvec w) 0.0) + (set! (-> arg0 uvec x) (* f5-0 f4-0)) + (set! (-> arg0 uvec y) f2-0) + (set! (-> arg0 uvec z) (* f5-0 f3-0)) + (set! (-> arg0 uvec w) 0.0) + (set! (-> arg0 fvec x) (+ (* f0-5 f3-0) (* f1-1 f2-0 f4-0))) + (set! (-> arg0 fvec y) (- (* f1-1 f5-0))) + (set! (-> arg0 fvec z) (- (* f1-1 f2-0 f3-0) (* f0-5 f4-0))) + ) + ) + (set! (-> arg0 fvec w) 0.0) + (set! (-> arg0 trans x) 0.0) + (set! (-> arg0 trans y) 0.0) + (set! (-> arg0 trans z) 0.0) + (set! (-> arg0 trans w) 1.0) + arg0 + ) + +(defun matrix-rotate-yx! ((arg0 matrix) (arg1 float) (arg2 float)) + "Rotate by y then x." + (matrix-rotate-y! arg0 arg1) + (let ((a1-2 (matrix-rotate-x! (new-stack-matrix0) arg2))) + (matrix*! arg0 a1-2 arg0) + ) + arg0 + ) + +;; WARN: Return type mismatch matrix vs none. +;; ERROR: Unsupported inline assembly instruction kind - [prot3w a1, v1] +;; ERROR: Unsupported inline assembly instruction kind - [prot3w a2, a1] +(defun matrix-axis-sin-cos-vu! ((arg0 matrix) (arg1 vector) (arg2 float) (arg3 float)) + "Create an axis-angle rotation matrix. But given the sin/cos of the angle. Uses the VU." + ;; og:preserve-this unused and basically identital to the non-VU version, so I'm leaving this out. + (/ 0 0) + (none) + ) + +;; ERROR: Unsupported inline assembly instruction kind - [prot3w a0, v1] +;; ERROR: Unsupported inline assembly instruction kind - [prot3w a1, a0] +(defun matrix-axis-sin-cos! ((dst matrix) (axis vector) (s float) (c float)) + "Create an axis-angle rotation matrix. But given the sin/cos of the angle." + ;;or v0, a0, r0 + ;;or v1, a1, r0 + ;;mtc1 f0, a2 + ;;mtc1 f1, a3 + ;;sll r0, r0, 0 + + ;; input scramble: + ;; - v0 = dst + ;; - v1 = axis + ;; - f0 = sine + ;; - f1 = cosine + (rlet ((vf5 :class vf) ;; vf5.x will be sine, vf5.w will be -cosine + (vf6 :class vf) ;; vf6.x will be cosine + (vf1 :class vf) ;; vector. + (vf0 :class vf) + (vf2 :class vf) + (vf3 :class vf) + (vf4 :class vf) + (vf11 :class vf) + (vf7 :class vf) + (vf8 :class vf) + (vf9 :class vf) + (vf10 :class vf) + (a1 :class i128 :type uint128) + (r0 :class i128 :type uint128)) ;; will be used for zero check. + ;; initialize constant vectors + (init-vf0-vector) + (.xor.p r0 r0 r0) + + ;; this is an overly complicated check to see if xyz = 0. + + (let ((a0 65535) ;; ori a0, r0, 65535 + (v1 (-> axis quad))) ;; lq v1, 0(v1) + + ;; this a0 constant has ffff in the upper 16 bits to mask out w, later on. + ;; dsll32 a0, a0, 16 + (set! a0 (shl a0 48)) ;; a0 = ffff'0000'0000'0000 + + ;;mfc1 a1, f1 + ;;qmtc2.i vf6, a1 + (.mov vf6 c) ;; will set vf6.x to cosine. + + ;;pceqw a1, v1, r0 + ;; compare for equality with zero. + ;; this will set 32-bits for each component. + (.pceqw a1 v1 r0) + + ;; so we pack: [upper64, w0?16, z0?16, y0?16, x0?16] + (.ppach a1 r0 a1) + + ;;qmtc2.i vf1, v1 + (.mov vf1 v1) ;; should be quad move! + + ;;or v1, a1, a0 + ;; make it seem like w is zero. If x,y,z = 0, but w != 0, we want + ;; it to act like zero. + (let ((xyz-zero (logior a0 (the uint a1)))) + ;;mfc1 a0, f0 + ;;qmtc2.i vf5, a0 + (.mov vf5 s) + + ;;daddiu v1, v1, 1 + ;; if all is zero, this will overflow and give us 0. + (+! xyz-zero 1) + + ;;vsubx.w vf5, vf0, vf6 + (.sub.x.vf vf5 vf0 vf6 :mask #b1000) + + ;;beq v1, r0, L15 + ;;vaddx.y vf5, vf0, vf6 + (.add.x.vf vf5 vf0 vf6 :mask #b0010) + (when-goto (zero? xyz-zero) zero-case) + ) + ) + + ;; Nonzero case: + ;; vsubw.w vf2, vf0, vf0 + ;; vsubw.w vf3, vf0, vf0 + ;; vsubw.w vf4, vf0, vf0 + (.xor.vf vf2 vf2 vf2) + (.xor.vf vf3 vf3 vf3) + (.xor.vf vf4 vf4 vf4) + + ;;vmulx.xyz vf11, vf1, vf5 + (.mul.x.vf vf11 vf1 vf5 :mask #b0111) + + ;;vaddy.x vf7, vf0, vf5 + (.add.y.vf vf7 vf0 vf5 :mask #b0001) + + ;;vaddy.y vf8, vf0, vf5 + (.add.y.vf vf8 vf0 vf5 :mask #b0010) + + ;;vaddy.z vf9, vf0, vf5 + (.add.y.vf vf9 vf0 vf5 :mask #b0100) + + ;;vmulw.xyz vf10, vf1, vf5 + (.mul.w.vf vf10 vf1 vf5 :mask #b0111) + + ;;vsubz.y vf7, vf0, vf11 + (.sub.z.vf vf7 vf0 vf11 :mask #b0010) + + ;;vaddy.z vf7, vf0, vf11 + (.add.y.vf vf7 vf0 vf11 :mask #b0100) + + ;;vaddz.x vf8, vf0, vf11 + (.add.z.vf vf8 vf0 vf11 :mask #b0001) + + ;;vsubx.z vf8, vf0, vf11 + (.sub.x.vf vf8 vf0 vf11 :mask #b0100) + + ;;vmulx.xyz vf2, vf10, vf1 + (.mul.x.vf vf2 vf10 vf1 :mask #b0111) + + ;;vmuly.xyz vf3, vf10, vf1 + (.mul.y.vf vf3 vf10 vf1 :mask #b0111) + + ;;vmulz.xyz vf4, vf10, vf1 + (.mul.z.vf vf4 vf10 vf1 :mask #b0111) + + ;;vsuby.x vf9, vf0, vf11 + (.sub.y.vf vf9 vf0 vf11 :mask #b0001) + + ;;vaddx.y vf9, vf0, vf11 + (.add.x.vf vf9 vf0 vf11 :mask #b0010) + + ;;vadd.xyz vf2, vf2, vf7 + (.add.vf vf2 vf2 vf7 :mask #b0111) + + ;;vadd.xyz vf3, vf3, vf8 + (.add.vf vf3 vf3 vf8 :mask #b0111) + + ;;vadd.xyz vf4, vf4, vf9 + (.add.vf vf4 vf4 vf9 :mask #b0111) + + ;;sqc2 vf2, 0(v0) + ;;sqc2 vf3, 16(v0) + ;;sqc2 vf0, 48(v0) + ;;sqc2 vf4, 32(v0) + (.svf (-> dst vector 0) vf2) + (.svf (-> dst vector 1) vf3) + (.svf (-> dst vector 3) vf0) + (.svf (-> dst vector 2) vf4) + (goto end) + (label zero-case) + ;; overly clever way to set identity matrix + ;;lui v1, 16256 + ;;sqc2 vf0, 48(v0) + ;;pcpyld v1, r0, v1 + ;;mfc1 r0, f31 + ;;prot3w a0, v1 + ;;mfc1 r0, f31 + ;;prot3w a1, a0 + ;;sq v1, 0(v0) + ;;sll r0, r0, 0 + ;;sq a0, 32(v0) + ;;sll r0, r0, 0 + ;;sq a1, 16(v0) + (matrix-identity! dst) + (label end) + ) + dst + ) + +(defun matrix-axis-angle! ((arg0 matrix) (arg1 vector) (arg2 float)) + "Create an axis-angle rotation matrix." + (matrix-axis-sin-cos! arg0 arg1 (sin arg2) (cos arg2)) + ) + +(defun matrix-lerp! ((arg0 matrix) (arg1 matrix) (arg2 matrix) (arg3 float)) + "Lerp an entire matrix, coefficient-wise." + (rlet ((vf1 :class vf) + (vf2 :class vf) + (vf3 :class vf) + (vf4 :class vf) + (vf5 :class vf) + (vf6 :class vf) + (vf7 :class vf) + (vf8 :class vf) + (vf9 :class vf) + ) + (.mov vf9 arg3) + (.lvf vf1 (&-> arg1 rvec quad)) + (.lvf vf2 (&-> arg1 uvec quad)) + (.lvf vf3 (&-> arg1 fvec quad)) + (.lvf vf4 (&-> arg1 trans quad)) + (.lvf vf5 (&-> arg2 rvec quad)) + (.lvf vf6 (&-> arg2 uvec quad)) + (.lvf vf7 (&-> arg2 fvec quad)) + (.lvf vf8 (&-> arg2 trans quad)) + (.sub.vf vf5 vf5 vf1) + (.sub.vf vf6 vf6 vf2) + (.sub.vf vf7 vf7 vf3) + (.sub.vf vf8 vf8 vf4) + (.mul.x.vf vf5 vf5 vf9) + (.mul.x.vf vf6 vf6 vf9) + (.mul.x.vf vf7 vf7 vf9) + (.mul.x.vf vf8 vf8 vf9) + (.add.vf vf1 vf1 vf5) + (.add.vf vf2 vf2 vf6) + (.add.vf vf3 vf3 vf7) + (.add.vf vf4 vf4 vf8) + (.svf (&-> arg0 rvec quad) vf1) + (.svf (&-> arg0 uvec quad) vf2) + (.svf (&-> arg0 fvec quad) vf3) + (.svf (&-> arg0 trans quad) vf4) + arg0 + ) + ) + +(defun matrix-3x3-determinant ((arg0 matrix)) + "Compute the determinant of a 3x3 matrix." + (let ((f8-0 (-> arg0 rvec x)) + (f1-0 (-> arg0 rvec y)) + (f4-0 (-> arg0 rvec z)) + (f2-0 (-> arg0 uvec x)) + (f5-0 (-> arg0 uvec y)) + (f9-0 (-> arg0 uvec z)) + (f3-0 (-> arg0 fvec x)) + (f6-0 (-> arg0 fvec y)) + (f0-0 (-> arg0 fvec z)) + ) + (- (+ (* f8-0 f5-0 f0-0) (* f1-0 f9-0 f3-0) (* f4-0 f2-0 f6-0)) + (+ (* f8-0 f9-0 f6-0) (* f4-0 f5-0 f3-0) (* f1-0 f2-0 f0-0)) + ) + ) + ) + +(defun matrix3-determinant ((arg0 matrix)) + "Unused. Not sure if this has limitations compared to the above version." + (local-vars (v0-0 float)) + (rlet ((acc :class vf) + (vf10 :class vf) + (vf11 :class vf) + (vf12 :class vf) + (vf13 :class vf) + ) + (.lvf vf11 (&-> arg0 uvec quad)) + (.lvf vf12 (&-> arg0 fvec quad)) + (.lvf vf10 (&-> arg0 rvec quad)) + (.outer.product.a.vf acc vf11 vf12) + (.outer.product.b.vf vf13 vf12 vf11 acc) + (.mul.vf vf13 vf13 vf10 :mask #b111) + (.add.y.vf vf13 vf13 vf13 :mask #b1) + (.add.z.vf vf13 vf13 vf13 :mask #b1) + (.mov v0-0 vf13) + v0-0 + ) + ) + +(defun matrix-3x3-inverse! ((arg0 matrix) (arg1 matrix)) + "Compute the inverse of a 3x3 matrix. Not very efficient. +Requires src != dst." + (let ((f0-0 (matrix-3x3-determinant arg1))) + (set! (-> arg0 rvec x) + (/ (- (* (-> arg1 uvec y) (-> arg1 fvec z)) (* (-> arg1 uvec z) (-> arg1 fvec y))) f0-0) + ) + (set! (-> arg0 uvec x) + (/ (- (* (-> arg1 uvec z) (-> arg1 fvec x)) (* (-> arg1 uvec x) (-> arg1 fvec z))) f0-0) + ) + (set! (-> arg0 fvec x) + (/ (- (* (-> arg1 uvec x) (-> arg1 fvec y)) (* (-> arg1 uvec y) (-> arg1 fvec x))) f0-0) + ) + (set! (-> arg0 rvec y) + (/ (- (* (-> arg1 fvec y) (-> arg1 rvec z)) (* (-> arg1 fvec z) (-> arg1 rvec y))) f0-0) + ) + (set! (-> arg0 uvec y) + (/ (- (* (-> arg1 fvec z) (-> arg1 rvec x)) (* (-> arg1 fvec x) (-> arg1 rvec z))) f0-0) + ) + (set! (-> arg0 fvec y) + (/ (- (* (-> arg1 fvec x) (-> arg1 rvec y)) (* (-> arg1 fvec y) (-> arg1 rvec x))) f0-0) + ) + (set! (-> arg0 rvec z) + (/ (- (* (-> arg1 rvec y) (-> arg1 uvec z)) (* (-> arg1 rvec z) (-> arg1 uvec y))) f0-0) + ) + (set! (-> arg0 uvec z) + (/ (- (* (-> arg1 rvec z) (-> arg1 uvec x)) (* (-> arg1 rvec x) (-> arg1 uvec z))) f0-0) + ) + (set! (-> arg0 fvec z) + (/ (- (* (-> arg1 rvec x) (-> arg1 uvec y)) (* (-> arg1 rvec y) (-> arg1 uvec x))) f0-0) + ) + ) + arg0 + ) + +(defun matrix-3x3-inverse-transpose! ((arg0 matrix) (arg1 matrix)) + "Invert and transpose. +Requires dst != src." + (let ((f0-0 (matrix-3x3-determinant arg1))) + (set! (-> arg0 rvec x) + (/ (- (* (-> arg1 uvec y) (-> arg1 fvec z)) (* (-> arg1 uvec z) (-> arg1 fvec y))) f0-0) + ) + (set! (-> arg0 rvec y) + (/ (- (* (-> arg1 uvec z) (-> arg1 fvec x)) (* (-> arg1 uvec x) (-> arg1 fvec z))) f0-0) + ) + (set! (-> arg0 rvec z) + (/ (- (* (-> arg1 uvec x) (-> arg1 fvec y)) (* (-> arg1 uvec y) (-> arg1 fvec x))) f0-0) + ) + (set! (-> arg0 uvec x) + (/ (- (* (-> arg1 fvec y) (-> arg1 rvec z)) (* (-> arg1 fvec z) (-> arg1 rvec y))) f0-0) + ) + (set! (-> arg0 uvec y) + (/ (- (* (-> arg1 fvec z) (-> arg1 rvec x)) (* (-> arg1 fvec x) (-> arg1 rvec z))) f0-0) + ) + (set! (-> arg0 uvec z) + (/ (- (* (-> arg1 fvec x) (-> arg1 rvec y)) (* (-> arg1 fvec y) (-> arg1 rvec x))) f0-0) + ) + (set! (-> arg0 fvec x) + (/ (- (* (-> arg1 rvec y) (-> arg1 uvec z)) (* (-> arg1 rvec z) (-> arg1 uvec y))) f0-0) + ) + (set! (-> arg0 fvec y) + (/ (- (* (-> arg1 rvec z) (-> arg1 uvec x)) (* (-> arg1 rvec x) (-> arg1 uvec z))) f0-0) + ) + (set! (-> arg0 fvec z) + (/ (- (* (-> arg1 rvec x) (-> arg1 uvec y)) (* (-> arg1 rvec y) (-> arg1 uvec x))) f0-0) + ) + ) + arg0 + ) + +(defun matrix3-inverse-transpose! ((arg0 matrix) (arg1 matrix)) + "Unused. Not sure if this has limitations compared to other version." + (rlet ((acc :class vf) + (Q :class vf) + (vf0 :class vf) + (vf1 :class vf) + (vf10 :class vf) + (vf11 :class vf) + (vf12 :class vf) + (vf13 :class vf) + (vf14 :class vf) + (vf15 :class vf) + ) + (init-vf0-vector) + (.lvf vf10 (&-> arg1 rvec quad)) + (.lvf vf11 (&-> arg1 uvec quad)) + (.lvf vf12 (&-> arg1 fvec quad)) + (.outer.product.a.vf acc vf11 vf12) + (.outer.product.b.vf vf13 vf12 vf11 acc) + (.outer.product.a.vf acc vf12 vf10) + (.outer.product.b.vf vf14 vf10 vf12 acc) + (.mul.vf vf1 vf10 vf13 :mask #b111) + (.outer.product.a.vf acc vf10 vf11) + (.outer.product.b.vf vf15 vf11 vf10 acc) + (.nop.vf) + (.add.y.vf vf1 vf1 vf1 :mask #b1) + (.nop.vf) + (.nop.vf) + (.nop.vf) + (.add.z.vf vf1 vf1 vf1 :mask #b1) + (.nop.vf) + (.nop.vf) + (.nop.vf) + (.div.vf Q vf0 vf1 :fsf #b11 :ftf #b0) + (.wait.vf) + (.mul.vf vf13 vf13 Q) + (.mul.vf vf14 vf14 Q) + (.mul.vf vf15 vf15 Q) + (.nop.vf) + (.nop.vf) + (.svf (&-> arg0 rvec quad) vf13) + (.svf (&-> arg0 uvec quad) vf14) + (.svf (&-> arg0 fvec quad) vf15) + arg0 + ) + ) + +;; ERROR: Unsupported inline assembly instruction kind - [mula.s f2, f2] +;; ERROR: Unsupported inline assembly instruction kind - [madda.s f0, f0] +;; ERROR: Unsupported inline assembly instruction kind - [madd.s f0, f1, f1] +;; ERROR: Unsupported inline assembly instruction kind - [rsqrt.s f0, f2, f0] +(defun matrix-3x3-normalize! ((arg0 matrix) (arg1 matrix)) + "Unused." + (/ 0 0) + arg0 + #| + (local-vars (f0-1 float) (f0-2 float)) + (rlet ((acc :class vf) + (Q :class vf) + (vf0 :class vf) + (vf10 :class vf) + (vf11 :class vf) + (vf12 :class vf) + (vf13 :class vf) + (vf14 :class vf) + (vf15 :class vf) + (vf16 :class vf) + ) + (init-vf0-vector) + (let ((f2-0 (-> arg1 data 0)) + (f0-0 (-> arg1 data 1)) + (f1-0 (-> arg1 data 2)) + (v1-0 #x3f800000) + ) + (.lvf vf10 (&-> arg1 quad 0)) + (.mula.s f2-0 f2-0) + (.lvf vf11 (&-> arg1 quad 1)) + (let ((f2-1 (gpr->fpr v1-0))) + (.lvf vf12 (&-> arg1 quad 2)) + (.madda.s f0-0 f0-0) + (.sub.w.vf vf13 vf0 vf0 :mask #b1000) + (.madd.s f0-1 f1-0 f1-0) + (.sub.w.vf vf14 vf0 vf0 :mask #b1000) + (.rsqrt.s f0-2 f2-1 f0-1) + ) + ) + (.sub.w.vf vf15 vf0 vf0 :mask #b1000) + (let ((v1-1 f0-2)) + (.mov vf16 v1-1) + ) + (.mul.x.vf vf13 vf10 vf16 :mask #b111) + (.outer.product.a.vf acc vf11 vf13) + (.outer.product.b.vf vf14 vf13 vf11 acc) + (.outer.product.a.vf acc vf13 vf14) + (.outer.product.b.vf vf14 vf14 vf13 acc) + (.mul.vf vf16 vf14 vf14 :mask #b111) + (.mul.x.vf acc vf0 vf16 :mask #b1000) + (.add.mul.y.vf acc vf0 vf16 acc :mask #b1000) + (.add.mul.z.vf vf16 vf0 vf16 acc :mask #b1000) + (.isqrt.vf Q vf0 vf16 :fsf #b11 :ftf #b11) + (.wait.vf) + (.mul.vf vf14 vf14 Q :mask #b111) + (.outer.product.a.vf acc vf13 vf14) + (.outer.product.b.vf vf15 vf14 vf13 acc) + (.svf (&-> arg0 quad 0) vf13) + (.svf (&-> arg0 quad 1) vf14) + (.svf (&-> arg0 quad 2) vf15) + arg0 + ) + |# + ) + +(defun matrix-4x4-determinant ((arg0 matrix)) + "Take the determinant of a 4x4 matrix, but this is wrong." + (let ((f15-0 (-> arg0 rvec x)) + (f14-0 (-> arg0 rvec y)) + (f10-0 (-> arg0 rvec z)) + (f2-0 (-> arg0 rvec w)) + (f9-0 (-> arg0 uvec x)) + (f6-0 (-> arg0 uvec y)) + (f3-0 (-> arg0 uvec z)) + (f11-0 (-> arg0 uvec w)) + (f5-0 (-> arg0 fvec x)) + (f1-0 (-> arg0 fvec y)) + (f8-0 (-> arg0 fvec z)) + (f13-0 (-> arg0 fvec w)) + (f0-0 (-> arg0 trans x)) + (f7-0 (-> arg0 trans y)) + (f4-0 (-> arg0 trans z)) + (f12-0 (-> arg0 trans w)) + ) + (- (+ (* f15-0 f6-0 f8-0 f12-0) + (* f15-0 f3-0 f13-0 f7-0) + (* f15-0 f11-0 f1-0 f4-0) + (* f14-0 f9-0 f13-0 f4-0) + (* f14-0 f3-0 f5-0 f4-0) + (* f14-0 f11-0 f8-0 f0-0) + (* f10-0 f9-0 f1-0 f12-0) + (* f10-0 f6-0 f13-0 f0-0) + (* f10-0 f11-0 f5-0 f7-0) + (* f2-0 f9-0 f1-0 f4-0) + (* f2-0 f6-0 f8-0 f0-0) + (* f2-0 f3-0 f5-0 f7-0) + ) + (+ (* f15-0 f6-0 f13-0 f4-0) + (* f15-0 f3-0 f1-0 f12-0) + (* f15-0 f11-0 f8-0 f7-0) + (* f14-0 f9-0 f8-0 f12-0) + (* f14-0 f3-0 f13-0 f0-0) + (* f14-0 f11-0 f5-0 f4-0) + (* f10-0 f9-0 f13-0 f7-0) + (* f10-0 f6-0 f5-0 f12-0) + (* f10-0 f11-0 f1-0 f0-0) + (* f2-0 f9-0 f8-0 f7-0) + (* f2-0 f6-0 f5-0 f4-0) + (* f2-0 f3-0 f1-0 f0-0) + ) + ) + ) + ) + +(defun matrix-4x4-inverse-transpose! ((arg0 matrix) (arg1 matrix)) + "Invert and transpose an entire 4x4. I think has no restrictions, other than dst != src. Unused. +The answer is wrong. The determinant function is wrong." + (let ((f0-0 (matrix-4x4-determinant arg1))) + (let ((f9-0 (-> arg1 uvec y)) + (f2-0 (-> arg1 uvec z)) + (f5-0 (-> arg1 uvec w)) + (f3-0 (-> arg1 fvec y)) + (f6-0 (-> arg1 fvec z)) + (f10-0 (-> arg1 fvec w)) + (f4-0 (-> arg1 trans y)) + (f7-0 (-> arg1 trans z)) + (f1-0 (-> arg1 trans w)) + ) + (set! (-> arg0 rvec x) (/ (- (+ (* f9-0 f6-0 f1-0) (* f2-0 f10-0 f4-0) (* f5-0 f3-0 f7-0)) + (+ (* f9-0 f10-0 f7-0) (* f5-0 f6-0 f4-0) (* f2-0 f3-0 f1-0)) + ) + f0-0 + ) + ) + ) + (let ((f9-2 (-> arg1 uvec x)) + (f2-2 (-> arg1 uvec z)) + (f5-2 (-> arg1 uvec w)) + (f3-1 (-> arg1 fvec x)) + (f6-1 (-> arg1 fvec z)) + (f10-1 (-> arg1 fvec w)) + (f4-3 (-> arg1 trans x)) + (f7-2 (-> arg1 trans z)) + (f1-6 (-> arg1 trans w)) + ) + (set! (-> arg0 rvec y) (- (/ (- (+ (* f9-2 f6-1 f1-6) (* f2-2 f10-1 f4-3) (* f5-2 f3-1 f7-2)) + (+ (* f9-2 f10-1 f7-2) (* f5-2 f6-1 f4-3) (* f2-2 f3-1 f1-6)) + ) + f0-0 + ) + ) + ) + ) + (let ((f9-4 (-> arg1 uvec x)) + (f2-4 (-> arg1 uvec y)) + (f5-4 (-> arg1 uvec w)) + (f3-2 (-> arg1 fvec x)) + (f6-2 (-> arg1 fvec y)) + (f10-2 (-> arg1 fvec w)) + (f4-6 (-> arg1 trans x)) + (f7-4 (-> arg1 trans y)) + (f1-13 (-> arg1 trans w)) + ) + (set! (-> arg0 rvec z) (/ (- (+ (* f9-4 f6-2 f1-13) (* f2-4 f10-2 f4-6) (* f5-4 f3-2 f7-4)) + (+ (* f9-4 f10-2 f7-4) (* f5-4 f6-2 f4-6) (* f2-4 f3-2 f1-13)) + ) + f0-0 + ) + ) + ) + (let ((f9-6 (-> arg1 uvec x)) + (f2-6 (-> arg1 uvec y)) + (f5-6 (-> arg1 uvec z)) + (f3-3 (-> arg1 fvec x)) + (f6-3 (-> arg1 fvec y)) + (f10-3 (-> arg1 fvec z)) + (f4-9 (-> arg1 trans x)) + (f7-6 (-> arg1 trans y)) + (f1-19 (-> arg1 trans z)) + ) + (set! (-> arg0 rvec w) (- (/ (- (+ (* f9-6 f6-3 f1-19) (* f2-6 f10-3 f4-9) (* f5-6 f3-3 f7-6)) + (+ (* f9-6 f10-3 f7-6) (* f5-6 f6-3 f4-9) (* f2-6 f3-3 f1-19)) + ) + f0-0 + ) + ) + ) + ) + (let ((f9-8 (-> arg1 rvec y)) + (f2-8 (-> arg1 rvec z)) + (f5-8 (-> arg1 rvec w)) + (f3-4 (-> arg1 fvec y)) + (f6-4 (-> arg1 fvec z)) + (f10-4 (-> arg1 fvec w)) + (f4-12 (-> arg1 trans y)) + (f7-8 (-> arg1 trans z)) + (f1-26 (-> arg1 trans w)) + ) + (set! (-> arg0 uvec x) (- (/ (- (+ (* f9-8 f6-4 f1-26) (* f2-8 f10-4 f4-12) (* f5-8 f3-4 f7-8)) + (+ (* f9-8 f10-4 f7-8) (* f5-8 f6-4 f4-12) (* f2-8 f3-4 f1-26)) + ) + f0-0 + ) + ) + ) + ) + (let ((f9-10 (-> arg1 rvec x)) + (f2-10 (-> arg1 rvec z)) + (f5-10 (-> arg1 rvec w)) + (f3-5 (-> arg1 fvec x)) + (f6-5 (-> arg1 fvec z)) + (f10-5 (-> arg1 fvec w)) + (f4-15 (-> arg1 trans x)) + (f7-10 (-> arg1 trans z)) + (f1-33 (-> arg1 trans w)) + ) + (set! (-> arg0 uvec y) (/ (- (+ (* f9-10 f6-5 f1-33) (* f2-10 f10-5 f4-15) (* f5-10 f3-5 f7-10)) + (+ (* f9-10 f10-5 f7-10) (* f5-10 f6-5 f4-15) (* f2-10 f3-5 f1-33)) + ) + f0-0 + ) + ) + ) + (let ((f9-12 (-> arg1 rvec x)) + (f2-12 (-> arg1 rvec y)) + (f5-12 (-> arg1 rvec w)) + (f3-6 (-> arg1 fvec x)) + (f6-6 (-> arg1 fvec y)) + (f10-6 (-> arg1 fvec w)) + (f4-18 (-> arg1 trans x)) + (f7-12 (-> arg1 trans y)) + (f1-39 (-> arg1 trans w)) + ) + (set! (-> arg0 uvec z) (- (/ (- (+ (* f9-12 f6-6 f1-39) (* f2-12 f10-6 f4-18) (* f5-12 f3-6 f7-12)) + (+ (* f9-12 f10-6 f7-12) (* f5-12 f6-6 f4-18) (* f2-12 f3-6 f1-39)) + ) + f0-0 + ) + ) + ) + ) + (let ((f9-14 (-> arg1 rvec x)) + (f2-14 (-> arg1 rvec y)) + (f5-14 (-> arg1 rvec z)) + (f3-7 (-> arg1 fvec x)) + (f6-7 (-> arg1 fvec y)) + (f10-7 (-> arg1 fvec z)) + (f4-21 (-> arg1 trans x)) + (f7-14 (-> arg1 trans y)) + (f1-46 (-> arg1 trans z)) + ) + (set! (-> arg0 uvec w) (/ (- (+ (* f9-14 f6-7 f1-46) (* f2-14 f10-7 f4-21) (* f5-14 f3-7 f7-14)) + (+ (* f9-14 f10-7 f7-14) (* f5-14 f6-7 f4-21) (* f2-14 f3-7 f1-46)) + ) + f0-0 + ) + ) + ) + (let ((f9-16 (-> arg1 rvec y)) + (f2-16 (-> arg1 rvec z)) + (f5-16 (-> arg1 rvec w)) + (f3-8 (-> arg1 uvec y)) + (f6-8 (-> arg1 uvec z)) + (f10-8 (-> arg1 uvec w)) + (f4-24 (-> arg1 trans y)) + (f7-16 (-> arg1 trans z)) + (f1-52 (-> arg1 trans w)) + ) + (set! (-> arg0 fvec x) (/ (- (+ (* f9-16 f6-8 f1-52) (* f2-16 f10-8 f4-24) (* f5-16 f3-8 f7-16)) + (+ (* f9-16 f10-8 f7-16) (* f5-16 f6-8 f4-24) (* f2-16 f3-8 f1-52)) + ) + f0-0 + ) + ) + ) + (let ((f9-18 (-> arg1 rvec x)) + (f2-18 (-> arg1 rvec z)) + (f5-18 (-> arg1 rvec w)) + (f3-9 (-> arg1 uvec x)) + (f6-9 (-> arg1 uvec z)) + (f10-9 (-> arg1 uvec w)) + (f4-27 (-> arg1 trans x)) + (f7-18 (-> arg1 trans z)) + (f1-58 (-> arg1 trans w)) + ) + (set! (-> arg0 fvec y) (- (/ (- (+ (* f9-18 f6-9 f1-58) (* f2-18 f10-9 f4-27) (* f5-18 f3-9 f7-18)) + (+ (* f9-18 f10-9 f7-18) (* f5-18 f6-9 f4-27) (* f2-18 f3-9 f1-58)) + ) + f0-0 + ) + ) + ) + ) + (let ((f9-20 (-> arg1 rvec x)) + (f2-20 (-> arg1 rvec y)) + (f5-20 (-> arg1 rvec w)) + (f3-10 (-> arg1 uvec x)) + (f6-10 (-> arg1 uvec y)) + (f10-10 (-> arg1 uvec w)) + (f4-30 (-> arg1 trans x)) + (f7-20 (-> arg1 trans y)) + (f1-65 (-> arg1 trans w)) + ) + (set! (-> arg0 fvec z) (/ (- (+ (* f9-20 f6-10 f1-65) (* f2-20 f10-10 f4-30) (* f5-20 f3-10 f7-20)) + (+ (* f9-20 f10-10 f7-20) (* f5-20 f6-10 f4-30) (* f2-20 f3-10 f1-65)) + ) + f0-0 + ) + ) + ) + (let ((f9-22 (-> arg1 rvec x)) + (f2-22 (-> arg1 rvec y)) + (f5-22 (-> arg1 rvec z)) + (f3-11 (-> arg1 uvec x)) + (f6-11 (-> arg1 uvec y)) + (f10-11 (-> arg1 uvec z)) + (f4-33 (-> arg1 trans x)) + (f7-22 (-> arg1 trans y)) + (f1-71 (-> arg1 trans z)) + ) + (set! (-> arg0 fvec w) (- (/ (- (+ (* f9-22 f6-11 f1-71) (* f2-22 f10-11 f4-33) (* f5-22 f3-11 f7-22)) + (+ (* f9-22 f10-11 f7-22) (* f5-22 f6-11 f4-33) (* f2-22 f3-11 f1-71)) + ) + f0-0 + ) + ) + ) + ) + (let ((f9-24 (-> arg1 rvec y)) + (f2-24 (-> arg1 rvec z)) + (f5-24 (-> arg1 rvec w)) + (f3-12 (-> arg1 uvec y)) + (f6-12 (-> arg1 uvec z)) + (f10-12 (-> arg1 uvec w)) + (f4-36 (-> arg1 fvec y)) + (f7-24 (-> arg1 fvec z)) + (f1-78 (-> arg1 fvec w)) + ) + (set! (-> arg0 trans x) (- (/ (- (+ (* f9-24 f6-12 f1-78) (* f2-24 f10-12 f4-36) (* f5-24 f3-12 f7-24)) + (+ (* f9-24 f10-12 f7-24) (* f5-24 f6-12 f4-36) (* f2-24 f3-12 f1-78)) + ) + f0-0 + ) + ) + ) + ) + (let ((f9-26 (-> arg1 rvec x)) + (f2-26 (-> arg1 rvec z)) + (f5-26 (-> arg1 rvec w)) + (f3-13 (-> arg1 uvec x)) + (f6-13 (-> arg1 uvec z)) + (f10-13 (-> arg1 uvec w)) + (f4-39 (-> arg1 fvec x)) + (f7-26 (-> arg1 fvec z)) + (f1-85 (-> arg1 fvec w)) + ) + (set! (-> arg0 trans y) (/ (- (+ (* f9-26 f6-13 f1-85) (* f2-26 f10-13 f4-39) (* f5-26 f3-13 f7-26)) + (+ (* f9-26 f10-13 f7-26) (* f5-26 f6-13 f4-39) (* f2-26 f3-13 f1-85)) + ) + f0-0 + ) + ) + ) + (let ((f9-28 (-> arg1 rvec x)) + (f2-28 (-> arg1 rvec y)) + (f5-28 (-> arg1 rvec w)) + (f3-14 (-> arg1 uvec x)) + (f6-14 (-> arg1 uvec y)) + (f10-14 (-> arg1 uvec w)) + (f4-42 (-> arg1 fvec x)) + (f7-28 (-> arg1 fvec y)) + (f1-91 (-> arg1 fvec w)) + ) + (set! (-> arg0 trans z) (- (/ (- (+ (* f9-28 f6-14 f1-91) (* f2-28 f10-14 f4-42) (* f5-28 f3-14 f7-28)) + (+ (* f9-28 f10-14 f7-28) (* f5-28 f6-14 f4-42) (* f2-28 f3-14 f1-91)) + ) + f0-0 + ) + ) + ) + ) + (let ((f8-60 (-> arg1 rvec x)) + (f1-98 (-> arg1 rvec y)) + (f5-30 (-> arg1 rvec z)) + (f2-30 (-> arg1 uvec x)) + (f6-15 (-> arg1 uvec y)) + (f9-30 (-> arg1 uvec z)) + (f4-45 (-> arg1 fvec x)) + (f7-30 (-> arg1 fvec y)) + (f3-15 (-> arg1 fvec z)) + ) + (set! (-> arg0 trans w) (/ (- (+ (* f8-60 f6-15 f3-15) (* f1-98 f9-30 f4-45) (* f5-30 f2-30 f7-30)) + (+ (* f8-60 f9-30 f7-30) (* f5-30 f6-15 f4-45) (* f1-98 f2-30 f3-15)) + ) + f0-0 + ) + ) + ) + ) + arg0 + ) + +(defun matrix-y-angle ((arg0 matrix)) + "If mat has its upper 3x3 as a rotation, gets the y axis rotation." + (let ((v1-0 (-> arg0 fvec))) + (atan (-> v1-0 x) (-> v1-0 z)) + ) + ) + +(defun matrix->trans ((arg0 matrix) (arg1 vector)) + "Multiply xyz by 1/w." + (rlet ((Q :class vf) + (vf0 :class vf) + (vf2 :class vf) + ) + (init-vf0-vector) + (.lvf vf2 (&-> arg0 trans quad)) + (.div.vf Q vf0 vf2 :fsf #b11 :ftf #b11) + (.wait.vf) + (.mul.vf vf2 vf2 Q :mask #b111) + (.nop.vf) + (.nop.vf) + (.mov.vf vf2 vf0 :mask #b1000) + (.svf (&-> arg1 quad) vf2) + arg1 + ) + ) + +(defun matrix<-trans ((arg0 matrix) (arg1 vector)) + "Set the translation." + (set! (-> arg0 trans quad) (-> arg1 quad)) + arg0 + ) + +(defun matrix->scale ((arg0 matrix) (arg1 vector)) + "Get the scale of a matrix." + (set! (-> arg1 x) (vector-length (-> arg0 rvec))) + (set! (-> arg1 y) (vector-length (-> arg0 uvec))) + (set! (-> arg1 z) (vector-length (-> arg0 fvec))) + (set! (-> arg1 w) 1.0) + arg1 + ) + +(defun matrix<-scale ((arg0 matrix) (arg1 vector)) + "Set the scale of a matrix by rescaling." + (vector-normalize! (-> arg0 rvec) (-> arg1 x)) + (vector-normalize! (-> arg0 uvec) (-> arg1 y)) + (vector-normalize! (-> arg0 fvec) (-> arg1 z)) + arg0 + ) + +(defun matrix->quat ((arg0 matrix) (arg1 quaternion)) + "Convert matrix to quaternion, works for matrix with scale. +unlike matrix->quaternion." + (let ((s5-0 (new 'stack-no-clear 'matrix))) + (let* ((a2-0 arg0) + (v1-0 (-> a2-0 rvec quad)) + (a0-1 (-> a2-0 uvec quad)) + (a1-1 (-> a2-0 fvec quad)) + (a2-1 (-> a2-0 trans quad)) + ) + (set! (-> s5-0 rvec quad) v1-0) + (set! (-> s5-0 uvec quad) a0-1) + (set! (-> s5-0 fvec quad) a1-1) + (set! (-> s5-0 trans quad) a2-1) + ) + (vector-reset! (-> s5-0 trans)) + (vector-normalize! (-> s5-0 rvec) 1.0) + (vector-normalize! (-> s5-0 uvec) 1.0) + (vector-normalize! (-> s5-0 fvec) 1.0) + (matrix->quaternion arg1 s5-0) + ) + ) + +(defun matrix<-quat ((arg0 matrix) (arg1 quaternion)) + "Modify the rotation part of a transform." + (let ((s5-0 (matrix->scale arg0 (new 'stack-no-clear 'vector))) + (s4-1 (quaternion->matrix (new 'stack-no-clear 'matrix) arg1)) + ) + (vector-normalize-copy! (-> arg0 rvec) (-> s4-1 rvec) (-> s5-0 x)) + (vector-normalize-copy! (-> arg0 uvec) (-> s4-1 uvec) (-> s5-0 y)) + (vector-normalize-copy! (-> arg0 fvec) (-> s4-1 fvec) (-> s5-0 z)) + ) + (set! (-> arg0 rvec w) 0.0) + (set! (-> arg0 uvec w) 0.0) + (set! (-> arg0 fvec w) 0.0) + arg0 + ) + +(defun matrix->transformq ((arg0 transformq) (arg1 matrix)) + "Create a transformq from a matrix. Allowing scale, etc." + (rlet ((Q :class vf) + (vf0 :class vf) + (vf2 :class vf) + ) + (init-vf0-vector) + (.lvf vf2 (&-> arg1 trans quad)) + (.div.vf Q vf0 vf2 :fsf #b11 :ftf #b11) + (.wait.vf) + (.mul.vf vf2 vf2 Q :mask #b111) + (.nop.vf) + (.nop.vf) + (.mov.vf vf2 vf0 :mask #b1000) + (.svf (&-> arg0 trans quad) vf2) + (let ((s4-0 (new 'stack-no-clear 'matrix))) + (let* ((a2-0 arg1) + (v1-0 (-> a2-0 rvec quad)) + (a0-1 (-> a2-0 uvec quad)) + (a1-1 (-> a2-0 fvec quad)) + (a2-1 (-> a2-0 trans quad)) + ) + (set! (-> s4-0 rvec quad) v1-0) + (set! (-> s4-0 uvec quad) a0-1) + (set! (-> s4-0 fvec quad) a1-1) + (set! (-> s4-0 trans quad) a2-1) + ) + (vector-normalize! (-> s4-0 rvec) 1.0) + (vector-normalize! (-> s4-0 uvec) 1.0) + (vector-normalize! (-> s4-0 fvec) 1.0) + (vector-cross! (-> s4-0 fvec) (-> s4-0 rvec) (-> s4-0 uvec)) + (vector-cross! (-> s4-0 uvec) (-> s4-0 fvec) (-> s4-0 rvec)) + (matrix->quaternion (the-as quaternion (-> arg0 rot)) s4-0) + ) + (set-vector! + (-> arg0 scale) + (vector-length (-> arg1 rvec)) + (vector-length (-> arg1 uvec)) + (vector-length (-> arg1 fvec)) + 1.0 + ) + arg0 + ) + ) + +(defmethod transform-vectors! matrix ((this _type_) (dst (inline-array vector)) (src (inline-array vector)) (count int)) + "Transform many vectors. This acts like w = 1, even if it isn't. The value of w is copied." + (rlet ((vf0 :class vf) + (vf1 :class vf) + (vf2 :class vf) + (vf3 :class vf) + (vf4 :class vf) + (vf5 :class vf) + (vf6 :class vf) + (vf7 :class vf) + (vf8 :class vf) + (acc :class vf) + (v1 :type int) + ) + (init-vf0-vector) + + ;; blez a3, L3 + (when-goto (<= count 0) end) + + ;; lqc2 vf1, 0(a0) + (.lvf vf1 (-> this vector 0)) + + ;; lqc2 vf2, 16(a0) + (.lvf vf2 (-> this vector 1)) + + ;; lqc2 vf3, 32(a0) + (.lvf vf3 (-> this vector 2)) + + ;; lqc2 vf4, 48(a0) + (.lvf vf4 (-> this vector 3)) + + ;; lqc2 vf5, 0(a2) + (.lvf vf5 (-> src 0)) + + ;; lqc2 vf6, 16(a2) + (.lvf vf6 (-> src 1)) + + (label loop-top) +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + ;;vmulaw.xyzw acc, vf4, vf0 + (.mul.w.vf acc vf4 vf0) + + ;; lqc2 vf7, 32(a2) + (.lvf vf7 (-> src 2)) + + ;;vmaddax.xyzw acc, vf1, vf5 + (.add.mul.x.vf acc vf1 vf5 acc) + + ;;lqc2 vf8, 48(a2) + (.lvf vf8 (-> src 3)) + + ;;vmadday.xyzw acc, vf2, vf5 + (.add.mul.y.vf acc vf2 vf5 acc) + + ;;daddiu a2, a2, 64 + ;;(&+! src 64) + (set! src (the (inline-array vector) (+ 64 (the int src)))) + + ;;vmaddz.xyz vf5, vf3, vf5 + (.add.mul.z.vf vf5 vf3 vf5 acc :mask #b0111) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + + ;;daddiu v1, a3, -1 + (set! v1 (- count 1)) + + ;;vmulaw.xyzw acc, vf4, vf0 + (.mul.w.vf acc vf4 vf0) + + ;;vmaddax.xyzw acc, vf1, vf6 + (.add.mul.x.vf acc vf1 vf6 acc) + + ;; vmadday.xyzw acc, vf2, vf6 + (.add.mul.y.vf acc vf2 vf6 acc) + + ;; vmaddz.xyz vf6, vf3, vf6 + (.add.mul.z.vf vf6 vf3 vf6 acc :mask #b0111) + + ;;sqc2 vf5, 0(a1) + (.svf (-> dst 0) vf5) + + ;;beq v1, r0, L3 + ;;vmulaw.xyzw acc, vf4, vf0 + (.mul.w.vf acc vf4 vf0) + (when-goto (zero? v1) end) +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + + ;;vmaddax.xyzw acc, vf1, vf7 + (.add.mul.x.vf acc vf1 vf7 acc) + ;;daddiu v1, v1, -1 + (+! v1 -1) + ;;vmadday.xyzw acc, vf2, vf7 + (.add.mul.y.vf acc vf2 vf7 acc) + ;;lqc2 vf5, 0(a2) + (.lvf vf5 (-> src 0)) + ;;vmaddz.xyz vf7, vf3, vf7 + (.add.mul.z.vf vf7 vf3 vf7 acc :mask #b0111) + ;;sqc2 vf6, 16(a1) + (.svf (-> dst 1) vf6) + + ;;beq v1, r0, L3 + ;;vmulaw.xyzw acc, vf4, vf0 + (.mul.w.vf acc vf4 vf0) + (when-goto (zero? v1) end) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + ;;vmaddax.xyzw acc, vf1, vf8 + (.add.mul.x.vf acc vf1 vf8 acc) + ;;daddiu v1, v1, -1 + (+! v1 -1) + ;;vmadday.xyzw acc, vf2, vf8 + (.add.mul.y.vf acc vf2 vf8 acc) + ;;lqc2 vf6, 16(a2) + (.lvf vf6 (-> src 1)) + ;;vmaddz.xyz vf8, vf3, vf8 + (.add.mul.z.vf vf8 vf3 vf8 acc :mask #b0111) + ;;sqc2 vf7, 32(a1) + (.svf (-> dst 2) vf7) + + ;;beq v1, r0, L3 + ;;daddiu a1, a1, 64 + ;;(&!+ dst 64) + (set! dst (the (inline-array vector) (+ 64 (the int dst)))) + (when-goto (zero? v1) end) + + ;;daddiu a3, v1, -1 + (set! count (- v1 1)) + ;;sqc2 vf8, -16(a1) + (.svf dst vf8 :offset -16) + (when-goto (not (zero? count)) loop-top) + (label end) + (none) + ) + ) + +(defun matrix-mirror! ((arg0 matrix) (arg1 vector) (arg2 vector)) + "Make a matrix that mirrors. Arguments are unclear." + (let ((f10-0 -2.0) + (f0-0 1.0) + ) + (let* ((f1-0 0.0) + (f9-0 (-> arg2 x)) + (f12-0 (-> arg2 y)) + (f11-0 (-> arg2 z)) + (f6-0 (-> arg1 x)) + (f5-0 (-> arg1 y)) + (f2-0 (-> arg1 z)) + (f3-2 (+ f0-0 (* f10-0 f9-0 f9-0))) + (f4-2 (+ f0-0 (* f10-0 f12-0 f12-0))) + (f7-2 (+ f0-0 (* f10-0 f11-0 f11-0))) + (f8-1 (* f10-0 f9-0 f12-0)) + (f9-2 (* f10-0 f9-0 f11-0)) + (f10-2 (* f10-0 f12-0 f11-0)) + (f11-4 (- f6-0 (+ (* f6-0 f3-2) (* f5-0 f8-1) (* f2-0 f9-2)))) + (f12-6 (- f5-0 (+ (* f6-0 f8-1) (* f5-0 f4-2) (* f2-0 f10-2)))) + (f2-1 (- f2-0 (+ (* f6-0 f9-2) (* f5-0 f10-2) (* f2-0 f7-2)))) + ) + (set! (-> arg0 rvec x) f3-2) + (set! (-> arg0 rvec y) f8-1) + (set! (-> arg0 rvec z) f9-2) + (set! (-> arg0 rvec w) f1-0) + (set! (-> arg0 uvec x) f8-1) + (set! (-> arg0 uvec y) f4-2) + (set! (-> arg0 uvec z) f10-2) + (set! (-> arg0 uvec w) f1-0) + (set! (-> arg0 fvec x) f9-2) + (set! (-> arg0 fvec y) f10-2) + (set! (-> arg0 fvec z) f7-2) + (set! (-> arg0 fvec w) f1-0) + (set! (-> arg0 trans x) f11-4) + (set! (-> arg0 trans y) f12-6) + (set! (-> arg0 trans z) f2-1) + ) + (set! (-> arg0 trans w) f0-0) + ) + arg0 + ) diff --git a/goal_src/jak3/engine/math/quaternion-h.gc b/goal_src/jak3/engine/math/quaternion-h.gc index 0ae50ac1ba..cd45bb31f0 100644 --- a/goal_src/jak3/engine/math/quaternion-h.gc +++ b/goal_src/jak3/engine/math/quaternion-h.gc @@ -5,5 +5,33 @@ ;; name in dgo: quaternion-h ;; dgos: GAME +(defmacro new-stack-quaternion0 () + "Get a stack quaternion that's set to 0. + This is more efficient than (new 'stack 'quaternion) because + this doesn't call the constructor." + `(let ((q (new 'stack-no-clear 'quaternion))) + (set! (-> q quad) (the-as uint128 0)) + q + ) + ) + ;; DECOMP BEGINS +(deftype quaternion (structure) + "Quaternion. Stored in xyzw order." + ((data float 4) + (x float :overlay-at (-> data 0)) + (y float :overlay-at (-> data 1)) + (z float :overlay-at (-> data 2)) + (w float :overlay-at (-> data 3)) + (vec vector :inline :overlay-at (-> data 0)) + (quad uint128 :overlay-at (-> data 0)) + ) + ) + +(define-extern quaternion-normalize! (function quaternion quaternion)) +(define-extern vector-y-angle (function vector float)) +(define-extern matrix->quaternion (function quaternion matrix quaternion)) +(define-extern quaternion->matrix (function matrix quaternion matrix)) + +(define *unity-quaternion* (new 'static 'quaternion :w 1.0)) diff --git a/goal_src/jak3/engine/math/quaternion.gc b/goal_src/jak3/engine/math/quaternion.gc index f0105ac8b7..b9f4dbd645 100644 --- a/goal_src/jak3/engine/math/quaternion.gc +++ b/goal_src/jak3/engine/math/quaternion.gc @@ -7,3 +7,1055 @@ ;; DECOMP BEGINS + +(defun quaternion-axis-angle! ((arg0 quaternion) (arg1 float) (arg2 float) (arg3 float) (arg4 float)) + "Construct a quaternion from an axis and angle. The axis should be normalized." + (let ((s5-0 (new 'stack-no-clear 'vector))) + (sincos! s5-0 (* 0.5 arg4)) + (let ((f0-2 (-> s5-0 x))) + (set! (-> arg0 x) (* arg1 f0-2)) + (set! (-> arg0 y) (* arg2 f0-2)) + (set! (-> arg0 z) (* arg3 f0-2)) + ) + (set! (-> arg0 w) (-> s5-0 y)) + ) + arg0 + ) + +(defun quaternion-vector-angle! ((arg0 quaternion) (arg1 vector) (arg2 float)) + "Construct a quaternion from an axis and angle. The axis should be normalized." + (let ((s5-0 (new 'stack-no-clear 'vector))) + (sincos! s5-0 (* 0.5 arg2)) + (let ((f0-2 (-> s5-0 x))) + (set! (-> arg0 x) (* (-> arg1 x) f0-2)) + (set! (-> arg0 y) (* (-> arg1 y) f0-2)) + (set! (-> arg0 z) (* (-> arg1 z) f0-2)) + ) + (set! (-> arg0 w) (-> s5-0 y)) + ) + arg0 + ) + +(defun vector-angle<-quaternion! ((arg0 vector) (arg1 quaternion)) + "Convert the quaternion arg1 to axis-angle form and store in arg0 (angle goes in w)" + (let* ((f0-0 1.0) + (f1-0 1.0) + (f2-0 (-> arg1 w)) + (f30-0 (/ f0-0 (sqrtf (- f1-0 (* f2-0 f2-0))))) + (f0-3 (* 2.0 (acos-rad (-> arg1 w)))) + ) + (set! (-> arg0 x) (* (-> arg1 x) f30-0)) + (set! (-> arg0 y) (* (-> arg1 y) f30-0)) + (set! (-> arg0 z) (* (-> arg1 z) f30-0)) + (set! (-> arg0 w) f0-3) + ) + arg0 + ) + +(defun quaternion-look-at! ((arg0 quaternion) (arg1 vector) (arg2 vector)) + "Look along arg1, with arg2 as up." + (let ((s5-0 (new 'stack-no-clear 'matrix))) + (vector-cross! (-> s5-0 rvec) arg2 arg1) + (vector-cross! (-> s5-0 uvec) arg1 (-> s5-0 rvec)) + (set! (-> s5-0 fvec quad) (-> arg1 quad)) + (quaternion-normalize! (matrix->quaternion arg0 s5-0)) + ) + ) + +(defun quaternion-zero! ((arg0 quaternion)) + "Set quaternion to all 0's." + (set! (-> arg0 quad) (the-as uint128 0)) + arg0 + ) + +(defun quaternion-identity! ((arg0 quaternion)) + "Set quaternion to 0,0,0,1 (identity)." + (set! (-> arg0 quad) (the-as uint128 0)) + (set! (-> arg0 w) 1.0) + arg0 + ) + +(defun quaternion-i! ((arg0 quaternion)) + "Create unit i quaternion." + (set! (-> arg0 quad) (the-as uint128 0)) + (set! (-> arg0 x) 1.0) + arg0 + ) + +(defun quaternion-j! ((arg0 quaternion)) + "Create unit j quaternion." + (set! (-> arg0 quad) (the-as uint128 0)) + (set! (-> arg0 y) 1.0) + arg0 + ) + +(defun quaternion-k! ((arg0 quaternion)) + "Create unit k quaternion." + (set! (-> arg0 quad) (the-as uint128 0)) + (set! (-> arg0 z) 1.0) + arg0 + ) + +(defun quaternion-copy! ((arg0 quaternion) (arg1 quaternion)) + "Set arg0 = arg1." + (set! (-> arg0 quad) (-> arg1 quad)) + arg0 + ) + +(defun quaternion-set! ((arg0 quaternion) (arg1 float) (arg2 float) (arg3 float) (arg4 float)) + "Set arg0 = [arg1, arg2, arg3, arg4]." + (set! (-> arg0 x) arg1) + (set! (-> arg0 y) arg2) + (set! (-> arg0 z) arg3) + (set! (-> arg0 w) arg4) + arg0 + ) + +(defun quaternion+! ((arg0 quaternion) (arg1 quaternion) (arg2 quaternion)) + "Add quaternions as vectors." + (rlet ((vf1 :class vf) + (vf2 :class vf) + ) + (.lvf vf1 (&-> arg1 quad)) + (.lvf vf2 (&-> arg2 quad)) + (.add.vf vf1 vf1 vf2) + (.svf (&-> arg0 quad) vf1) + arg0 + ) + ) + +(defun quaternion-! ((arg0 quaternion) (arg1 quaternion) (arg2 quaternion)) + "Subtract quaternions as vectors." + (rlet ((vf1 :class vf) + (vf2 :class vf) + ) + (.lvf vf1 (&-> arg1 quad)) + (.lvf vf2 (&-> arg2 quad)) + (.sub.vf vf1 vf1 vf2) + (.svf (&-> arg0 quad) vf1) + arg0 + ) + ) + +;; ERROR: Bad vector register dependency: vf2 +(defun quaternion-negate! ((arg0 quaternion) (arg1 quaternion)) + "Set arg0 = -arg1." + (rlet ((vf1 :class vf) + (vf2 :class vf) + ) + (.lvf vf1 (&-> arg1 quad)) + ;; og:preserve-this + ;; (.sub.vf vf2 vf2 vf2) + (.xor.vf vf2 vf2 vf2) + (.sub.vf vf1 vf2 vf1) + (.svf (&-> arg0 quad) vf1) + arg0 + ) + ) + +;; ERROR: Bad vector register dependency: vf2 +(defun quaternion-conjugate! ((arg0 quaternion) (arg1 quaternion)) + "Set arg0 to the conjugate of arg1 (negate only ijk). +If arg1 is normalized, this is equivalent to the inverse +NOTE: this gives you the inverse rotation." + (rlet ((vf1 :class vf) + (vf2 :class vf) + ) + (.lvf vf1 (&-> arg1 quad)) + ;; og:preserve-this + ;; (.sub.vf vf2 vf2 vf2) + (.xor.vf vf2 vf2 vf2) + (.sub.vf vf2 vf2 vf1 :mask #b111) + (.add.vf vf2 vf2 vf1 :mask #b1000) + (.svf (&-> arg0 quad) vf2) + arg0 + ) + ) + +(defun quaternion-float*! ((arg0 quaternion) (arg1 quaternion) (arg2 float)) + "Multiply each element." + (rlet ((vf1 :class vf) + (vf2 :class vf) + ) + (.lvf vf1 (&-> arg1 quad)) + (.mov vf2 arg2) + (.mul.x.vf vf1 vf1 vf2) + (.svf (&-> arg0 quad) vf1) + arg0 + ) + ) + +(defun quaternion-float/! ((arg0 quaternion) (arg1 quaternion) (arg2 float)) + "Divide each element." + (let ((f0-1 (/ 1.0 arg2))) + (quaternion-float*! arg0 arg1 f0-1) + ) + arg0 + ) + +(defun quaternion-norm2 ((arg0 quaternion)) + "Get the squared norm of a quaternion." + (local-vars (v0-0 float)) + (rlet ((acc :class vf) + (vf0 :class vf) + (vf1 :class vf) + ) + (init-vf0-vector) + (.lvf vf1 (&-> arg0 quad)) + (.mul.vf vf1 vf1 vf1) + (.add.z.vf acc vf1 vf1 :mask #b1000) + (.add.mul.y.vf acc vf0 vf1 acc :mask #b1000) + (.add.mul.x.vf vf1 vf0 vf1 acc :mask #b1000) + (.add.w.vf vf1 vf0 vf1) + (.mov v0-0 vf1) + v0-0 + ) + ) + +(defun quaternion-norm ((arg0 quaternion)) + "Get the norm of a quaternion." + (local-vars (v1-1 float)) + (rlet ((acc :class vf) + (vf0 :class vf) + (vf1 :class vf) + ) + (init-vf0-vector) + (.lvf vf1 (&-> arg0 quad)) + (.mul.vf vf1 vf1 vf1) + (.add.z.vf acc vf1 vf1 :mask #b1000) + (.add.mul.y.vf acc vf0 vf1 acc :mask #b1000) + (.add.mul.x.vf vf1 vf0 vf1 acc :mask #b1000) + (.add.w.vf vf1 vf0 vf1) + (.mov v1-1 vf1) + (sqrtf v1-1) + ) + ) + +(defun quaternion-normalize! ((arg0 quaternion)) + "Normalize a quaternion." + (rlet ((acc :class vf) + (Q :class vf) + (vf0 :class vf) + (vf1 :class vf) + (vf2 :class vf) + ) + (init-vf0-vector) + (.lvf vf1 (&-> arg0 quad)) + (.mul.vf vf2 vf1 vf1) + (.add.z.vf acc vf2 vf2 :mask #b1000) + (.add.mul.y.vf acc vf0 vf2 acc :mask #b1000) + (.add.mul.x.vf vf2 vf0 vf2 acc :mask #b1000) + (.isqrt.vf Q vf0 vf2 :fsf #b11 :ftf #b11) + ;; og:preserve-this + ;; (.wait.vf) + (.mul.vf vf2 vf1 Q) + ;; (.nop.vf) + ;; (.nop.vf) + (.svf (&-> arg0 quad) vf2) + arg0 + ) + ) + +;; ERROR: Bad vector register dependency: vf3 +(defun quaternion-inverse! ((arg0 quaternion) (arg1 quaternion)) + "Invert a quaternion. The inverse will satisfy q * q^-1 = identity, even if q is not normalized. +If your quaternion is normalized, it is faster/more accurate to do quaternion-conjugate!" + (rlet ((acc :class vf) + (Q :class vf) + (vf0 :class vf) + (vf1 :class vf) + (vf2 :class vf) + (vf3 :class vf) + ) + (init-vf0-vector) + (.lvf vf1 (&-> arg1 quad)) + (.mul.vf vf2 vf1 vf1) + ;; og:preserve-this + ;; (.sub.vf vf3 vf3 vf3) + (.xor.vf vf3 vf3 vf3) + (.add.z.vf acc vf2 vf2 :mask #b1000) + (.add.mul.y.vf acc vf0 vf2 acc :mask #b1000) + (.add.mul.x.vf vf2 vf0 vf2 acc :mask #b1000) + (.sub.vf vf3 vf3 vf1 :mask #b111) + (.div.vf Q vf0 vf2 :fsf #b11 :ftf #b11) + (.add.vf vf3 vf3 vf1 :mask #b1000) + (.wait.vf) + (.mul.vf vf3 vf3 Q) + (.nop.vf) + (.nop.vf) + (.svf (&-> arg0 quad) vf3) + arg0 + ) + ) + +(defun quaternion-dot ((arg0 quaternion) (arg1 quaternion)) + "Treat quaternions as vectors and take the dot product." + (local-vars (v0-0 float)) + (rlet ((acc :class vf) + (vf0 :class vf) + (vf1 :class vf) + (vf2 :class vf) + ) + (init-vf0-vector) + (.lvf vf1 (&-> arg0 quad)) + (.lvf vf2 (&-> arg1 quad)) + (.mul.vf vf1 vf1 vf2) + (.add.z.vf acc vf1 vf1 :mask #b1000) + (.add.mul.y.vf acc vf0 vf1 acc :mask #b1000) + (.add.mul.x.vf vf1 vf0 vf1 acc :mask #b1000) + (.add.w.vf vf1 vf0 vf1) + (.mov v0-0 vf1) + v0-0 + ) + ) + +(defun quaternion*! ((arg0 quaternion) (arg1 quaternion) (arg2 quaternion)) + "Real quaternion multiplication." + (rlet ((acc :class vf) + (vf0 :class vf) + (vf1 :class vf) + (vf2 :class vf) + (vf3 :class vf) + (vf4 :class vf) + ) + (init-vf0-vector) + (.lvf vf1 (&-> arg1 quad)) + (.lvf vf2 (&-> arg2 quad)) + (.sub.vf vf4 vf0 vf0 :mask #b1000) + (.mul.vf vf3 vf1 vf2) + (.outer.product.a.vf acc vf1 vf2) + (.outer.product.b.vf vf4 vf2 vf1 acc) + (.mul.w.vf acc vf1 vf2) + (.add.mul.w.vf acc vf2 vf1 acc) + (.sub.mul.w.vf acc vf0 vf3 acc :mask #b1000) + (.sub.mul.z.vf acc vf0 vf3 acc :mask #b1000) + (.sub.mul.y.vf acc vf0 vf3 acc :mask #b1000) + (.sub.mul.x.vf acc vf0 vf3 acc :mask #b1000) + (.add.mul.w.vf vf1 vf4 vf0 acc) + (.svf (&-> arg0 quad) vf1) + arg0 + ) + ) + +(defun quaternion-right-mult-matrix! ((arg0 matrix) (arg1 quaternion)) + "Place quaternion coefficients into a matrix. +You can convert a quaternion to a matrix by taking the product of this +right-mult and left-mult matrix, but this method is not used. +Instead, quaternion->matrix is a more efficient implementation." + (let ((f3-0 (-> arg1 x)) + (f2-0 (-> arg1 y)) + (f1-0 (-> arg1 z)) + (f0-0 (-> arg1 w)) + ) + (set! (-> arg0 rvec x) f0-0) + (set! (-> arg0 rvec y) f1-0) + (set! (-> arg0 rvec z) (- f2-0)) + (set! (-> arg0 rvec w) f3-0) + (set! (-> arg0 uvec x) (- f1-0)) + (set! (-> arg0 uvec y) f0-0) + (set! (-> arg0 uvec z) f3-0) + (set! (-> arg0 uvec w) f2-0) + (set! (-> arg0 fvec x) f2-0) + (set! (-> arg0 fvec y) (- f3-0)) + (set! (-> arg0 fvec z) f0-0) + (set! (-> arg0 fvec w) f1-0) + (set! (-> arg0 trans x) (- f3-0)) + (set! (-> arg0 trans y) (- f2-0)) + (set! (-> arg0 trans z) (- f1-0)) + (set! (-> arg0 trans w) f0-0) + ) + arg0 + ) + +(defun quaternion-left-mult-matrix! ((arg0 matrix) (arg1 quaternion)) + "Place quaternion coefficients into a matrix. Unused." + (let ((f2-0 (-> arg1 x)) + (f1-0 (-> arg1 y)) + (f0-0 (-> arg1 z)) + ) + (let ((f3-0 (-> arg1 w))) + (set! (-> arg0 rvec x) f2-0) + (set! (-> arg0 rvec y) f3-0) + (set! (-> arg0 rvec z) (- f0-0)) + (set! (-> arg0 rvec w) f1-0) + (set! (-> arg0 uvec x) f1-0) + (set! (-> arg0 uvec y) f0-0) + (set! (-> arg0 uvec z) f3-0) + (set! (-> arg0 uvec w) (- f3-0)) + (set! (-> arg0 fvec x) f0-0) + (set! (-> arg0 fvec y) (- f1-0)) + (set! (-> arg0 fvec z) f2-0) + (set! (-> arg0 fvec w) f3-0) + (set! (-> arg0 trans x) f3-0) + ) + (set! (-> arg0 trans y) (- f2-0)) + (set! (-> arg0 trans z) (- f1-0)) + (set! (-> arg0 trans w) (- f0-0)) + ) + arg0 + ) + +(defun quaternion->matrix ((arg0 matrix) (arg1 quaternion)) + "Convert quaternion to matrix." + (rlet ((acc :class vf) + (vf0 :class vf) + (vf1 :class vf) + (vf2 :class vf) + (vf3 :class vf) + (vf4 :class vf) + (vf5 :class vf) + ) + (init-vf0-vector) + (.lvf vf1 (&-> arg1 quad)) + (.add.vf vf5 vf1 vf1) + (.add.w.vf vf2 vf0 vf1 :mask #b1) + (.add.z.vf vf2 vf0 vf1 :mask #b10) + (.sub.y.vf vf2 vf0 vf1 :mask #b100) + (.sub.w.vf vf2 vf0 vf0 :mask #b1000) + (.sub.z.vf vf3 vf0 vf1 :mask #b1) + (.add.w.vf vf3 vf0 vf1 :mask #b10) + (.add.x.vf vf3 vf0 vf1 :mask #b100) + (.sub.w.vf vf3 vf0 vf0 :mask #b1000) + (.add.y.vf vf4 vf0 vf1 :mask #b1) + (.sub.x.vf vf4 vf0 vf1 :mask #b10) + (.add.w.vf vf4 vf0 vf1 :mask #b100) + (.sub.w.vf vf4 vf0 vf0 :mask #b1000) + (.outer.product.a.vf acc vf5 vf2) + (.outer.product.b.vf vf2 vf2 vf5 acc) + (.outer.product.a.vf acc vf5 vf3) + (.outer.product.b.vf vf3 vf3 vf5 acc) + (.outer.product.a.vf acc vf5 vf4) + (.outer.product.b.vf vf4 vf4 vf5 acc) + (.add.w.vf vf2 vf2 vf0 :mask #b1) + (.add.w.vf vf3 vf3 vf0 :mask #b10) + (.add.w.vf vf4 vf4 vf0 :mask #b100) + (.svf (&-> arg0 trans quad) vf0) + (.svf (&-> arg0 rvec quad) vf2) + (.svf (&-> arg0 uvec quad) vf3) + (.svf (&-> arg0 fvec quad) vf4) + arg0 + ) + ) + +(defun quaternion->matrix-2 ((arg0 matrix) (arg1 quaternion)) + "Unused alternate quaternion->matrix function." + (/ 0 0) + arg0 + ; (local-vars (v1-1 uint128) (a1-1 uint128) (a1-2 uint128) (a2-0 uint128) (a3-0 uint128)) + ; (rlet ((acc :class vf) + ; (vf0 :class vf) + ; (vf1 :class vf) + ; (vf2 :class vf) + ; (vf3 :class vf) + ; (vf4 :class vf) + ; (vf5 :class vf) + ; (vf6 :class vf) + ; (vf7 :class vf) + ; (vf8 :class vf) + ; ) + ; (init-vf0-vector) + ; (let ((v1-0 (-> arg1 vec quad))) + ; (.pexew a1-1 v1-0) + ; (.mov vf1 v1-0) + ; (.prot3w a2-0 a1-1) + ; (.pcpyud a1-2 v1-0 a1-1) + ; (.mov vf4 a2-0) + ; (let ((a2-1 #x3f800000)) + ; (.add.vf vf5 vf1 vf1) + ; (.sub.y.vf vf4 vf0 vf4 :mask #b10) + ; (.pextlw a3-0 v1-0 a1-2) + ; (.mov vf3 a1-2) + ; (.pextuw v1-1 v1-0 a3-0) + ; (.mov vf2 v1-1) + ; (set! (-> arg0 trans quad) (the-as uint128 0)) + ; (.sub.x.vf vf3 vf0 vf3 :mask #b1) + ; (set! (-> arg0 trans w) (the-as float a2-1)) + ; (.sub.z.vf vf2 vf0 vf2 :mask #b100) + ; (.outer.product.a.vf acc vf5 vf4) + ; (.outer.product.b.vf vf8 vf4 vf5 acc) + ; (.outer.product.a.vf acc vf5 vf3) + ; (.outer.product.b.vf vf7 vf3 vf5 acc) + ; (.outer.product.a.vf acc vf5 vf2) + ; (.outer.product.b.vf vf6 vf2 vf5 acc) + ; (.add.w.vf vf8 vf8 vf0 :mask #b100) + ; (.add.w.vf vf7 vf7 vf0 :mask #b10) + ; (.add.w.vf vf6 vf6 vf0 :mask #b1) + ; (.svf (&-> arg0 quad 2) vf8) + ; (set! (-> arg0 data 11) (the-as float a2-1)) + ; (.svf (&-> arg0 quad 1) vf7) + ; (set! (-> arg0 data 7) (the-as float a2-1)) + ; (.svf (&-> arg0 quad 0) vf6) + ; (set! (-> arg0 data 3) (the-as float a2-1)) + ; ) + ; ) + ; arg0 + ; ) + ) + +(defun matrix->quaternion ((arg0 quaternion) (arg1 matrix)) + "Convert a rotation matrix to a quaternion." + (let ((f0-2 (+ (-> arg1 rvec x) (-> arg1 uvec y) (-> arg1 fvec z)))) + (cond + ((< 0.0 f0-2) + (let ((f0-4 (sqrtf (+ 1.0 f0-2)))) + (set! (-> arg0 w) (* 0.5 f0-4)) + (let ((f0-5 (/ 0.5 f0-4))) + (set! (-> arg0 x) (* f0-5 (- (-> arg1 uvec z) (-> arg1 fvec y)))) + (set! (-> arg0 y) (* f0-5 (- (-> arg1 fvec x) (-> arg1 rvec z)))) + (set! (-> arg0 z) (* f0-5 (- (-> arg1 rvec y) (-> arg1 uvec x)))) + ) + ) + ) + (else + (let ((a2-0 0) + (a3-0 1) + (v1-4 2) + ) + (when (< (-> arg1 rvec x) (-> arg1 uvec y)) + (set! a2-0 1) + (set! a3-0 2) + (set! v1-4 0) + ) + (when (< (-> (the-as (pointer float) (+ (+ (* a2-0 4) (* a2-0 16)) (the-as int arg1)))) (-> arg1 fvec z)) + (set! a2-0 2) + (set! a3-0 0) + (set! v1-4 1) + ) + (let ((f0-12 + (sqrtf + (+ (- 1.0 + (+ (-> (the-as (pointer float) (+ (+ (* a3-0 4) (* a3-0 16)) (the-as int arg1)))) + (-> (the-as (pointer float) (+ (+ (* v1-4 4) (* v1-4 16)) (the-as int arg1)))) + ) + ) + (-> (the-as (pointer float) (+ (+ (* a2-0 4) (* a2-0 16)) (the-as int arg1)))) + ) + ) + ) + ) + (set! (-> arg0 data a2-0) (* 0.5 f0-12)) + (if (!= f0-12 0.0) + (set! f0-12 (/ 0.5 f0-12)) + ) + (set! (-> arg0 w) + (* (- (-> (the-as (pointer float) (+ (+ (* v1-4 4) (* a3-0 16)) (the-as int arg1)))) + (-> (the-as (pointer float) (+ (+ (* a3-0 4) (* v1-4 16)) (the-as int arg1)))) + ) + f0-12 + ) + ) + (set! (-> arg0 data a3-0) + (* (+ (-> (the-as (pointer float) (+ (+ (* a3-0 4) (* a2-0 16)) (the-as int arg1)))) + (-> (the-as (pointer float) (+ (+ (* a2-0 4) (* a3-0 16)) (the-as int arg1)))) + ) + f0-12 + ) + ) + (set! (-> arg0 data v1-4) + (* (+ (-> (the-as (pointer float) (+ (+ (* v1-4 4) (* a2-0 16)) (the-as int arg1)))) + (-> (the-as (pointer float) (+ (+ (* a2-0 4) (* v1-4 16)) (the-as int arg1)))) + ) + f0-12 + ) + ) + ) + ) + ) + ) + ) + arg0 + ) + +(defun matrix-with-scale->quaternion ((arg0 quaternion) (arg1 matrix)) + "Convert a matrix with a rotation and scale into a quaternion (just the rotation)." + (local-vars (a1-4 float)) + (rlet ((vf1 :class vf) + (vf2 :class vf) + (vf3 :class vf) + (vf4 :class vf) + (vf5 :class vf) + (vf6 :class vf) + (vf7 :class vf) + ) + (let ((v1-0 (new 'stack-no-clear 'matrix))) + (set! (-> v1-0 rvec quad) (the-as uint128 0)) + (set! (-> v1-0 uvec quad) (the-as uint128 0)) + (set! (-> v1-0 fvec quad) (the-as uint128 0)) + (set! (-> v1-0 trans quad) (the-as uint128 0)) + (let* ((f0-1 (vector-dot (-> arg1 rvec) (-> arg1 rvec))) + (f1-1 (vector-dot (-> arg1 uvec) (-> arg1 uvec))) + (f2-1 (vector-dot (-> arg1 fvec) (-> arg1 fvec))) + (f0-3 (/ 1.0 (sqrtf f0-1))) + (f1-3 (/ 1.0 (sqrtf f1-1))) + (f2-3 (/ 1.0 (sqrtf f2-1))) + ) + (.lvf vf1 (&-> arg1 rvec quad)) + (.lvf vf2 (&-> arg1 uvec quad)) + (.lvf vf3 (&-> arg1 fvec quad)) + (.lvf vf4 (&-> arg1 trans quad)) + (let ((a1-1 f0-3)) + (.mov vf5 a1-1) + ) + (let ((a1-2 f1-3)) + (.mov vf6 a1-2) + ) + (let ((a1-3 f2-3)) + (.mov vf7 a1-3) + ) + ) + (.mul.x.vf vf1 vf1 vf5) + (.mul.x.vf vf2 vf2 vf6) + (.mul.x.vf vf3 vf3 vf7) + (.svf (&-> v1-0 rvec quad) vf1) + (.svf (&-> v1-0 uvec quad) vf2) + (.svf (&-> v1-0 fvec quad) vf3) + (.svf (&-> v1-0 trans quad) vf4) + (.mov a1-4 vf4) + (matrix->quaternion arg0 v1-0) + ) + ) + ) + +(defun quaternion-vector-len ((arg0 quaternion)) + "Assuming quaternion is normalized, get the length of the xyz part." + (let ((f0-0 1.0) + (f1-0 (-> arg0 w)) + ) + (sqrtf (- f0-0 (* f1-0 f1-0))) + ) + ) + +(defun quaternion-log! ((arg0 quaternion) (arg1 quaternion)) + "Take the log of a quaternion. Unused." + (cond + ((= (-> arg1 w) 0.0) + (set! (-> arg0 x) (* 1.5707963 (-> arg1 x))) + (set! (-> arg0 y) (* 1.5707963 (-> arg1 y))) + (set! (-> arg0 z) (* 1.5707963 (-> arg1 z))) + ) + (else + (let* ((f30-0 (quaternion-vector-len arg1)) + (f0-9 (/ (atan2-rad (-> arg1 w) f30-0) f30-0)) + ) + (set! (-> arg0 x) (* (-> arg1 x) f0-9)) + (set! (-> arg0 y) (* (-> arg1 y) f0-9)) + (set! (-> arg0 z) (* (-> arg1 z) f0-9)) + ) + ) + ) + arg0 + ) + +(defun quaternion-exp! ((arg0 quaternion) (arg1 quaternion)) + "Quaternion exponentiation. Unused." + (let ((f30-0 (vector-length (the-as vector arg1)))) + (cond + ((= f30-0 0.0) + (set! (-> arg0 x) 0.0) + (set! (-> arg0 y) 0.0) + (set! (-> arg0 z) 0.0) + (set! (-> arg0 w) 1.0) + ) + (else + (let ((s5-0 (new 'stack-no-clear 'vector))) + (sincos-rad! s5-0 f30-0) + (let ((f0-6 (/ (-> s5-0 x) f30-0))) + (set! (-> arg0 x) (* (-> arg1 x) f0-6)) + (set! (-> arg0 y) (* (-> arg1 y) f0-6)) + (set! (-> arg0 z) (* (-> arg1 z) f0-6)) + ) + (set! (-> arg0 w) (-> s5-0 y)) + ) + ) + ) + ) + arg0 + ) + +(defun quaternion-slerp! ((arg0 quaternion) (arg1 quaternion) (arg2 quaternion) (arg3 float)) + "Real quaternion slerp. Spherical-linear interpolation is a nice way to interpolate +between quaternions." + (local-vars (v1-15 float)) + (rlet ((acc :class vf) + (vf1 :class vf) + (vf2 :class vf) + (vf3 :class vf) + (vf4 :class vf) + ) + (let ((f0-0 (quaternion-dot arg1 arg2)) + (f30-0 1.0) + ) + (when (< f0-0 0.0) + (set! f0-0 (- f0-0)) + (set! f30-0 -1.0) + ) + (cond + ((< (- 1.0 f0-0) 0.0001) + (let ((v1-7 (- 1.0 arg3))) + (.mov vf1 v1-7) + ) + (let ((v1-8 (* arg3 f30-0))) + (.mov vf2 v1-8) + ) + (.lvf vf3 (&-> arg1 quad)) + (.lvf vf4 (&-> arg2 quad)) + (.mul.x.vf acc vf3 vf1) + (.add.mul.x.vf vf3 vf4 vf2 acc) + (.svf (&-> arg0 quad) vf3) + (quaternion-normalize! arg0) + ) + (else + (let* ((f1-4 1.0) + (f2-1 f0-0) + (f1-6 (sqrtf (- f1-4 (* f2-1 f2-1)))) + (f0-6 (/ (- f1-6 f0-0) (+ f1-6 f0-0))) + (f28-0 (/ 1.0 f1-6)) + ) + (let ((f0-7 (atan-series-rad f0-6)) + (s2-0 (new 'stack-no-clear 'vector)) + ) + (set! (-> s2-0 x) (* (- 1.0 arg3) f0-7)) + (set! (-> s2-0 y) (* arg3 f0-7 f30-0)) + (vector-sin-rad! s2-0 s2-0) + (.lvf vf1 (&-> s2-0 quad)) + ) + (let ((v1-14 f28-0)) + (.mov vf2 v1-14) + ) + ) + (.mul.x.vf vf1 vf1 vf2) + (.lvf vf3 (&-> arg1 quad)) + (.lvf vf4 (&-> arg2 quad)) + (.mul.x.vf acc vf3 vf1) + (.add.mul.y.vf vf3 vf4 vf1 acc) + (.svf (&-> arg0 quad) vf3) + (.mov v1-15 vf3) + ) + ) + ) + arg0 + ) + ) + +(defun quaternion-pseudo-slerp! ((arg0 quaternion) (arg1 quaternion) (arg2 quaternion) (arg3 float)) + "This is a bad interpolation between quaternions. It lerps then normalizes. +It will behave extremely poorly for 180 rotations. +It is unused." + (rlet ((acc :class vf) + (vf1 :class vf) + (vf2 :class vf) + (vf3 :class vf) + (vf4 :class vf) + ) + (let ((f1-0 (quaternion-dot arg1 arg2)) + (f0-0 1.0) + ) + (when (< f1-0 0.0) + (- f1-0) + (set! f0-0 -1.0) + ) + (let ((v1-5 (- 1.0 arg3))) + (.mov vf1 v1-5) + ) + (let ((v1-6 (* arg3 f0-0))) + (.mov vf2 v1-6) + ) + ) + (.lvf vf3 (&-> arg1 quad)) + (.lvf vf4 (&-> arg2 quad)) + (.mul.x.vf acc vf3 vf1) + (.add.mul.x.vf vf3 vf4 vf2 acc) + (.svf (&-> arg0 quad) vf3) + (quaternion-normalize! arg0) + arg0 + ) + ) + +(defun quaternion-pseudo-seek ((arg0 quaternion) (arg1 quaternion) (arg2 quaternion) (arg3 float)) + "Seek one quaternion toward another. Not using real slerp, so this is only good if the quaternions +are pretty similar." + (let ((s3-0 (new 'stack-no-clear 'quaternion))) + (let ((s5-0 (new 'stack-no-clear 'quaternion))) + (quaternion-copy! s3-0 arg2) + (if (< (quaternion-dot s3-0 arg1) 0.0) + (quaternion-negate! s3-0 s3-0) + ) + (quaternion-! s5-0 s3-0 arg1) + (let ((f0-1 (quaternion-norm2 s5-0)) + (f1-1 arg3) + ) + (if (< (* f1-1 f1-1) f0-1) + (quaternion-float*! s5-0 s5-0 (/ arg3 (sqrtf f0-1))) + ) + ) + (quaternion+! s3-0 arg1 s5-0) + ) + (quaternion-normalize! s3-0) + (quaternion-copy! arg0 s3-0) + ) + ) + +(defun quaternion-smooth-seek! ((arg0 quaternion) (arg1 quaternion) (arg2 quaternion) (arg3 float)) + "Another hacky rotation interpolation." + (let ((gp-0 (new 'stack-no-clear 'quaternion))) + (quaternion-copy! (the-as quaternion (&-> gp-0 x)) arg2) + (if (< (quaternion-dot (the-as quaternion (&-> gp-0 x)) arg1) 0.0) + (quaternion-negate! (the-as quaternion (&-> gp-0 x)) (the-as quaternion (&-> gp-0 x))) + ) + (quaternion-! (&+ gp-0 16) (the-as quaternion (&-> gp-0 x)) arg1) + (quaternion-float*! (&+ gp-0 16) (&+ gp-0 16) (fmin 1.0 arg3)) + (quaternion+! (the-as quaternion (&-> gp-0 x)) arg1 (&+ gp-0 16)) + (quaternion-normalize! (the-as quaternion (&-> gp-0 x))) + (quaternion-copy! arg0 (the-as quaternion (&-> gp-0 x))) + ) + ) + +(defun quaternion-zxy! ((arg0 quaternion) (arg1 vector)) + "Make a quaternion from a sequence of z, x, y axis rotations." + (rlet ((acc :class vf) + (vf0 :class vf) + (vf1 :class vf) + (vf2 :class vf) + (vf3 :class vf) + (vf4 :class vf) + (vf5 :class vf) + (vf6 :class vf) + (vf7 :class vf) + ) + (init-vf0-vector) + (let ((s4-0 (new 'stack-no-clear 'vector)) + (gp-0 (new 'stack-no-clear 'vector)) + (s5-0 (new 'stack-no-clear 'vector)) + ) + (vector-rad<-vector-deg/2! s4-0 arg1) + (vector-sincos-rad! gp-0 s5-0 s4-0) + (.lvf vf1 (&-> gp-0 quad)) + (.lvf vf2 (&-> s5-0 quad)) + ) + (.mul.x.vf vf4 vf0 vf1 :mask #b1000) + (.add.vf vf4 vf0 vf2 :mask #b111) + (.sub.vf vf4 vf0 vf4 :mask #b110) + (.add.vf vf3 vf0 vf1 :mask #b111) + (.mul.x.vf vf3 vf0 vf2 :mask #b1000) + (.outer.product.a.vf acc vf1 vf1) + (.outer.product.b.vf vf6 vf0 vf0 acc) + (.outer.product.a.vf acc vf2 vf2) + (.outer.product.b.vf vf5 vf0 vf0 acc) + (.mul.x.vf vf6 vf0 vf6 :mask #b1000) + (.mul.x.vf vf5 vf0 vf5 :mask #b1000) + (.mul.vf acc vf6 vf4) + (.add.mul.vf vf7 vf5 vf3 acc) + (.svf (&-> arg0 quad) vf7) + arg0 + ) + ) + +(defun vector-x-quaternion! ((arg0 vector) (arg1 quaternion)) + "Get the first row of the rotation matrix for this quaternion." + (let ((s5-0 (new 'stack-no-clear 'matrix))) + (set! (-> s5-0 rvec quad) (the-as uint128 0)) + (set! (-> s5-0 uvec quad) (the-as uint128 0)) + (set! (-> s5-0 fvec quad) (the-as uint128 0)) + (set! (-> s5-0 trans quad) (the-as uint128 0)) + (quaternion->matrix s5-0 arg1) + (set! (-> arg0 quad) (-> s5-0 rvec quad)) + ) + arg0 + ) + +(defun vector-y-quaternion! ((arg0 vector) (arg1 quaternion)) + "Get the second row of the rotation matrix for this quaternion." + (let ((s5-0 (new 'stack-no-clear 'matrix))) + (set! (-> s5-0 rvec quad) (the-as uint128 0)) + (set! (-> s5-0 uvec quad) (the-as uint128 0)) + (set! (-> s5-0 fvec quad) (the-as uint128 0)) + (set! (-> s5-0 trans quad) (the-as uint128 0)) + (quaternion->matrix s5-0 arg1) + (set! (-> arg0 quad) (-> s5-0 uvec quad)) + ) + arg0 + ) + +(defun vector-z-quaternion! ((arg0 vector) (arg1 quaternion)) + "Get the third row of the rotation matrix for this quaternion." + (let ((s5-0 (new 'stack-no-clear 'matrix))) + (set! (-> s5-0 rvec quad) (the-as uint128 0)) + (set! (-> s5-0 uvec quad) (the-as uint128 0)) + (set! (-> s5-0 fvec quad) (the-as uint128 0)) + (set! (-> s5-0 trans quad) (the-as uint128 0)) + (quaternion->matrix s5-0 arg1) + (set! (-> arg0 quad) (-> s5-0 fvec quad)) + ) + arg0 + ) + +(defun quaternion-x-angle ((arg0 quaternion)) + "Get the x rotation angle. Not very efficient." + (let ((v1-1 (vector-y-quaternion! (new 'stack-no-clear 'vector) arg0))) + (atan (-> v1-1 z) (-> v1-1 y)) + ) + ) + +(defun quaternion-y-angle ((arg0 quaternion)) + "Get the y rotation angle. Not very efficient." + (let ((v1-1 (vector-z-quaternion! (new 'stack-no-clear 'vector) arg0))) + (atan (-> v1-1 x) (-> v1-1 z)) + ) + ) + +(defun quaternion-z-angle ((arg0 quaternion)) + "Get the z rotation angle. Not very efficient." + (let ((v1-1 (vector-y-quaternion! (new 'stack-no-clear 'vector) arg0))) + (atan (-> v1-1 x) (-> v1-1 y)) + ) + ) + +(defun quaternion-vector-y-angle ((arg0 quaternion) (arg1 vector)) + "Not sure. Angle between quaternion and axis, projected in xz plane?" + (let ((f30-0 (quaternion-y-angle arg0)) + (f0-2 (atan (-> arg1 x) (-> arg1 z))) + ) + (deg-diff f30-0 f0-2) + ) + ) + +(defun quaternion-rotate-local-x! ((arg0 quaternion) (arg1 quaternion) (arg2 float)) + "Rotate existing quaternion along x axis." + (let ((a2-1 (quaternion-vector-angle! (new-stack-quaternion0) (new 'static 'vector :x 1.0 :w 1.0) arg2))) + (quaternion-normalize! (quaternion*! arg0 arg1 a2-1)) + ) + ) + +(defun quaternion-rotate-local-y! ((arg0 quaternion) (arg1 quaternion) (arg2 float)) + "Rotate existing quaternion along y axis." + (let ((a2-1 (quaternion-vector-angle! (new-stack-quaternion0) (new 'static 'vector :y 1.0 :w 1.0) arg2))) + (quaternion-normalize! (quaternion*! arg0 arg1 a2-1)) + ) + ) + +(defun quaternion-rotate-local-z! ((arg0 quaternion) (arg1 quaternion) (arg2 float)) + "Rotate existing quaternion along z axis." + (let ((a2-1 (quaternion-vector-angle! (new-stack-quaternion0) (new 'static 'vector :z 1.0 :w 1.0) arg2))) + (quaternion-normalize! (quaternion*! arg0 arg1 a2-1)) + ) + ) + +(defun quaternion-rotate-y! ((arg0 quaternion) (arg1 quaternion) (arg2 float)) + "Rotate existing quaternion along y axis (right multiply)." + (let ((a1-2 (quaternion-vector-angle! (new-stack-quaternion0) (new 'static 'vector :y 1.0 :w 1.0) arg2))) + (quaternion-normalize! (quaternion*! arg0 a1-2 arg1)) + ) + ) + +(defun quaternion-rotate-x! ((arg0 quaternion) (arg1 quaternion) (arg2 float)) + "Rotate existing quaternion along x axis (right multiply)." + (let ((a1-3 (quaternion-vector-angle! (new-stack-quaternion0) (vector-x-quaternion! (new-stack-vector0) arg1) arg2)) + ) + (quaternion-normalize! (quaternion*! arg0 a1-3 arg1)) + ) + ) + +(defun quaternion-rotate-z! ((arg0 quaternion) (arg1 quaternion) (arg2 float)) + "Rotate existing quaternion along z axis (right multiply)." + (let ((a1-3 (quaternion-vector-angle! (new-stack-quaternion0) (vector-z-quaternion! (new-stack-vector0) arg1) arg2)) + ) + (quaternion-normalize! (quaternion*! arg0 a1-3 arg1)) + ) + ) + +(defun quaternion-delta-y ((arg0 quaternion) (arg1 quaternion)) + "Difference in yaw between two quaternions." + (acos (vector-dot + (vector-z-quaternion! (new 'stack-no-clear 'vector) arg0) + (vector-z-quaternion! (new 'stack-no-clear 'vector) arg1) + ) + ) + ) + +(defun quaternion-rotate-y-to-vector! ((arg0 quaternion) (arg1 quaternion) (arg2 quaternion) (arg3 float)) + (let ((s5-0 (new 'stack-no-clear 'quaternion))) + (let ((t9-0 vector-xz-normalize!) + (a0-1 (new 'stack-no-clear 'vector)) + ) + (set! (-> a0-1 x) (-> arg2 x)) + (set! (-> a0-1 y) 0.0) + (set! (-> a0-1 z) (-> arg2 z)) + (set! (-> a0-1 w) 1.0) + (let ((s0-0 (t9-0 a0-1 1.0))) + (quaternion-from-two-vectors-max-angle! + s5-0 + (vector-z-quaternion! (new 'stack-no-clear 'vector) arg1) + s0-0 + arg3 + ) + ) + ) + (quaternion-normalize! (quaternion*! arg0 s5-0 arg1)) + ) + ) + +(defun vector-rotate-around-axis! ((arg0 vector) (arg1 quaternion) (arg2 float) (arg3 vector)) + "Rotate along y so z-axis points to match another. Use arg3 as the max rotation amount." + (let ((a2-1 (quaternion-vector-angle! (new 'stack-no-clear 'quaternion) arg3 arg2))) + (vector-orient-by-quat! arg0 (the-as vector arg1) a2-1) + ) + ) + +(defun vector-rotate-x! ((arg0 vector) (arg1 vector) (arg2 float)) + "Rotate vector along x axis." + (vector-rotate-around-axis! arg0 (the-as quaternion arg1) arg2 *x-vector*) + ) + +(defun vector-rotate-y! ((arg0 vector) (arg1 vector) (arg2 float)) + "Rotate vector along y axis." + (vector-rotate-around-axis! arg0 (the-as quaternion arg1) arg2 *y-vector*) + ) + +(defun vector-rotate-z! ((arg0 vector) (arg1 vector) (arg2 float)) + "Rotate vector along z axis." + (vector-rotate-around-axis! arg0 (the-as quaternion arg1) arg2 *z-vector*) + ) + +(defun vector-y-angle ((arg0 vector)) + "Get the yaw angle of a vector." + (atan (-> arg0 x) (-> arg0 z)) + ) + +(defun vector-x-angle ((arg0 vector)) + "Get the pitch angle of a vector." + (atan (-> arg0 y) (vector-xz-length arg0)) + ) + +(defun quaternion<-rotate-y-vector ((arg0 quaternion) (arg1 vector)) + "Create a quaternion representing only the yaw of the given vector." + (quaternion-vector-angle! arg0 (new 'static 'vector :y 1.0 :w 1.0) (vector-y-angle arg1)) + ) + +(defun-debug quaternion-validate ((arg0 quaternion)) + "Verify that a quaternion is valid, print an error if the length is off by more than 1%.." + (with-pp + (let ((f0-0 (quaternion-norm arg0))) + (when (or (< 1.01 f0-0) (< f0-0 0.99)) + (format #t "WARNING: bad quaternion (magnitude ~F) process is " f0-0) + (if (and pp (type? pp process-tree)) + (format #t "~A~%" (-> pp name)) + (format #t "#f~%") + ) + ) + ) + 0 + (none) + ) + ) + +(defun quaternion-xz-angle ((arg0 quaternion)) + "Yet another function to compute the yaw of a quaternion. This is a particularly inefficient version." + (let ((gp-0 (new 'stack-no-clear 'matrix)) + (s5-0 (new 'stack-no-clear 'vector)) + ) + (quaternion->matrix gp-0 arg0) + (set-vector! s5-0 0.0 0.0 1.0 1.0) + (vector-matrix*! s5-0 s5-0 gp-0) + (vector-y-angle s5-0) + ) + ) diff --git a/goal_src/jak3/engine/math/transform-h.gc b/goal_src/jak3/engine/math/transform-h.gc index 508f7b09c4..bf40f634d8 100644 --- a/goal_src/jak3/engine/math/transform-h.gc +++ b/goal_src/jak3/engine/math/transform-h.gc @@ -7,3 +7,27 @@ ;; DECOMP BEGINS +(deftype transform (structure) + "Transformation. w components of vectors should be 1.0 +This can represent any rotation, translation, and scaling. +Note that the scaling is applied before rotation +(meaning it scales along the axes of the pre-transformed frame)." + ((trans vector :inline) + (rot vector :inline) + (scale vector :inline) + ) + ) + + +(deftype trs (basic) + "Like transform, but it's a basic. +Note that the trsq child type overrides this rotation with a quaternion. +usage of the plain trs is very limited, at least in Jak 1." + ((trans vector :inline) + (rot vector :inline) + (scale vector :inline) + ) + (:methods + (new (symbol type) _type_) + ) + ) diff --git a/goal_src/jak3/engine/math/transform.gc b/goal_src/jak3/engine/math/transform.gc index 8a6dc4c3a8..8cb2f1ef21 100644 --- a/goal_src/jak3/engine/math/transform.gc +++ b/goal_src/jak3/engine/math/transform.gc @@ -7,3 +7,62 @@ ;; DECOMP BEGINS +(defmethod print ((this transform)) + (format #t "# this trans x) (-> this trans y) (-> this trans z) (-> this trans w)) + (format #t "~T~Trot: ~F ~F ~F ~F ~%" (-> this rot x) (-> this rot y) (-> this rot z) (-> this rot w)) + (format #t "~T~Tscale:~F ~F ~F ~F>" (-> this scale x) (-> this scale y) (-> this scale z) (-> this scale w)) + this + ) + +(defmethod new trs ((allocation symbol) (type-to-make type)) + (let ((gp-0 (object-new allocation type-to-make (the-as int (-> type-to-make size))))) + (set! (-> gp-0 trans w) 1.0) + (set! (-> gp-0 rot w) 1.0) + (vector-identity! (-> gp-0 scale)) + gp-0 + ) + ) + +(defun transform-matrix-calc! ((arg0 transform) (arg1 matrix)) + "Convert a transform to matrix. Not efficient, and the output is the second arg." + (let ((s4-0 (new-stack-matrix0)) + (s3-0 (new-stack-matrix0)) + ) + (matrix-identity! arg1) + (matrix-translate! arg1 (-> arg0 trans)) + (matrix-rotate-y! s4-0 (-> arg0 rot y)) + (matrix*! s3-0 s4-0 arg1) + (matrix-rotate-x! s4-0 (-> arg0 rot x)) + (matrix*! arg1 s4-0 s3-0) + (matrix-rotate-z! s4-0 (-> arg0 rot z)) + (matrix*! s3-0 s4-0 arg1) + (matrix-scale! s4-0 (-> arg0 scale)) + (matrix*! arg1 s4-0 s3-0) + ) + ) + +(defun transform-matrix-parent-calc! ((arg0 transform) (arg1 matrix) (arg2 vector)) + "Convert a transform to a matrix, applying an inverse scaling." + (let ((s4-0 (new-stack-matrix0)) + (s3-0 (new-stack-matrix0)) + ) + (matrix-identity! s3-0) + (matrix-translate! s3-0 (-> arg0 trans)) + (matrix-inv-scale! s4-0 arg2) + (matrix*! arg1 s4-0 s3-0) + (matrix-rotate-y! s4-0 (-> arg0 rot y)) + (matrix*! s3-0 s4-0 arg1) + (matrix-rotate-x! s4-0 (-> arg0 rot x)) + (matrix*! arg1 s4-0 s3-0) + (matrix-rotate-z! s4-0 (-> arg0 rot z)) + (matrix*! s3-0 s4-0 arg1) + (matrix-scale! s4-0 (-> arg0 scale)) + (matrix*! arg1 s4-0 s3-0) + ) + ) + +(defun trs-matrix-calc! ((arg0 trs) (arg1 matrix)) + "Convert a trs to a matrix." + (transform-matrix-calc! (the-as transform (-> arg0 trans)) arg1) + ) diff --git a/goal_src/jak3/engine/math/transformq-h.gc b/goal_src/jak3/engine/math/transformq-h.gc index d5d00e9174..bcfbcaabbc 100644 --- a/goal_src/jak3/engine/math/transformq-h.gc +++ b/goal_src/jak3/engine/math/transformq-h.gc @@ -7,3 +7,69 @@ ;; DECOMP BEGINS +(deftype transformq (transform) + ((quat quaternion :inline :overlay-at (-> rot data 0)) + ) + ) + + +(deftype trsq (trs) + ((quat quaternion :inline :overlay-at (-> rot data 0)) + ) + ) + + +(deftype trsqv (trsq) + "A transform with: +- type information (child of [[basic]]) +- rotation stored as quaternion +- velocity information. +This is a very commonly used type to represent the position of an in-game object. +The `root` of a process-drawable (the parent 'in-game object' type) is a [[trsqv]]. +Additionally, the collision system uses [[trsqv]] as the parent type for foreground +collision objects ([[collide-shape]], [[collide-shape-moving]]). +As a result, this type has a lot of weird methods and extra stuff hidden in it." + ((pause-adjust-distance meters :offset 4) + (nav-radius meters :offset 8) + (transv vector :inline) + (rotv vector :inline) + (scalev vector :inline) + (dir-targ quaternion :inline) + (angle-change-time time-frame) + (old-y-angle-diff float) + ) + (:methods + (seek-toward-heading-vec! (_type_ vector float time-frame) quaternion) + (set-heading-vec! (_type_ vector) quaternion) + (seek-to-point-toward-point! (_type_ vector float time-frame) quaternion) + (point-toward-point! (_type_ vector) quaternion) + (seek-toward-yaw-angle! (_type_ float float time-frame) quaternion) + (set-yaw-angle-clear-roll-pitch! (_type_ float) quaternion) + (set-roll-to-grav! (_type_ float) quaternion) + (set-roll-to-grav-2! (_type_ float) quaternion) + (rotate-toward-orientation! (_type_ quaternion float float int int float) quaternion) + (set-quaternion! (_type_ quaternion) quaternion) + (set-heading-vec-clear-roll-pitch! (_type_ vector) quaternion) + (point-toward-point-clear-roll-pitch! (_type_ vector) quaternion) + (rot->dir-targ! (_type_) quaternion) + (y-angle (_type_) float) + (global-y-angle-to-point (_type_ vector) float) + (relative-y-angle-to-point (_type_ vector) float) + (roll-relative-to-gravity (_type_) float) + (set-and-limit-velocity (_type_ int vector float) trsqv) + (get-quaternion (_type_) quaternion) + ) + ) + + +(defmethod global-y-angle-to-point ((this trsqv) (arg0 vector)) + "Get the angle in the xz plane from the position of this trsqv to the point arg0 +(ignores our current yaw)." + (vector-y-angle (vector-! (new 'stack-no-clear 'vector) arg0 (-> this trans))) + ) + +(defmethod relative-y-angle-to-point ((this trsqv) (arg0 vector)) + "Get the y angle between the current orientation and arg0 +(how much we'd have to yaw to point at arg0)." + (deg-diff (y-angle this) (vector-y-angle (vector-! (new 'stack-no-clear 'vector) arg0 (-> this trans)))) + ) diff --git a/goal_src/jak3/engine/math/trigonometry-h.gc b/goal_src/jak3/engine/math/trigonometry-h.gc index b46875d7ea..71e6cbfec5 100644 --- a/goal_src/jak3/engine/math/trigonometry-h.gc +++ b/goal_src/jak3/engine/math/trigonometry-h.gc @@ -5,5 +5,22 @@ ;; name in dgo: trigonometry-h ;; dgos: GAME +(define-extern deg-diff (function float float float)) +(define-extern sin (function float float)) +(define-extern cos (function float float)) +(define-extern acos (function float float)) +(define-extern atan (function float float float)) +(define-extern sincos! (function vector float int)) +(define-extern sincos-rad! (function vector float int)) +(define-extern vector-sin-rad! (function vector vector vector)) +(define-extern vector-sincos-rad! (function vector vector vector int)) +(define-extern vector-rad<-vector-deg! (function vector vector none)) +(define-extern vector-rad<-vector-deg/2! (function vector vector int)) +(define-extern vector-sincos! (function vector vector vector int)) +(define-extern acos-rad (function float float)) +(define-extern atan-series-rad (function float float)) +(define-extern atan2-rad (function float float float)) + ;; DECOMP BEGINS +;; No code! \ No newline at end of file diff --git a/goal_src/jak3/engine/math/trigonometry.gc b/goal_src/jak3/engine/math/trigonometry.gc index 426b9e56c2..eed82ca0eb 100644 --- a/goal_src/jak3/engine/math/trigonometry.gc +++ b/goal_src/jak3/engine/math/trigonometry.gc @@ -5,5 +5,1079 @@ ;; name in dgo: trigonometry ;; dgos: GAME +#|@file +The "rotation" unit stores an angle in a float, where 1.0 = 1/65,536 (1/2^16) of a rotation. +Use the ~r format specifier to print rotations as degrees. +In general, functions which use these units will only be accurate to within 1/65,536th of a rotation, +as they often internally convert the float to an integer. These function also handle wrapping +correctly, and will output angles in the range -32768 to 32768 (+/- one half of a rotation) +Functions with these units have deg or nothing special in the name. + +Some functions use radians. These typically have rad in the name, and they don't handle wrapping. +The input must be in the range -pi to pi + +General note on floating point constants: to avoid ambiguity/rounding issues related to printing/parsing, weird +constants are stored as hex. Commonly used constants that are exactly represented (1, 0.5, etc) will appear +normally. +|# + +;; There is a bug in some of the cosine functions that can be fixed by toggling this flag. +(defglobalconstant FIX_COSINE_BUG #f) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Floating Point Constants +;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(defconstant ROT_TO_RAD (the-as float #x38c90fda)) +(defconstant PI (the-as float #x40490fda)) +(defconstant MINUS_PI (the-as float #xc0490fda)) +(defconstant PI_OVER_2 (the-as float #x3fc90fda)) +(defconstant TWO_PI (the-as float #x40c90fda)) + +(defmacro unwrap-angle (angle) + `(the float (sar (shl (the int ,angle) 48) 48)) + ) + +(defmacro unwrap-angle-small-angle-fix (angle) + "Same as unwrap angle, but small angles are not rounded to zero." + `(if (< (fabs ,angle) 1.1) + ,angle + (the float (sar (shl (the int ,angle) 48) 48)) + ) + ) + ;; DECOMP BEGINS +(defun radmod ((arg0 float)) + "Wrap arg0 to be within (-pi, pi)." + (let ((f0-1 (+ 3.1415925 arg0))) + (if (< 0.0 f0-1) + (+ -3.1415925 (- f0-1 (* (the float (the int (/ f0-1 6.283185))) 6.283185))) + (+ 3.1415925 (- f0-1 (* (the float (the int (/ f0-1 6.283185))) 6.283185))) + ) + ) + ) + +(defun deg- ((arg0 float) (arg1 float)) + "Compute arg0-arg1, unwrapped, using rotation units. +Result should be in the range (-180, 180)" + (the float (sar (- (shl (the int arg0) 48) (shl (the int arg1) 48)) 48)) + ) + +(defun deg-diff ((arg0 float) (arg1 float)) + "Very similar to the function above, but computes arg1 - arg0 instead." + (the float (sar (- (shl (the int arg1) 48) (shl (the int arg0) 48)) 48)) + ) + +(defun deg-seek ((arg0 float) (arg1 float) (arg2 float)) + "Move in toward target by at most max-diff, using rotation units" + (let ((v1-1 (shl (the int arg0) 48)) + (a0-2 (shl (the int arg1) 48)) + ) + (let* ((a1-2 (shl (the int arg2) 48)) + (a2-1 (- a0-2 v1-1)) + (a3-0 (abs a2-1)) + ) + (set! a0-2 (cond + ((< a3-0 0) + (+ v1-1 a1-2) + ) + ((>= a1-2 a3-0) + (empty) + a0-2 + ) + ((>= a2-1 0) + (+ v1-1 a1-2) + ) + (else + (- v1-1 a1-2) + ) + ) + ) + ) + (the float (sar a0-2 48)) + ) + ) + +(defun deg-seek-smooth ((arg0 float) (arg1 float) (arg2 float) (arg3 float)) + "Step amount of the way from in to target, by at most max-diff, using rotation units" + (let ((f0-1 (* (deg- arg1 arg0) arg3))) + (if (< arg2 (fabs f0-1)) + (set! f0-1 (if (>= f0-1 0.0) + arg2 + (- arg2) + ) + ) + ) + (+ arg0 f0-1) + ) + ) + +(defun deg-lerp-clamp ((arg0 float) (arg1 float) (arg2 float)) + "Map [0, 1] to min-val, max-val, handling wrapping and saturating, using rotation units." + (cond + ((>= 0.0 arg2) + arg0 + ) + ((>= arg2 1.0) + arg1 + ) + (else + (the float (sar (shl (the int (+ arg0 (* arg2 (deg-diff arg0 arg1)))) 48) 48)) + ) + ) + ) + +(define binary-table (new 'static 'boxed-array :type float + 1.0 + 0.5 + 0.25 + 0.125 + 0.0625 + 0.03125 + 0.015625 + 0.0078125 + 0.00390625 + 0.001953125 + 0.0009765625 + 0.00048828125 + 0.00024414062 + 0.00012207031 + 0.000061035156 + 0.000030517578 + 0.000015258789 + 0.0000076293945 + 0.0000038146973 + 0.0000019073486 + 0.0000009536743 + 0.00000047683716 + 0.00000023841858 + 0.00000011920929 + 0.000000059604645 + 0.000000029802322 + 0.000000014901161 + 0.000000007450581 + 0.0000000037252903 + 0.0000000018626451 + 0.0000000009313226 + 0.0000000004656613 + ) + ) + +(define sincos-table (new 'static 'boxed-array :type float + 0.7853982 + 0.4636476 + 0.24497867 + 0.124354996 + 0.06241881 + 0.031239834 + 0.015623729 + 0.007812341 + 0.0039062302 + 0.0019531226 + 0.0009765622 + 0.0004882812 + 0.00024414062 + 0.00012207031 + 0.000061035156 + 0.000030517578 + 0.000015258789 + 0.0000076293945 + 0.0000038146973 + 0.0000019073486 + 0.0000009536743 + 0.00000047683716 + 0.00000023841858 + 0.00000011920929 + 0.000000059604645 + 0.000000029802322 + 0.000000014901161 + 0.000000007450581 + 0.0000000037252903 + 0.0000000018626451 + 0.0000000009313226 + 0.0000000004656613 + ) + ) + +(defun sin ((arg0 float)) + "Compute the sine of an angle in rotation units. Unwraps it." + ;; og:preserve-this + (let ((f2-0 (* 0.000095873795 (unwrap-angle arg0)))) + f2-0 + (let* ((f1-4 (* 0.999998 f2-0)) + (f0-3 (* f2-0 f2-0)) + (f2-1 (* f2-0 f0-3)) + (f1-5 (+ f1-4 (* -0.16666014 f2-1))) + (f2-2 (* f2-1 f0-3)) + (f1-6 (+ f1-5 (* 0.008326521 f2-2))) + (f2-3 (* f2-2 f0-3)) + (f1-7 (+ f1-6 (* -0.0001956241 f2-3))) + (f0-4 (* f2-3 f0-3)) + ) + (+ f1-7 (* 0.0000023042373 f0-4)) + ) + ) + ) + +(defun sin-rad ((arg0 float)) + "Compute the sine of an angle in radians. + No unwrap is done, should be in -pi, pi" + (local-vars + (f1-0 float) + (f2-0 float) + (f3-0 float) + (f4-0 float) + (f5-0 float) + (f6-0 float) + (f7-0 float) + (f8-0 float) + (f9-0 float) + (f10-0 float) + (f11-0 float) + (acc float) + ) + (set! f1-0 (* arg0 arg0)) + (set! f7-0 (the-as float #x3f7fffde)) + (set! f8-0 (the-as float #xbe2aa8f5)) + (set! f2-0 (* arg0 f1-0)) + (set! f3-0 (* f1-0 f1-0)) + (set! f9-0 (the-as float #x3c086bf6)) + (set! f4-0 (* f2-0 f1-0)) + (set! f5-0 (* f3-0 f2-0)) + (set! f10-0 (the-as float #xb94d2072)) + (set! f6-0 (* f4-0 f3-0)) + (set! f11-0 (the-as float #x361aa27f)) + ;;(.mula.s arg0 f7-0) + (set! acc (* arg0 f7-0)) + ;;(.madda.s f2-0 f8-0) + (set! acc (+ acc (* f2-0 f8-0))) + ;;(.madda.s f4-0 f9-0) + (set! acc (+ acc (* f4-0 f9-0))) + ;;(.madda.s f5-0 f10-0) + (set! acc (+ acc (* f5-0 f10-0))) + ;;(.madd.s f12-0 f6-0 f11-0) + (+ acc (* f6-0 f11-0)) + ) + +(define *sin-poly-vec* + (new 'static 'vector :x -0.16666014 :y 0.008326521 :z -0.0001956241 :w 0.0000023042373) + ) + +(define *sin-poly-vec2* (new 'static 'vector :x 0.999998)) + +(defun vector-sin-rad! ((arg0 vector) (arg1 vector)) + "Taylor series approximation of sine on all 4 elements in a vector. +Inputs should be in radians, in -pi to pi. +Somehow their coefficients are a little bit off. +Like the first coefficient, which should obviously be 1, is not quite 1." + (rlet ((acc :class vf) + (vf1 :class vf) + (vf10 :class vf) + (vf2 :class vf) + (vf3 :class vf) + (vf4 :class vf) + (vf5 :class vf) + (vf6 :class vf) + (vf7 :class vf) + (vf8 :class vf) + (vf9 :class vf) + ) + (.lvf vf1 (&-> arg1 quad)) + (.mul.vf vf3 vf1 vf1) + (.lvf vf10 (&-> *sin-poly-vec2* quad)) + (.lvf vf9 (&-> *sin-poly-vec* quad)) + (.mul.vf vf4 vf3 vf1) + (.mul.vf vf5 vf3 vf3) + (.mul.x.vf acc vf1 vf10) + (.mul.vf vf6 vf4 vf3) + (.mul.vf vf7 vf5 vf4) + (.add.mul.x.vf acc vf4 vf9 acc) + (.mul.vf vf8 vf6 vf5) + (.add.mul.y.vf acc vf6 vf9 acc) + (.add.mul.z.vf acc vf7 vf9 acc) + (.add.mul.w.vf vf2 vf8 vf9 acc) + (.svf (&-> arg0 quad) vf2) + arg0 + ) + ) + +(defun cos-rad ((arg0 float)) + "Cosine with taylor series. Input is in radians, in -pi, pi. + - TODO constants" + (local-vars + (f1-0 float) + (f3-0 float) + (f4-0 float) + (f5-0 float) + (f7-0 float) + (f8-0 float) + (f9-0 float) + (f10-0 float) + (f11-0 float) + (acc float) + ) + (set! f1-0 (* arg0 arg0)) + (set! f7-0 1.000000) + (set! f8-0 (the-as float #xbefffd62)) + (set! f3-0 (* f1-0 f1-0)) + (set! f9-0 (the-as float #x3d2a7a28)) + (set! f10-0 (the-as float #xbab2bc31)) + (set! f4-0 (* f3-0 f1-0)) + (set! f5-0 (* f3-0 f3-0)) + (set! f11-0 (the-as float #x37a933eb)) + ;;(.mula.s f7-0 f7-0) + (set! acc (* f7-0 f7-0)) + ;;(.madda.s f8-0 f1-0) + (set! acc (+ acc (* f8-0 f1-0))) + ;;(.madda.s f9-0 f3-0) + (set! acc (+ acc (* f9-0 f3-0))) + ;;(.madda.s f10-0 f4-0) + (set! acc (+ acc (* f10-0 f4-0))) + ;;(.madd.s f12-0 f11-0 f5-0) + (+ acc (* f11-0 f5-0)) + ;;(the-as float f12-0) + ) + +(define *cos-poly-vec* (new 'static 'vector :x -0.49998003 :y 0.041620404 :z -0.0013636408 :w 0.000020170546)) + +;; ERROR: Bad vector register dependency: vf2 +(defun vector-cos-rad! ((arg0 vector) (arg1 vector)) + "Compute the cosine of all 4 vector elements. +Radians, with no wrapping. Uses taylor series with 4 coefficients." + (rlet ((acc :class vf) + (vf0 :class vf) + (vf1 :class vf) + (vf2 :class vf) + (vf3 :class vf) + (vf4 :class vf) + (vf5 :class vf) + (vf6 :class vf) + (vf9 :class vf) + ) + (init-vf0-vector) + (.lvf vf1 (&-> arg1 quad)) + ;; og:preserve-this + ;; (.sub.vf vf2 vf2 vf2) + (.xor.vf vf2 vf2 vf2) + (.lvf vf9 (&-> *cos-poly-vec* quad)) + (.mul.vf vf3 vf1 vf1) + (.add.w.vf acc vf2 vf0) + (.mul.vf vf4 vf3 vf3) + (.add.mul.x.vf acc vf3 vf9 acc) + (.mul.vf vf5 vf4 vf3) + (.add.mul.y.vf acc vf4 vf9 acc) + (.mul.vf vf6 vf4 vf4) + (.add.mul.z.vf acc vf5 vf9 acc) + (.add.mul.w.vf vf2 vf6 vf9 acc) + (.svf (&-> arg0 quad) vf2) + arg0 + ) + ) + +;; ERROR: Bad vector register dependency: vf14 +(defun vector-sincos-rad! ((arg0 vector) (arg1 vector) (arg2 vector)) + "Compute the sine and cosine of each element of src, storing it in dst-sin and dst-cos. +This is more efficient than separate calls to sin and cos. +Inputs should be radians in -pi to pi." + (rlet ((acc :class vf) + (vf0 :class vf) + (vf1 :class vf) + (vf10 :class vf) + (vf11 :class vf) + (vf12 :class vf) + (vf13 :class vf) + (vf14 :class vf) + (vf2 :class vf) + (vf3 :class vf) + (vf4 :class vf) + (vf5 :class vf) + (vf6 :class vf) + (vf7 :class vf) + (vf8 :class vf) + (vf9 :class vf) + ) + (init-vf0-vector) + (.lvf vf1 (&-> arg2 quad)) + ;; og:preserve-this + ;; (.sub.vf vf14 vf14 vf14) + (.xor.vf vf14 vf14 vf14) + (.lvf vf11 (&-> *sin-poly-vec2* quad)) + (.mul.vf vf2 vf1 vf1) + (.lvf vf10 (&-> *sin-poly-vec* quad)) + (.lvf vf13 (&-> *cos-poly-vec* quad)) + (.mul.x.vf acc vf1 vf11) + (.mul.vf vf3 vf2 vf1) + (.mul.vf vf4 vf2 vf2) + (.mul.vf vf5 vf3 vf2) + (.mul.vf vf6 vf3 vf3) + (.mul.vf vf7 vf4 vf3) + (.mul.vf vf8 vf4 vf4) + (.mul.vf vf9 vf5 vf4) + (.add.mul.x.vf acc vf3 vf10 acc) + (.add.mul.y.vf acc vf5 vf10 acc) + (.add.mul.z.vf acc vf7 vf10 acc) + (.add.mul.w.vf vf12 vf9 vf10 acc) + (.add.w.vf acc vf14 vf0) + (.add.mul.x.vf acc vf2 vf13 acc) + (.add.mul.y.vf acc vf4 vf13 acc) + (.add.mul.z.vf acc vf6 vf13 acc) + (.add.mul.w.vf vf14 vf8 vf13 acc) + (.svf (&-> arg0 quad) vf12) + (.svf (&-> arg1 quad) vf14) + 0 + ) + ) + +;; og:preserve-this +(defmacro sincos-rad-asm (out x) + ;; Compute the sine and cosine of x, store it in the output array + ;; this assembly is shared in two functions. + `(rlet ((f10 :class fpr :type float) ;; coeff 1.0 + (f11 :class fpr :type float) ;; coeff -1/3! + (f12 :class fpr :type float) ;; coeff 1/5! + (f14 :class fpr :type float) ;; coeff -1/7! + (f15 :class fpr :type float) ;; coeff 1/9! + (f1 :class fpr :type float) ;; x + (f2 :class fpr :type float) ;; x^2 + (f3 :class fpr :type float) ;; x^3 + (f4 :class fpr :type float) ;; x^4 + (f5 :class fpr :type float) ;; x^5 + (f6 :class fpr :type float) ;; x^6 + (f7 :class fpr :type float) ;; x^7 + (f8 :class fpr :type float) ;; x^8 + (f9 :class fpr :type float) ;; x^9 + (f21 :class fpr :type float) + (f22 :class fpr :type float) ;; 0 ? + (acc :class fpr :type float) ;; temp + (f16 :class fpr :type float) ;; 1.0 + (f17 :class fpr :type float) ;; cos coeff 1 + (f18 :class fpr :type float) ;; cos coeff 2 + (f19 :class fpr :type float) ;; cos coeff 3 + (f20 :class fpr :type float) ;; cos coeff 4 + ) + ;; lui v1, 16255 + ;; lui a2, -16854 + ;; ori v1, v1, 65502 + ;; mtc1 f1, a1 + (set! f1 ,x) + ;; ori a1, a2, 43253 + ;; sub.s f22, f22, f22 + (set! f22 (the-as float 0)) + ;; lui a2, 15368 + ;; mtc1 f10, v1 + (set! f10 (the-as float #x3F7FFFDE)) ;; almost 1.0 + ;; ori v1, a2, 27638 + ;; mtc1 f11, a1 + (set! f11 (the-as float #xBE2AA8F5)) ;; -0.166, 1/3! + ;; lui a1, -18099 + ;; mul.s f2, f1, f1 + (set! f2 (* f1 f1)) + ;; ori a1, a1, 8306 + ;; mtc1 f12, v1 + (set! f12 (the-as float #x3C086BF6)) ;; 1/5! + ;; lui v1, 13850 + ;; mtc1 f14, a1 + (set! f14 (the-as float #xB94D2072)) ;; 1/7! + ;; ori a1, v1, 41599 + ;; mula.s f1, f10 + (set! acc (* f1 f10)) ;; x * c_1 + ;; lui v1, 16256 + ;; mul.s f3, f2, f1 + (set! f3 (* f2 f1)) ;; x^3 + ;; or v1, v1, r0 + ;; mul.s f4, f2, f2 + (set! f4 (* f2 f2)) ;; x^4 + ;; lui a2, -16641 + ;; mtc1 f15, a1 + (set! f15 (the-as float #x361AA27F)) ;; 1/9! + ;; lui a1, -16641 ;; I think this is a typo... + ;; or a1, a2, a1 ;; this should set the lower 16 bits. + ;; mtc1 f16, v1 + (set! f16 (the-as float #x3f800000)) ;; 1.0 + ;; sll r0, r0, 0 + ;; mtc1 f17, a1 + + ;; it looks like they set the lower 16-bits of the x^2 + ;; coefficient for cosine incorrectly + (#cond + (FIX_COSINE_BUG + ;; the constant used in *cos-poly-vec* + (set! f17 (the-as float #xbefffd62)) + ) + (#t + ;; missing the lower 16 bits. + (set! f17 (the-as float #xBEFF0000)) + ) + ) + + ;; sll r0, r0, 0 + ;; mul.s f5, f3, f2 + (set! f5 (* f3 f2)) + ;; sll r0, r0, 0 + ;; mul.s f6, f3, f3 + (set! f6 (* f3 f3)) + ;; sll r0, r0, 0 + ;; mul.s f7, f4, f3 + (set! f7 (* f4 f3)) + ;; sll r0, r0, 0 + ;; mul.s f8, f4, f4 + (set! f8 (* f4 f4)) + ;; sll r0, r0, 0 + ;; mul.s f9, f5, f4 + (set! f9 (* f5 f4)) + ;; lui v1, 15658 + ;; madda.s f3, f11 + (set! acc (+ acc (* f3 f11))) ;; add x^3 sine term + ;; ori v1, v1, 31272 + ;; madda.s f5, f12 + (set! acc (+ acc (* f5 f12))) ;; add x^5 sine term + ;; lui a1, -17742 + ;; madda.s f7, f14 + (set! acc (+ acc (* f7 f14))) ;; add x^7 sine term + ;; ori a1, a1, 48177 + ;; madd.s f21, f9, f15 + (set! f21 (+ acc (* f9 f15))) ;; add x^9 sine term + ;; lui a2, 14249 + ;; mtc1 f18, v1 + (set! f18 (the-as float #x3D2A7A28)) ;; cos coeff + ;; ori v1, a2, 13291 + ;; mtc1 f19, a1 + (set! f19 (the-as float #xBAB2BC31)) ;; cos coeff + ;; sll r0, r0, 0 + ;; mtc1 f20, v1 + (set! f20 (the-as float #x37A933EB)) + ;; sll r0, r0, 0 + ;; mula.s f16, f16 + (set! acc (* f16 f16)) ;; acc = 1, constant cos term. + ;; sll r0, r0, 0 + ;; madda.s f2, f17 + (set! acc (+ acc (* f2 f17))) + ;; sll r0, r0, 0 + ;; madda.s f4, f18 + (set! acc (+ acc (* f4 f18))) + ;; sll r0, r0, 0 + ;; madda.s f6, f19 + (set! acc (+ acc (* f6 f19))) + ;; sll r0, r0, 0 + ;; madd.s f22, f8, f20 + (set! f22 (+ acc (* f8 f20))) + ;; sll r0, r0, 0 + ;; swc1 f21, 0(a0) + (set! (-> ,out x) f21) + ;; sll r0, r0, 0 + ;; swc1 f22, 4(a0) + (set! (-> ,out y) f22) + ;; or v0, r0, r0 + 0 + ) + ) + +(defun sincos-rad! ((out vector) (x float)) + "Compute the sine and cosine of x, store it in the output array. + Has the cosine bug." + (sincos-rad-asm out x) + ) + +(defun sincos! ((out vector) (x float)) + "Compute the sine and cosine of x, store it in the output array. + The input is in rotation units, and is unwrapped properly. + Also has the cosine bug" + (sincos-rad-asm out (* ROT_TO_RAD (unwrap-angle x))) + ) + +(defun vector-rad<-vector-deg! ((out vector) (in vector)) + "Convert a vector in rotation units to radians, and unwrap. + Input can be anything, output will be -2pi to pi." + (rlet ((rot-to-rad :class vf) + (vf1 :class vf)) + (.mov rot-to-rad (the-as float ROT_TO_RAD)) + (.lvf vf1 in) + (.ftoi.vf vf1 vf1) ;; to int + (.pw.sll vf1 vf1 16) ;; shifts + (.pw.sra vf1 vf1 16) + (.itof.vf vf1 vf1) ;; to float + (.mul.x.vf vf1 vf1 rot-to-rad) + (.svf out vf1) + ) + ) + +;; WARN: Return type mismatch float vs int. +(defun vector-rad<-vector-deg/2! ((out vector) (in vector)) + "Divide the input by two, and then convert from rotation units to radians, unwrapping. +Not sure why this really needs to be separate the from previous function..." + (rlet ((temp :class vf) + (vf1 :class vf)) + ;;(set! v1-0 952700890) + ;;(set! a2-0 1056964608) + ;;(.lqc2 vf1 0 a1-0) + (.lvf vf1 in) + + ;; multiply by 0.5. + ;;(.qmtc2.i vf2 a2-0) + (.mov temp (the-as float #x3f000000)) ;; 0.5 + ;;(.vmulx.xyzw vf1 vf1 vf2) + (.mul.x.vf vf1 vf1 temp) + + ;;(.vftoi0.xyzw vf1 vf1) + (.ftoi.vf vf1 vf1) + ;;(.qmtc2.i vf2 v1-0) + ;;(.qmfc2.i v1-1 vf1) + ;;(.psllw v1-2 v1-1 16) + (.pw.sll vf1 vf1 16) + ;;(.psraw v1-3 v1-2 16) + (.pw.sra vf1 vf1 16) + ;;(.qmtc2.i vf1 v1-3) + ;;(.vitof0.xyzw vf1 vf1) + (.itof.vf vf1 vf1) + ;;(.vmulx.xyzw vf1 vf1 vf2) + (.mov temp (the-as float ROT_TO_RAD)) + (.mul.x.vf vf1 vf1 temp) + ;;(.sqc2 vf1 0 arg0) + ;;(.qmfc2.i v0-0 vf1) + (.svf out vf1) + 0 + ) + ) + +(defun vector-sincos! ((arg0 vector) (arg1 vector) (arg2 vector)) + "Compute sine and cosine of each element in a vector, in rotation units" + (let ((s4-0 (new 'stack-no-clear 'vector))) + (vector-rad<-vector-deg! s4-0 arg2) + (vector-sincos-rad! arg0 arg1 s4-0) + ) + ) + +(defun tan-rad ((arg0 float)) + "This function appears to be named wrong and actually operates on rotation units." + (/ (sin arg0) (cos arg0)) + ) + +(defun cos ((arg0 float)) + "Cosine of rotation units." + (sin (+ 16384.0 arg0)) + ) + +(defun tan ((arg0 float)) + "Correctly named tangent of rotation units." + (/ (sin arg0) (cos arg0)) + ) + +(defun atan0 ((arg0 float) (arg1 float)) + "Inverse tangent, to rotation units. y,x order. Does not handle signs correctly. + Do not use this function directly, instead use atan2." + (rlet ((f20 :class fpr :type float) + (f21 :class fpr :type float) + (f1 :class fpr :type float) + (f2 :class fpr :type float) + (f3 :class fpr :type float) + (f4 :class fpr :type float) + (f5 :class fpr :type float) + (f6 :class fpr :type float) + (f7 :class fpr :type float) + (f8 :class fpr :type float) + (f9 :class fpr :type float) + (f10 :class fpr :type float) + (f19 :class fpr :type float) + (f11 :class fpr :type float) + (f12 :class fpr :type float) + (f13 :class fpr :type float) + (f14 :class fpr :type float) + (f15 :class fpr :type float) + (f16 :class fpr :type float) + (f17 :class fpr :type float) + (f18 :class fpr :type float) + (acc :class fpr :type float) + ) + + ;;mtc1 f20, a1 + (set! f20 arg1) + ;;mtc1 f21, a0 + (set! f21 arg0) + ;;sub.s f1, f21, f20 + (set! f1 (- f21 f20)) + ;;add.s f2, f21, f20 + (set! f2 (+ f21 f20)) + ;;div.s f1, f1, f2 + (set! f1 (/ f1 f2)) + ;;lwc1 f19, L132(fp) + (set! f19 (the-as float #x46000000)) + ;;lwc1 f11, L140(fp) + (set! f11 (the-as float #x4622f97c)) + ;;lwc1 f12, L151(fp) + (set! f12 (the-as float #xc55946e1)) + ;;lwc1 f13, L120(fp) + (set! f13 (the-as float #x450207fd)) + ;;lwc1 f14, L126(fp) + (set! f14 (the-as float #xc4b556ce)) + ;;lwc1 f15, L113(fp) + (set! f15 (the-as float #x447b6ca4)) + ;;mul.s f2, f1, f1 + (set! f2 (* f1 f1)) + ;;lwc1 f16, L142(fp) + (set! f16 (the-as float #xc411ca52)) + ;;lwc1 f17, L118(fp) + (set! f17 (the-as float #x43640558)) + ;;mul.s f3, f1, f2 + (set! f3 (* f1 f2)) + ;;mul.s f1, f1, f11 + (set! f1 (* f1 f11)) + ;;mul.s f4, f2, f2 + (set! f4 (* f2 f2)) + ;;lwc1 f18, L141(fp) + (set! f18 (the-as float #xc2292434)) + ;;mul.s f5, f3, f2 + (set! f5 (* f3 f2)) + ;;mul.s f6, f4, f3 + (set! f6 (* f4 f3)) + ;;mul.s f7, f5, f4 + (set! f7 (* f5 f4)) + ;;mul.s f8, f6, f4 + (set! f8 (* f6 f4)) + ;;mul.s f9, f7, f4 + (set! f9 (* f7 f4)) + ;;mul.s f10, f8, f4 + (set! f10 (* f8 f4)) + ;;adda.s f1, f19 + (set! acc (+ f1 f19)) + ;;madda.s f3, f12 + (set! acc (+ acc (* f3 f12))) + + ;;madda.s f5, f13 + (set! acc (+ acc (* f5 f13))) + + ;;madda.s f6, f14 + (set! acc (+ acc (* f6 f14))) + + ;;madda.s f7, f15 + (set! acc (+ acc (* f7 f15))) + + ;;madda.s f8, f16 + (set! acc (+ acc (* f8 f16))) + + ;;madda.s f9, f17 + (set! acc (+ acc (* f9 f17))) + + ;;madd.s f19, f10, f18 + ;;mfc1 v0, f19 + (+ acc (* f10 f18)) + ) + ) + +;; og:preserve-this +(defmacro .adda.s (a b) + `(set! acc (+ ,a ,b)) + ) + +(defmacro .madda.s (a b) + `(set! acc (+ acc (* ,a ,b))) + ) + +(defmacro .madd.s (a b c) + `(set! ,a (+ acc (* ,b ,c))) + ) + +(defun atan-series-rad ((arg0 float)) + "A helper function for atan" + (local-vars + (f0-1 float) + (f1-0 float) + (f2-0 float) + (f3-0 float) + (f4-0 float) + (f5-0 float) + (f6-0 float) + (f7-0 float) + (f8-0 float) + (f9-0 float) + (f10-0 float) + (f11-0 float) + (f12-0 float) + (f13-0 float) + (f14-0 float) + (f15-0 float) + (f16-0 float) + (f17-0 float) + (f18-0 float) + (acc float) + (f18-1 float) + ) + (set! f1-0 (* arg0 arg0)) + (set! f10-0 (the-as float #x3f7ffff5)) + (set! f11-0 (the-as float #xbeaaa61c)) + (set! f2-0 (* arg0 f1-0)) + (set! f3-0 (* f1-0 f1-0)) + (set! f12-0 (the-as float #x3e4c40a6)) + (set! f4-0 (* f2-0 f1-0)) + (set! f5-0 (* f3-0 f2-0)) + (set! f13-0 (the-as float #xbe0e6c63)) + (set! f6-0 (* f4-0 f3-0)) + (set! f7-0 (* f5-0 f3-0)) + (set! f14-0 (the-as float #x3dc577df)) + (set! f8-0 (* f6-0 f3-0)) + (set! f9-0 (* f7-0 f3-0)) + (set! f15-0 (the-as float #xbd6501c4)) + (set! f18-0 (the-as float #x3f490fdb)) + (set! f0-1 (* arg0 f10-0)) + (set! f16-0 (the-as float #x3cb31652)) + (set! f17-0 (the-as float #xbb84d7e7)) + (.adda.s f0-1 f18-0) + (.madda.s f2-0 f11-0) + (.madda.s f4-0 f12-0) + (.madda.s f5-0 f13-0) + (.madda.s f6-0 f14-0) + (.madda.s f7-0 f15-0) + (.madda.s f8-0 f16-0) + (.madd.s f18-1 f9-0 f17-0) + ;;(the-as float f18-1) + f18-1 + ) + +(defun atan-rad ((arg0 float)) + "Inverse tangent in radians." + (atan-series-rad (/ (+ -1.0 arg0) (+ 1.0 arg0))) + ) + +(defun sign-bit ((arg0 int)) + "Return 1 if bit 31 is set, otherwise 0." + ;; originally used 32-bit shift, doesn't really matter. + (logand (shr arg0 31) 1) + + ;(local-vars (v1-1 int)) + ; (let ((v1-0 arg0)) + ; (shift-arith-right-32 v1-1 v1-0 31) + ; ) + ; (logand v1-1 1) + ) + +(defun sign-float ((arg0 float)) + "Return 1 if arg0 is positive or zero, -1 otherwise. + Fast (no branching)." + (let ((a1-0 #xffffffff80000000) + (v1-0 #x3f800000) + ) + (the-as float (logior (logand (the-as uint arg0) (the-as uint a1-0)) v1-0)) + ) + ) + +(defun sign ((arg0 float)) + "Similar to above, but returns 0 if input is 0. +But is more complicated." + (cond + ((< 0.0 arg0) + 1.0 + ) + ((< arg0 0.0) + -1.0 + ) + (else + 0.0 + ) + ) + ) + +(defun atan2-rad ((arg0 float) (arg1 float)) + "Atan for radians." + (cond + ((= arg1 0.0) + (* 1.5707963 (sign arg0)) + ) + ((and (< arg0 0.0) (< arg1 0.0)) + (let ((f30-1 -3.1415925) + (f0-6 (/ arg0 arg1)) + ) + (+ f30-1 (atan-series-rad (/ (+ -1.0 f0-6) (+ 1.0 f0-6)))) + ) + ) + ((< arg0 0.0) + (let ((f0-14 (- (/ arg0 arg1)))) + (- (atan-series-rad (/ (+ -1.0 f0-14) (+ 1.0 f0-14)))) + ) + ) + ((< arg1 0.0) + (let ((f30-2 3.1415925) + (f0-22 (- (/ arg0 arg1))) + ) + (- f30-2 (atan-series-rad (/ (+ -1.0 f0-22) (+ 1.0 f0-22)))) + ) + ) + (else + (let ((f0-28 (/ arg0 arg1))) + (atan-series-rad (/ (+ -1.0 f0-28) (+ 1.0 f0-28))) + ) + ) + ) + ) + +(defun atan ((arg0 float) (arg1 float)) + "Atan for rotation units. Signs behave like atan.." + (cond + ((and (= arg1 0.0) (= arg0 0.0)) + 0.0 + ) + ((and (< arg1 0.0) (< arg0 0.0)) + (+ -32768.0 (atan0 (- arg0) (- arg1))) + ) + ((< arg0 0.0) + (- (atan0 (- arg0) arg1)) + ) + ((< arg1 0.0) + (- 32768.0 (atan0 arg0 (- arg1))) + ) + (else + (atan0 arg0 arg1) + ) + ) + ) + +(defun asin ((arg0 float)) + "Inverse sine, rotation units." + (let ((gp-0 #f)) + 0.0 + (when (< arg0 0.0) + (set! arg0 (- arg0)) + (set! gp-0 #t) + ) + (let ((f0-5 (cond + ((< 1.0 arg0) + 16383.996 + ) + (else + (let* ((f0-6 1.0) + (f1-2 arg0) + (f0-8 (sqrtf (- f0-6 (* f1-2 f1-2)))) + ) + (atan0 arg0 f0-8) + ) + ) + ) + ) + ) + (if gp-0 + (- f0-5) + f0-5 + ) + ) + ) + ) + +(defun acos ((arg0 float)) + "Inverse cosine. Returns rotation units." + (let ((result (- 16384.000000 (asin arg0)))) + (#when PC_PORT + ;; og:preserve-this to avoid punch glitch: + ;; (note: it might be a better fix to change the global rounding mode, + ;; but it's not super clear to me that the mode picked by PCSX2 is + ;; more accurate than normal in all cases. So, we'll do this for now.) + (when (= result 0.0) + (set! result 0.00000000001) + ) + ) + result + ) + ) + +(defun acos-rad ((arg0 float)) + "Inverse cosine, radians." + (cond + ((>= arg0 0.0) + (let* ((f0-1 1.0) + (f1-1 arg0) + (f0-3 (sqrtf (- f0-1 (* f1-1 f1-1)))) + (f0-5 (/ (- f0-3 arg0) (+ f0-3 arg0))) + ) + (atan-series-rad f0-5) + ) + ) + (else + (let* ((f0-6 1.0) + (f1-6 arg0) + (f0-8 (sqrtf (- f0-6 (* f1-6 f1-6)))) + (f0-10 (/ (+ f0-8 arg0) (- f0-8 arg0))) + ) + (- 3.1415925 (atan-series-rad f0-10)) + ) + ) + ) + ) + +(defun sinerp ((arg0 float) (arg1 float) (arg2 float)) + "Map amount to min,max using sine. Kinda weird, usually people use cosine." + (lerp arg0 arg1 (sin (* 16384.0 arg2))) + ) + +(defun sinerp-clamp ((arg0 float) (arg1 float) (arg2 float)) + "Like sinerp, but clamp to min,max." + (cond + ((>= 0.0 arg2) + arg0 + ) + ((>= arg2 1.0) + arg1 + ) + (else + (sinerp arg0 arg1 arg2) + ) + ) + ) + +(defun coserp ((arg0 float) (arg1 float) (arg2 float)) + "Weird lerp with cosine (over 90 degrees?)." + (lerp arg0 arg1 (- 1.0 (cos (* 16384.0 arg2)))) + ) + +(defun coserp-clamp ((arg0 float) (arg1 float) (arg2 float)) + "Weird 90 degree lerp with cosine, clamped to min,max." + (cond + ((>= 0.0 arg2) + arg0 + ) + ((>= arg2 1.0) + arg1 + ) + (else + (coserp arg0 arg1 arg2) + ) + ) + ) + +(defun coserp180 ((arg0 float) (arg1 float) (arg2 float)) + "Classic lerp with cosine." + (lerp arg0 arg1 (* 0.5 (- 1.0 (cos (* 32768.0 arg2))))) + ) + +(defun coserp180-clamp ((arg0 float) (arg1 float) (arg2 float)) + "Classic coserp with saturation." + (cond + ((>= 0.0 arg2) + arg0 + ) + ((>= arg2 1.0) + arg1 + ) + (else + (coserp180 arg0 arg1 arg2) + ) + ) + ) + +(defun ease-in-out ((arg0 int) (arg1 int)) + "Weird coserp like mapping from 0 to 1 as progress goes from 0 to total." + (local-vars (v1-0 int)) + (cond + ((>= arg1 arg0) + 1.0 + ) + ((<= arg1 0) + 0.0 + ) + ((begin (set! v1-0 (/ arg0 2)) (< v1-0 arg1)) + (let ((a0-1 (- arg1 arg0))) + (+ 0.5 (* 0.5 (sin (- 16384.0 (/ (* 16384.0 (the float a0-1)) (the float v1-0)))))) + ) + ) + (else + (- 0.5 (* 0.5 (cos (/ (* 16384.0 (the float arg1)) (the float v1-0))))) + ) + ) + ) diff --git a/goal_src/jak3/engine/math/vector-h.gc b/goal_src/jak3/engine/math/vector-h.gc index 32f20d5529..c5c8fd7fa4 100644 --- a/goal_src/jak3/engine/math/vector-h.gc +++ b/goal_src/jak3/engine/math/vector-h.gc @@ -5,5 +5,620 @@ ;; name in dgo: vector-h ;; dgos: GAME +(define-extern vector-identity! (function vector vector)) +(define-extern vector-cross! (function vector vector vector vector)) +(define-extern vector-float*! (function vector vector float vector)) +(define-extern vector-normalize! (function vector float vector)) +(define-extern vector-normalize-copy! (function vector vector float vector)) +(define-extern vector-xz-normalize! (function vector float vector)) +(define-extern vector-get-unique! (function vector vector vector)) +(define-extern vector-get-closest-perpendicular! (function vector vector vector vector)) +(define-extern vector-length (function vector float)) +(define-extern vector-length-squared (function vector float)) +(define-extern vector-xz-length (function vector float)) + +(defmacro set-vector! (v xv yv zv wv) + "Set all fields in a vector" + (with-gensyms (vec) + `(let ((,vec ,v)) + (set! (-> ,vec x) ,xv) + (set! (-> ,vec y) ,yv) + (set! (-> ,vec z) ,zv) + (set! (-> ,vec w) ,wv) + ,vec + )) + ) + +(defmacro set-vector-xyz! (v xv yv zv) + "Set xyz fields in a vector" + (with-gensyms (vec) + `(let ((,vec ,v)) + (set! (-> ,vec x) ,xv) + (set! (-> ,vec y) ,yv) + (set! (-> ,vec z) ,zv) + ,vec + )) + ) + ;; DECOMP BEGINS +(deftype bit-array (basic) + ((length int32) + (allocated-length int32) + (_pad uint8) + (bytes uint8 :dynamic :overlay-at _pad) + ) + (:methods + (new (symbol type int) _type_) + (get-bit (_type_ int) symbol) + (clear-bit (_type_ int) int) + (set-bit (_type_ int) int) + (clear-all! (_type_) _type_) + ) + ) + + +(defmethod new bit-array ((allocation symbol) (type-to-make type) (arg0 int)) + "Allocate a new bit-array with room arg0 bits." + (let ((v0-0 (object-new allocation type-to-make (+ (/ (logand -8 (+ arg0 7)) 8) -1 (-> type-to-make size))))) + (set! (-> v0-0 length) arg0) + (set! (-> v0-0 allocated-length) arg0) + v0-0 + ) + ) + +(defmethod length ((this bit-array)) + (-> this length) + ) + +;; WARN: Return type mismatch uint vs int. +(defmethod asize-of ((this bit-array)) + (the-as int (+ (-> this type size) (/ (logand -8 (+ (-> this allocated-length) 7)) 8))) + ) + +(defmethod get-bit ((this bit-array) (arg0 int)) + "Get the nth bit as a boolean." + (let ((v1-2 (-> this bytes (/ arg0 8)))) + (logtest? v1-2 (ash 1 (logand arg0 7))) + ) + ) + +(defmethod clear-bit ((this bit-array) (arg0 int)) + "Set the nth bit to 0." + (logclear! (-> this bytes (/ arg0 8)) (ash 1 (logand arg0 7))) + 0 + ) + +(defmethod set-bit ((this bit-array) (arg0 int)) + "Set the nth bit to 1." + (logior! (-> this bytes (/ arg0 8)) (ash 1 (logand arg0 7))) + 0 + ) + +(defmethod clear-all! ((this bit-array)) + "Set all bits to 0." + (countdown (v1-2 (/ (logand -8 (+ (-> this allocated-length) 7)) 8)) + (nop!) + (nop!) + (set! (-> this bytes v1-2) (the-as uint 0)) + ) + this + ) + +(deftype vector16ub (structure) + ((data uint8 16) + (quad uint128 :overlay-at (-> data 0)) + ) + ) + + +(deftype vector4ub (structure) + ((data uint8 4) + (x uint8 :overlay-at (-> data 0)) + (y uint8 :overlay-at (-> data 1)) + (z uint8 :overlay-at (-> data 2)) + (w uint8 :overlay-at (-> data 3)) + (clr uint32 :overlay-at (-> data 0)) + ) + :pack-me + ) + + +(deftype vector4b (structure) + ((data int8 4) + (x int8 :overlay-at (-> data 0)) + (y int8 :overlay-at (-> data 1)) + (z int8 :overlay-at (-> data 2)) + (w int8 :overlay-at (-> data 3)) + (clr int32 :overlay-at (-> data 0)) + ) + :pack-me + ) + + +(deftype vector2ub (structure) + ((data uint8 2) + (x uint8 :overlay-at (-> data 0)) + (y uint8 :overlay-at (-> data 1)) + (clr uint16 :overlay-at (-> data 0)) + ) + :pack-me + ) + + +(deftype vector2b (structure) + ((data int8 2) + (x int8 :overlay-at (-> data 0)) + (y int8 :overlay-at (-> data 1)) + (clr int16 :overlay-at (-> data 0)) + ) + ) + + +(deftype vector2h (structure) + ((data int16 2) + (x int16 :overlay-at (-> data 0)) + (y int16 :overlay-at (-> data 1)) + ) + :pack-me + ) + + +(deftype vector2uh (structure) + ((data uint16 2) + (x uint16 :overlay-at (-> data 0)) + (y uint16 :overlay-at (-> data 1)) + (val uint32 :overlay-at (-> data 0)) + ) + :pack-me + ) + + +(deftype vector3h (structure) + ((data int16 3) + (x int16 :overlay-at (-> data 0)) + (y int16 :overlay-at (-> data 1)) + (z int16 :overlay-at (-> data 2)) + ) + ) + + +(deftype vector3uh (structure) + ((data uint16 3) + (x uint16 :overlay-at (-> data 0)) + (y uint16 :overlay-at (-> data 1)) + (z uint16 :overlay-at (-> data 2)) + ) + ) + + +(deftype vector2w (structure) + ((data int32 2) + (x int32 :overlay-at (-> data 0)) + (y int32 :overlay-at (-> data 1)) + ) + ) + + +(deftype vector3w (structure) + ((data int32 3) + (x int32 :overlay-at (-> data 0)) + (y int32 :overlay-at (-> data 1)) + (z int32 :overlay-at (-> data 2)) + ) + ) + + +(deftype vector4w (structure) + ((data int32 4) + (x int32 :overlay-at (-> data 0)) + (y int32 :overlay-at (-> data 1)) + (z int32 :overlay-at (-> data 2)) + (w int32 :overlay-at (-> data 3)) + (dword uint64 2 :overlay-at (-> data 0)) + (quad uint128 :overlay-at (-> data 0)) + ) + ) + + +(deftype vector2 (structure) + ((data float 2) + (x float :overlay-at (-> data 0)) + (y float :overlay-at (-> data 1)) + ) + :allow-misaligned + ) + + +(deftype vector3 (structure) + ((data float 3) + (x float :overlay-at (-> data 0)) + (y float :overlay-at (-> data 1)) + (z float :overlay-at (-> data 2)) + ) + ) + + +(deftype vector4 (structure) + ((data float 4) + (x float :overlay-at (-> data 0)) + (y float :overlay-at (-> data 1)) + (z float :overlay-at (-> data 2)) + (w float :overlay-at (-> data 3)) + (dword uint64 2 :overlay-at (-> data 0)) + (quad uint128 :overlay-at (-> data 0)) + ) + ) + + +(defmethod print ((this vector4w)) + (format #t "#" (-> this x) (-> this y) (-> this z) (-> this w) this) + this + ) + +(deftype vector4w-2 (structure) + ((data int32 8) + (quad uint128 2 :overlay-at (-> data 0)) + (vector vector4w 2 :inline :overlay-at (-> data 0)) + ) + ) + + +(deftype vector4w-3 (structure) + ((data int32 12) + (quad uint128 3 :overlay-at (-> data 0)) + (vector vector4w 3 :inline :overlay-at (-> data 0)) + ) + ) + + +(deftype vector4w-4 (structure) + ((data int32 16) + (quad uint128 4 :overlay-at (-> data 0)) + (vector vector4w 4 :inline :overlay-at (-> data 0)) + ) + ) + + +(deftype vector4h (structure) + ((data int16 4) + (x int16 :overlay-at (-> data 0)) + (y int16 :overlay-at (-> data 1)) + (z int16 :overlay-at (-> data 2)) + (w int16 :overlay-at (-> data 3)) + (long uint64 :overlay-at (-> data 0)) + ) + :pack-me + ) + + +(deftype vector8h (structure) + ((data int16 8) + (quad uint128 :overlay-at (-> data 0)) + ) + ) + + +(deftype vector16b (structure) + ((data int8 16) + (quad uint128 :overlay-at (-> data 0)) + ) + ) + + + +(defmethod print ((this vector)) + (format #t "#" (-> this x) (-> this y) (-> this z) (-> this w) this) + this + ) + +(define *null-vector* (new 'static 'vector :w 1.0)) + +(define *identity-vector* (new 'static 'vector :x 1.0 :y 1.0 :z 1.0 :w 1.0)) + +(define *x-vector* (new 'static 'vector :x 1.0 :w 1.0)) + +(define *y-vector* (new 'static 'vector :y 1.0 :w 1.0)) + +(define *z-vector* (new 'static 'vector :z 1.0 :w 1.0)) + +(define *up-vector* (new 'static 'vector :y 1.0 :w 1.0)) + +(deftype vector4s-3 (structure) + ((data float 12) + (quad uint128 3 :overlay-at (-> data 0)) + (vector vector 3 :inline :overlay-at (-> data 0)) + ) + ) + + +(deftype vector-array (inline-array-class) + ((data vector :inline :dynamic) + ) + ) + + +(set! (-> vector-array heap-base) (the-as uint 16)) + +(deftype rgbaf (vector) + ((r float :overlay-at (-> data 0)) + (g float :overlay-at (-> data 1)) + (b float :overlay-at (-> data 2)) + (a float :overlay-at (-> data 3)) + ) + ) + + +(deftype plane (vector) + ((a float :overlay-at (-> data 0)) + (b float :overlay-at (-> data 1)) + (c float :overlay-at (-> data 2)) + (d float :overlay-at (-> data 3)) + ) + ) + + +(deftype sphere (vector) + ((r float :overlay-at (-> data 3)) + ) + ) + + +(deftype isphere (vec4s) + () + ) + +(defmacro static-vector (x y z w) + "Creates a static vector." + `(new 'static 'vector :x ,x :y ,y :z ,z :w ,w) + ) +(defmacro static-vectorm (x y z) + "Creates a static vector using meters. `w` is set to 1.0" + `(new 'static 'vector :x (meters ,x) :y (meters ,y) :z (meters ,z) :w 1.0) + ) +(defmacro static-spherem (x y z r) + "Creates a static vector using meters where the w component is used as sphere radius. For a 'real' sphere, use [[static-bspherem]]." + `(new 'static 'vector :x (meters ,x) :y (meters ,y) :z (meters ,z) :w (meters ,r)) + ) +(defmacro static-bspherem (x y z r) + "Creates a static sphere using meters." + `(new 'static 'sphere :x (meters ,x) :y (meters ,y) :z (meters ,z) :w (meters ,r)) + ) + +(deftype box8s (structure) + ((data float 8) + (quad uint128 2 :overlay-at (-> data 0)) + (vector vector 2 :overlay-at (-> data 0)) + (min vector :inline :overlay-at (-> data 0)) + (max vector :inline :overlay-at (-> data 4)) + ) + ) + + +(deftype box8s-array (inline-array-class) + ((data box8s :inline :dynamic) + ) + ) + + +(set! (-> box8s-array heap-base) (the-as uint 32)) + +(deftype vertical-planes (structure) + ((data uint128 4) + ) + ) + + +(deftype vertical-planes-array (basic) + ((length uint32) + (data vertical-planes :inline :dynamic) + ) + ) + + +(deftype qword (structure) + ((data uint32 4) + (byte uint8 16 :overlay-at (-> data 0)) + (hword uint16 8 :overlay-at (-> data 0)) + (word uint32 4 :overlay-at (-> data 0)) + (dword uint64 2 :overlay-at (-> data 0)) + (quad uint128 :overlay-at (-> data 0)) + (vector vector :inline :overlay-at (-> data 0)) + (vector4w vector4w :inline :overlay-at (-> data 0)) + ) + ) + + +(deftype vector3s (structure) + ((data float 3) + (x float :overlay-at (-> data 0)) + (y float :overlay-at (-> data 1)) + (z float :overlay-at (-> data 2)) + ) + :pack-me + ) + +(defun vector-dot ((a vector) (b vector)) + "Take the dot product of two vectors. +Only does the x, y, z compoments. +Originally handwritten assembly to space out loads and use FPU accumulator" + (declare (inline)) + (let ((result 0.)) + (+! result (* (-> a x) (-> b x))) + (+! result (* (-> a y) (-> b y))) + (+! result (* (-> a z) (-> b z))) + result + ) + ) + +(defun vector-dot-vu ((arg0 vector) (arg1 vector)) + "Take the dot product (xyz only). Using VU0." + (local-vars (v0-0 float)) + (rlet ((vf1 :class vf) + (vf2 :class vf) + ) + (.lvf vf1 (&-> arg0 quad)) + (.lvf vf2 (&-> arg1 quad)) + (.mul.vf vf1 vf1 vf2) + (.add.y.vf vf1 vf1 vf1 :mask #b1) + (.add.z.vf vf1 vf1 vf1 :mask #b1) + (.mov v0-0 vf1) + v0-0 + ) + ) + +(defun vector4-dot ((a vector) (b vector)) + "Take the dot product of two vectors. +Does the x, y, z, and w compoments" + (declare (inline)) + (let ((result 0.)) + (+! result (* (-> a x) (-> b x))) + (+! result (* (-> a y) (-> b y))) + (+! result (* (-> a z) (-> b z))) + (+! result (* (-> a w) (-> b w))) + result + ) + ) + +(defun vector4-dot-vu ((arg0 vector) (arg1 vector)) + "Take the dot product (xyzw). Using VU0." + (local-vars (v0-0 float)) + (rlet ((acc :class vf) + (vf0 :class vf) + (vf1 :class vf) + (vf2 :class vf) + (vf3 :class vf) + ) + (init-vf0-vector) + (.lvf vf1 (&-> arg0 quad)) + (.lvf vf2 (&-> arg1 quad)) + (.mul.vf vf1 vf1 vf2) + (.add.w.vf vf3 vf0 vf0 :mask #b1) + (.mul.x.vf acc vf3 vf1 :mask #b1) + (.add.mul.y.vf acc vf3 vf1 acc :mask #b1) + (.add.mul.z.vf acc vf3 vf1 acc :mask #b1) + (.add.mul.w.vf vf1 vf3 vf1 acc :mask #b1) + (.mov v0-0 vf1) + v0-0 + ) + ) + +(defmacro print-vf (vf &key (name #f)) + "Print out a vf register as a vector." + `(let ((temp (new 'stack 'vector))) + (.svf temp ,vf) + ,(if name + `(format #t "~A: ~`vector`P~%" (quote ,name) temp) + `(format #t "~`vector`P~%" temp) + ) + ) + ) + +(defmacro print-vf-hex (vf) + "Print out a vf register as 4x 32-bit hexadecimal integers" + `(let ((temp (new 'stack 'vector4w))) + (.svf temp ,vf) + (format #t "~`vector4w`P~%" temp) + ) + ) + +(defmacro print-vf-dec (vf) + "Print out a vf register as 4x 32-bit base-10 integers" + `(let ((temp (new 'stack 'vector4w))) + (.svf temp ,vf) + (format #t " ~d ~d ~d ~d~%" (-> temp data 0) (-> temp data 1) (-> temp data 2) (-> temp data 3)) + ) + ) + +(defun vector+! ((dst vector) (a vector) (b vector)) + "Set dst = a + b. The w component of dst is set to 0." + (declare (inline)) + (rlet ((vf0 :class vf :reset-here #t) + (vf1 :class vf :reset-here #t) + (vf2 :class vf :reset-here #t) + (vf3 :class vf :reset-here #t)) + ;; load vectors + (.lvf vf2 a) + (.lvf vf3 b) + (init-vf0-vector) + ;; add + (.add.vf vf1 vf2 vf3) + ;; set w = 1 + (.blend.vf vf1 vf1 vf0 :mask #b1000) + ;; store + (.svf dst vf1) + ) + dst + ) + +(defun vector-! ((dst vector) (a vector) (b vector)) + "Set dst = a - b. The w componenent of dst is set to 0." + (declare (inline)) + (rlet ((vf0 :class vf :reset-here #t) + (vf1 :class vf :reset-here #t) + (vf2 :class vf :reset-here #t) + (vf3 :class vf :reset-here #t)) + ;; load vectors + (.lvf vf2 a) + (.lvf vf3 b) + (init-vf0-vector) + ;; subtract + (.sub.vf vf1 vf2 vf3) + ;; set w = 1 + (.blend.vf vf1 vf1 vf0 :mask #b1000) + ;; store + (.svf dst vf1) + ) + dst + ) + +(defun vector-zero! ((dst vector)) + "Set xyzw to 0." + (declare (inline)) + (rlet ((vf1 :class vf :reset-here #t)) + ;; set vf1 = 0 + (.xor.vf vf1 vf1 vf1) + ;; store the 0 + (.svf dst vf1) + ) + dst + ) + +(defun vector-reset! ((dst vector)) + "Set vector to <0,0,0,1>." + (declare (inline)) + (vector-zero! dst) + (set! (-> dst w) 1.0) + dst + ) + +(defun vector-copy! ((arg0 vector) (arg1 vector)) + "Copy arg1 to arg0." + (declare (inline)) + (set! (-> arg0 quad) (-> arg1 quad)) + arg0 + ) + +(defun vector-length< ((arg0 vector) (arg1 float)) + (let ((f0-0 (vector-length-squared arg0)) + (f1-0 arg1) + ) + (< f0-0 (* f1-0 f1-0)) + ) + ) + +(defun vector-length> ((arg0 vector) (arg1 float)) + (< (* arg1 arg1) (vector-length-squared arg0)) + ) + +(define *zero-vector* (new 'static 'vector)) + +(defmacro new-stack-vector0 () + "Get a stack vector that's set to 0. + This is more efficient than (new 'stack 'vector) because + this doesn't call the constructor." + `(let ((vec (new 'stack-no-clear 'vector))) + (set! (-> vec quad) (the-as uint128 0)) + vec + ) + ) \ No newline at end of file diff --git a/goal_src/jak3/engine/physics/gravity-h.gc b/goal_src/jak3/engine/physics/gravity-h.gc index 3368a39a40..7e61989dce 100644 --- a/goal_src/jak3/engine/physics/gravity-h.gc +++ b/goal_src/jak3/engine/physics/gravity-h.gc @@ -7,3 +7,4 @@ ;; DECOMP BEGINS +;; No code! diff --git a/scripts/decomp_progress.py b/scripts/decomp_progress.py index 899ac87fb7..785c8d1d09 100644 --- a/scripts/decomp_progress.py +++ b/scripts/decomp_progress.py @@ -1,10 +1,12 @@ import os +# change working dir to script location +os.chdir(os.path.dirname(__file__)) import glob import argparse ### Script to track decompilation progress. -### Example usage: python3 scripts/decomp_progress.py ~/jak-project/goal_src/jak2 +### Example usage: python3 scripts/decomp_progress.py jak2 def get_goal_files(root_dir, ext = "*.gc"): """Get all GOAL source files under root_dir.""" @@ -19,7 +21,7 @@ def lines_in_file(file_path): return lines -def print_table(stats, total_gc_files): +def print_table(game, stats, total_gc_files): total_lines = 0 print("| {: <24} | {: <6} |".format("file name", "lines")) print("-------------------------------------") @@ -29,7 +31,11 @@ def print_table(stats, total_gc_files): print("-------------------------------------") print("| {: <24} | {: >6} |".format("TOTAL", total_lines)) print("-------------------------------------") - estimated_lines = 1000000 + estimated_lines = 500000 + if game == "jak2": + estimated_lines = 1000000 + elif game == "jak3": + estimated_lines = 1200000 print("Progress: {}/{} lines ({:.2f}%)".format(total_lines, estimated_lines, 100. * total_lines / estimated_lines)) print("{}/{} files modified from template ({:.2f}%)".format(len(stats), total_gc_files, 100. * len(stats) / total_gc_files)) @@ -37,19 +43,23 @@ def print_table(stats, total_gc_files): def main(): parser = argparse.ArgumentParser() - parser.add_argument(dest='goal_src', help='the goal_src folder') + parser.add_argument(dest='game', help='game name') args = parser.parse_args() - all_files = get_goal_files(args.goal_src) + gsrc_path = "../goal_src/" + args.game + all_files = get_goal_files(gsrc_path) - ref_files = get_goal_files(args.goal_src + "/../../test/decompiler/reference/jak2", "*_REF.gc") + ref_files = get_goal_files("../test/decompiler/reference/" + args.game, "*_REF.gc") ref_files_no_ext = [os.path.basename(fn)[:-7] for fn in ref_files] - - file_stats = [] total_gc_files = 0 excluded_files = {"game_dgos.gc", "all_files.gc", "goal-lib.gc", "ocean-trans-tables.gc", "ocean-frames.gc", - "ocean-tables.gc"} + "ocean-tables.gc", "art-elts.gc", "joint-nodes.gc", "compiler-setup.gc", "kernel-defs.gc"} + excluded_paths = {"pc", "examples", "old"} + for path in excluded_paths: + files = get_goal_files(gsrc_path + "/" + path) + for fn in files: + excluded_files.add(os.path.basename(fn)) modified = set() for fn in all_files: @@ -76,10 +86,7 @@ def main(): print("Missing ref files:") for fn in missing_ref_files: print(" {}".format(fn)) - - - print_table(file_stats, total_gc_files) - + print_table(args.game, file_stats, total_gc_files) if __name__ == "__main__": main() diff --git a/scripts/gsrc/utils.py b/scripts/gsrc/utils.py index c14b95e373..e448cbcad6 100644 --- a/scripts/gsrc/utils.py +++ b/scripts/gsrc/utils.py @@ -3,30 +3,36 @@ import os jak1_files = None jak2_files = None +jak3_files = None with open('./goal_src/jak1/build/all_objs.json', 'r') as f: jak1_files = json.load(f) with open('./goal_src/jak2/build/all_objs.json', 'r') as f: jak2_files = json.load(f) +with open('./goal_src/jak3/build/all_objs.json', 'r') as f: + jak3_files = json.load(f) def get_file_list(game_name): - if game_name == "jak1": - return jak1_files - else: - return jak2_files + match game_name: + case "jak1": + return jak1_files + case "jak2": + return jak2_files + case "jak3": + return jak3_files def get_gsrc_path_from_filename(game_name, file_name): file_list = get_file_list(game_name) src_path = "" for f in file_list: - if f[2] != 3: + if f[2] != 3 and f[2] != 5: continue if f[0] == file_name: src_path = f[4] break path = "./goal_src/{}/{}/{}.gc".format(game_name, src_path, file_name) if not os.path.exists(path): - print("{} couldn't find in /goal_src/{}!".format(file_name, game_name)) + print("couldn't find {} in /goal_src/{}!".format(file_name, game_name)) exit(1) return path @@ -37,7 +43,7 @@ def get_ref_path_from_filename(game_name, file_name, ref_folder): file_list = get_file_list(game_name) src_path = "" for f in file_list: - if f[2] != 3: + if f[2] != 3 and f[2] != 5: continue if f[0] == file_name: src_path = f[4] diff --git a/test/decompiler/reference/jak3/decompiler-macros.gc b/test/decompiler/reference/jak3/decompiler-macros.gc index 22c9d8ad03..e9fd3d8e6e 100644 --- a/test/decompiler/reference/jak3/decompiler-macros.gc +++ b/test/decompiler/reference/jak3/decompiler-macros.gc @@ -1 +1,57 @@ ;; This file should contain an implementation for all macros that the decompiler uses in its output. + +(defmacro init-vf0-vector () + "Initializes the VF0 vector which is a constant vector in the VU set to <0,0,0,1>" + `(.lvf vf0 (new 'static 'vector :x 0.0 :y 0.0 :z 0.0 :w 1.0)) + ) + +(defmacro new-stack-vector0 () + "Get a stack vector that's set to 0. + This is more efficient than (new 'stack 'vector) because + this doesn't call the constructor." + `(let ((vec (new 'stack-no-clear 'vector))) + (set! (-> vec quad) (the-as uint128 0)) + vec + ) + ) + +(defmacro set-vector! (v xv yv zv wv) + "Set all fields in a vector" + (with-gensyms (vec) + `(let ((,vec ,v)) + (set! (-> ,vec x) ,xv) + (set! (-> ,vec y) ,yv) + (set! (-> ,vec z) ,zv) + (set! (-> ,vec w) ,wv) + ,vec + )) + ) + +(defmacro new-stack-quaternion0 () + "Get a stack quaternion that's set to 0. + This is more efficient than (new 'stack 'quaternion) because + this doesn't call the constructor." + `(let ((q (new 'stack-no-clear 'quaternion))) + (set! (-> q quad) (the-as uint128 0)) + q + ) + ) + +(defmacro with-pp (&rest body) + "execute the body with pp bound to the current process register." + `(rlet ((pp :reg r13 :reset-here #t :type process)) + ,@body) + ) + +(defconstant PP (with-pp pp)) + +(defmacro make-u128 (upper lower) + `(rlet ((result :class i128) + (upper-xmm :class i128) + (lower-xmm :class i128)) + (.mov upper-xmm ,upper) + (.mov lower-xmm ,lower) + (.pcpyld result upper-xmm lower-xmm) + (the uint result) + ) + ) \ No newline at end of file diff --git a/test/decompiler/reference/jak3/engine/geometry/bounding-box-h_REF.gc b/test/decompiler/reference/jak3/engine/geometry/bounding-box-h_REF.gc new file mode 100644 index 0000000000..e519a8923c --- /dev/null +++ b/test/decompiler/reference/jak3/engine/geometry/bounding-box-h_REF.gc @@ -0,0 +1,123 @@ +;;-*-Lisp-*- +(in-package goal) + +;; definition of type bounding-box +(deftype bounding-box (structure) + ((min vector :inline) + (max vector :inline) + ) + (:methods + (add-spheres! (_type_ (inline-array sphere) int) int) + (add-box! (_type_ bounding-box) int) + (add-point! (_type_ vector) none) + (intersects-line-segment? (_type_ vector vector) symbol) + (set-from-point-offset! (_type_ vector vector) none) + (set-from-point-offset-pad! (_type_ vector vector float) int) + (set-to-point! (_type_ vector) none) + (set-from-sphere! (_type_ sphere) none) + (set-from-spheres! (_type_ (inline-array sphere) int) int) + (get-bounding-sphere (_type_ vector) vector) + (inside-xyz? (bounding-box vector) symbol) + (inside-xz? (bounding-box vector) symbol) + ) + ) + +;; definition for method 3 of type bounding-box +(defmethod inspect ((this bounding-box)) + (when (not this) + (set! this this) + (goto cfg-4) + ) + (format #t "[~8x] ~A~%" this 'bounding-box) + (format #t "~1Tmin: ~`vector`P~%" (-> this min)) + (format #t "~1Tmax: ~`vector`P~%" (-> this max)) + (label cfg-4) + this + ) + +;; definition of type bounding-box2 +(deftype bounding-box2 (structure) + ((min vector2 :inline) + (max vector2 :inline) + ) + ) + +;; definition for method 3 of type bounding-box2 +(defmethod inspect ((this bounding-box2)) + (when (not this) + (set! this this) + (goto cfg-4) + ) + (format #t "[~8x] ~A~%" this 'bounding-box2) + (format #t "~1Tmin: #~%" (-> this min)) + (format #t "~1Tmax: #~%" (-> this max)) + (label cfg-4) + this + ) + +;; definition of type bounding-box4w +(deftype bounding-box4w (structure) + ((min vector4w :inline) + (max vector4w :inline) + ) + ) + +;; definition for method 3 of type bounding-box4w +(defmethod inspect ((this bounding-box4w)) + (when (not this) + (set! this this) + (goto cfg-4) + ) + (format #t "[~8x] ~A~%" this 'bounding-box4w) + (format #t "~1Tmin: ~`vector4w`P~%" (-> this min)) + (format #t "~1Tmax: ~`vector4w`P~%" (-> this max)) + (label cfg-4) + this + ) + +;; definition of type bounding-box-both +(deftype bounding-box-both (structure) + ((box bounding-box :inline) + (box4w bounding-box4w :inline) + ) + ) + +;; definition for method 3 of type bounding-box-both +(defmethod inspect ((this bounding-box-both)) + (when (not this) + (set! this this) + (goto cfg-4) + ) + (format #t "[~8x] ~A~%" this 'bounding-box-both) + (format #t "~1Tbox: #~%" (-> this box)) + (format #t "~1Tbox4w: #~%" (-> this box4w)) + (label cfg-4) + this + ) + +;; definition of type bounding-box-array +(deftype bounding-box-array (inline-array-class) + ((data bounding-box :dynamic) + ) + ) + +;; definition for method 3 of type bounding-box-array +(defmethod inspect ((this bounding-box-array)) + (when (not this) + (set! this this) + (goto cfg-4) + ) + (format #t "[~8x] ~A~%" this (-> this type)) + (format #t "~1Tlength: ~D~%" (-> this length)) + (format #t "~1Tallocated-length: ~D~%" (-> this allocated-length)) + (format #t "~1Tdata[0] @ #x~X~%" (-> this data)) + (label cfg-4) + this + ) + +;; failed to figure out what this is: +(set! (-> bounding-box-array heap-base) (the-as uint 32)) + + + + diff --git a/test/decompiler/reference/jak3/engine/geometry/bounding-box_REF.gc b/test/decompiler/reference/jak3/engine/geometry/bounding-box_REF.gc new file mode 100644 index 0000000000..80eb1f65ea --- /dev/null +++ b/test/decompiler/reference/jak3/engine/geometry/bounding-box_REF.gc @@ -0,0 +1,281 @@ +;;-*-Lisp-*- +(in-package goal) + +;; definition for method 19 of type bounding-box +(defmethod inside-xyz? ((this bounding-box) (arg0 vector)) + "Is the point in the box?" + (and (< (-> this min x) (-> arg0 x)) + (< (-> this min y) (-> arg0 y)) + (< (-> this min z) (-> arg0 z)) + (< (-> arg0 x) (-> this max x)) + (< (-> arg0 y) (-> this max y)) + (< (-> arg0 z) (-> this max z)) + ) + ) + +;; definition for method 20 of type bounding-box +(defmethod inside-xz? ((this bounding-box) (arg0 vector)) + "Is the point in the box? Check xz only." + (and (< (-> this min x) (-> arg0 x)) + (< (-> this min z) (-> arg0 z)) + (< (-> arg0 x) (-> this max x)) + (< (-> arg0 z) (-> this max z)) + ) + ) + +;; definition for function box-vector-enside? +(defun box-vector-enside? ((arg0 bounding-box) (arg1 vector)) + "Is the point in the box? On the edge doesn't count." + (and (< (-> arg0 min x) (-> arg1 x)) + (< (-> arg0 min y) (-> arg1 y)) + (< (-> arg0 min z) (-> arg1 z)) + (< (-> arg1 x) (-> arg0 max x)) + (< (-> arg1 y) (-> arg0 max y)) + (< (-> arg1 z) (-> arg0 max z)) + ) + ) + +;; definition for function box-vector-inside? +(defun box-vector-inside? ((arg0 bounding-box) (arg1 vector)) + "Is the point in the box? On the edge counts." + (and (>= (-> arg1 x) (-> arg0 min x)) + (>= (-> arg1 y) (-> arg0 min y)) + (>= (-> arg1 z) (-> arg0 min z)) + (>= (-> arg0 max x) (-> arg1 x)) + (>= (-> arg0 max y) (-> arg1 y)) + (>= (-> arg0 max z) (-> arg1 z)) + ) + ) + +;; definition for method 13 of type bounding-box +;; WARN: Return type mismatch int vs none. +(defmethod set-from-point-offset! ((this bounding-box) (arg0 vector) (arg1 vector)) + "Set to the smallest box containing arg0, (arg0 + arg1)" + (rlet ((vf0 :class vf) + (vf1 :class vf) + (vf2 :class vf) + (vf3 :class vf) + (vf4 :class vf) + (vf5 :class vf) + ) + (init-vf0-vector) + (.lvf vf3 (&-> arg1 quad)) + (.lvf vf4 (&-> arg0 quad)) + (.add.vf vf5 vf4 vf3) + (.min.vf vf1 vf4 vf5) + (.max.vf vf2 vf4 vf5) + (.mov.vf vf1 vf0 :mask #b1000) + (.mov.vf vf2 vf0 :mask #b1000) + (.svf (&-> this min quad) vf1) + (.svf (&-> this max quad) vf2) + 0 + (none) + ) + ) + +;; definition for method 11 of type bounding-box +;; WARN: Return type mismatch int vs none. +(defmethod add-point! ((this bounding-box) (arg0 vector)) + "Expand the box as needed to contain the given point." + (rlet ((vf1 :class vf) + (vf2 :class vf) + (vf3 :class vf) + ) + (.lvf vf1 (&-> this min quad)) + (.lvf vf2 (&-> this max quad)) + (.lvf vf3 (&-> arg0 quad)) + (.min.vf vf1 vf1 vf3) + (.max.vf vf2 vf2 vf3) + (.svf (&-> this min quad) vf1) + (.svf (&-> this max quad) vf2) + 0 + (none) + ) + ) + +;; definition for method 10 of type bounding-box +(defmethod add-box! ((this bounding-box) (arg0 bounding-box)) + "Expand the box as needed to contain the given box." + (rlet ((vf1 :class vf) + (vf2 :class vf) + (vf3 :class vf) + (vf4 :class vf) + ) + (.lvf vf1 (&-> this min quad)) + (.lvf vf2 (&-> this max quad)) + (.lvf vf3 (&-> arg0 min quad)) + (.lvf vf4 (&-> arg0 max quad)) + (.min.vf vf1 vf1 vf3) + (.max.vf vf2 vf2 vf4) + (.svf (&-> this min quad) vf1) + (.svf (&-> this max quad) vf2) + 0 + ) + ) + +;; definition for method 15 of type bounding-box +;; INFO: Used lq/sq +;; WARN: Return type mismatch int vs none. +(defmethod set-to-point! ((this bounding-box) (arg0 vector)) + "Set the box to be a single point." + (set! (-> this min quad) (-> arg0 quad)) + (set! (-> this max quad) (-> arg0 quad)) + 0 + (none) + ) + +;; definition for method 14 of type bounding-box +(defmethod set-from-point-offset-pad! ((this bounding-box) (arg0 vector) (arg1 vector) (arg2 float)) + "Set the box to contain arg0, arg0 + offset, with some padding." + (rlet ((vf0 :class vf) + (vf1 :class vf) + (vf2 :class vf) + (vf3 :class vf) + (vf4 :class vf) + (vf5 :class vf) + (vf6 :class vf) + ) + (init-vf0-vector) + (.lvf vf4 (&-> arg1 quad)) + (.lvf vf5 (&-> arg0 quad)) + (.mov vf1 arg2) + (.add.vf vf6 vf5 vf4) + (.min.vf vf2 vf5 vf6) + (.max.vf vf3 vf5 vf6) + (.add.x.vf vf3 vf3 vf1 :mask #b111) + (.sub.x.vf vf2 vf2 vf1 :mask #b111) + (.mov.vf vf2 vf0 :mask #b1000) + (.mov.vf vf3 vf0 :mask #b1000) + (.svf (&-> this min quad) vf2) + (.svf (&-> this max quad) vf3) + 0 + ) + ) + +;; definition for method 16 of type bounding-box +;; WARN: Return type mismatch int vs none. +(defmethod set-from-sphere! ((this bounding-box) (arg0 sphere)) + "Set the box to contain a single sphere." + (rlet ((vf0 :class vf) + (vf1 :class vf) + (vf2 :class vf) + (vf3 :class vf) + ) + (init-vf0-vector) + (.lvf vf1 (&-> arg0 quad)) + (.sub.w.vf vf2 vf1 vf1 :mask #b111) + (.add.w.vf vf3 vf1 vf1 :mask #b111) + (.mov.vf vf2 vf0 :mask #b1000) + (.mov.vf vf3 vf0 :mask #b1000) + (.svf (&-> this min quad) vf2) + (.svf (&-> this max quad) vf3) + 0 + (none) + ) + ) + +;; definition for method 17 of type bounding-box +;; ERROR: function was not converted to expressions. Cannot decompile. + +;; definition for method 9 of type bounding-box +;; ERROR: function was not converted to expressions. Cannot decompile. + +;; definition for method 18 of type bounding-box +(defmethod get-bounding-sphere ((this bounding-box) (arg0 vector)) + "Get a bounding sphere for a bounding box." + (let* ((a1-2 (vector-! (new 'stack-no-clear 'vector) (-> this max) (-> this min))) + (a0-3 (vector-float*! (new 'stack-no-clear 'vector) a1-2 0.5)) + ) + (vector+! arg0 (-> this min) a0-3) + (set! (-> arg0 w) (vector-length a0-3)) + ) + arg0 + ) + +;; definition of type liang-barsky-line-clip-params +(deftype liang-barsky-line-clip-params (structure) + ((te float) + (tl float) + ) + ) + +;; definition for method 3 of type liang-barsky-line-clip-params +(defmethod inspect ((this liang-barsky-line-clip-params)) + (when (not this) + (set! this this) + (goto cfg-4) + ) + (format #t "[~8x] ~A~%" this 'liang-barsky-line-clip-params) + (format #t "~1Tte: ~f~%" (-> this te)) + (format #t "~1Ttl: ~f~%" (-> this tl)) + (label cfg-4) + this + ) + +;; definition for function liang-barsky-line-clipt +(defun liang-barsky-line-clipt ((arg0 liang-barsky-line-clip-params) (arg1 float) (arg2 float)) + "Clip test in 1 dimension. Is arg1 in arg2?" + (cond + ((< 0.0 arg1) + (let ((f0-2 (/ arg2 arg1))) + (if (< (-> arg0 tl) f0-2) + (return #f) + ) + (if (< (-> arg0 te) f0-2) + (set! (-> arg0 te) f0-2) + ) + ) + ) + ((< arg1 0.0) + (let ((f0-5 (/ arg2 arg1))) + (if (< f0-5 (-> arg0 te)) + (return #f) + ) + (if (< f0-5 (-> arg0 tl)) + (set! (-> arg0 tl) f0-5) + ) + ) + ) + (else + (if (< 0.0 arg2) + (return #f) + ) + ) + ) + #t + ) + +;; definition for method 12 of type bounding-box +;; WARN: disable def twice: 23. This may happen when a cond (no else) is nested inside of another conditional, but it should be rare. +(defmethod intersects-line-segment? ((this bounding-box) (arg0 vector) (arg1 vector)) + "Check intersection in xz plane, using liang-barsky. Not sure if this actually +a useful check or not..." + (let ((f28-0 (- (-> arg1 x) (-> arg0 x))) + (f30-0 (- (-> arg1 z) (-> arg0 z))) + ) + (cond + ((and (= f28-0 0.0) (= f30-0 0.0)) + (let ((f1-2 (-> arg0 x)) + (f0-4 (-> arg0 z)) + ) + (and (>= f1-2 (-> this min x)) (>= (-> this max x) f1-2) (>= f0-4 (-> this min z)) (>= (-> this max z) f0-4)) + ) + ) + (else + (let ((s4-0 (new 'stack-no-clear 'liang-barsky-line-clip-params))) + (set! (-> s4-0 te) 0.0) + (set! (-> s4-0 tl) 1.0) + (and (liang-barsky-line-clipt s4-0 f28-0 (- (-> this min x) (-> arg0 x))) + (liang-barsky-line-clipt s4-0 (- f28-0) (- (-> arg0 x) (-> this max x))) + (liang-barsky-line-clipt s4-0 f30-0 (- (-> this min z) (-> arg0 z))) + (liang-barsky-line-clipt s4-0 (- f30-0) (- (-> arg0 z) (-> this max z))) + ) + ) + ) + ) + ) + ) + + + + diff --git a/test/decompiler/reference/jak3/engine/geometry/geometry-h_REF.gc b/test/decompiler/reference/jak3/engine/geometry/geometry-h_REF.gc new file mode 100644 index 0000000000..c293a7d54c --- /dev/null +++ b/test/decompiler/reference/jak3/engine/geometry/geometry-h_REF.gc @@ -0,0 +1,145 @@ +;;-*-Lisp-*- +(in-package goal) + +;; definition of type curve +(deftype curve (structure) + ((cverts (inline-array vector)) + (num-cverts int32) + (knots (pointer float)) + (num-knots int32) + (length float) + ) + ) + +;; definition for method 3 of type curve +(defmethod inspect ((this curve)) + (when (not this) + (set! this this) + (goto cfg-4) + ) + (format #t "[~8x] ~A~%" this 'curve) + (format #t "~1Tcverts: #x~X~%" (-> this cverts)) + (format #t "~1Tnum-cverts: ~D~%" (-> this num-cverts)) + (format #t "~1Tknots: #x~X~%" (-> this knots)) + (format #t "~1Tnum-knots: ~D~%" (-> this num-knots)) + (format #t "~1Tlength: ~f~%" (-> this length)) + (label cfg-4) + this + ) + +;; definition of type line-intersection-val +(deftype line-intersection-val (structure) + ((tt0 float) + (tt1 float) + ) + ) + +;; definition for method 3 of type line-intersection-val +(defmethod inspect ((this line-intersection-val)) + (when (not this) + (set! this this) + (goto cfg-4) + ) + (format #t "[~8x] ~A~%" this 'line-intersection-val) + (format #t "~1Ttt0: ~f~%" (-> this tt0)) + (format #t "~1Ttt1: ~f~%" (-> this tt1)) + (label cfg-4) + this + ) + +;; definition of type border-plane +(deftype border-plane (basic) + ((name symbol) + (action basic) + (slot int8) + (trans vector :inline) + (normal vector :inline) + ) + (:methods + (debug-draw (_type_) int) + (point-past-plane? (_type_ vector) symbol) + ) + ) + +;; definition for method 3 of type border-plane +(defmethod inspect ((this border-plane)) + (when (not this) + (set! this this) + (goto cfg-4) + ) + (format #t "[~8x] ~A~%" this (-> this type)) + (format #t "~1Tname: ~A~%" (-> this name)) + (format #t "~1Taction: ~A~%" (-> this action)) + (format #t "~1Tslot: ~D~%" (-> this slot)) + (format #t "~1Ttrans: ~`vector`P~%" (-> this trans)) + (format #t "~1Tnormal: ~`vector`P~%" (-> this normal)) + (label cfg-4) + this + ) + +;; definition of type lissajous +(deftype lissajous (structure) + ((x-mag float) + (y-mag float) + (theta float) + (wx float) + (wy float) + (period-shift float) + (theta-rate float) + ) + :pack-me + (:methods + (lissajous-method-9 (_type_ vector) vector) + ) + ) + +;; definition for method 3 of type lissajous +(defmethod inspect ((this lissajous)) + (when (not this) + (set! this this) + (goto cfg-4) + ) + (format #t "[~8x] ~A~%" this 'lissajous) + (format #t "~1Tx-mag: ~f~%" (-> this x-mag)) + (format #t "~1Ty-mag: ~f~%" (-> this y-mag)) + (format #t "~1Ttheta: ~f~%" (-> this theta)) + (format #t "~1Twx: ~f~%" (-> this wx)) + (format #t "~1Twy: ~f~%" (-> this wy)) + (format #t "~1Tperiod-shift: ~f~%" (-> this period-shift)) + (format #t "~1Ttheta-rate: ~f~%" (-> this theta-rate)) + (label cfg-4) + this + ) + +;; definition of type lissajous-interp +(deftype lissajous-interp (structure) + ((current lissajous :inline) + (dest lissajous :inline) + (rate lissajous :inline) + ) + (:methods + (lissajous-interp-method-9 (_type_ vector) vector) + (lissajous-interp-method-10 (_type_) float) + ) + ) + +;; definition for method 3 of type lissajous-interp +(defmethod inspect ((this lissajous-interp)) + (when (not this) + (set! this this) + (goto cfg-4) + ) + (format #t "[~8x] ~A~%" this 'lissajous-interp) + (format #t "~1Tcurrent: #~%" (-> this current)) + (format #t "~1Tdest: #~%" (-> this dest)) + (format #t "~1Trate: #~%" (-> this rate)) + (label cfg-4) + this + ) + +;; failed to figure out what this is: +0 + + + + diff --git a/test/decompiler/reference/jak3/engine/math/euler-h_REF.gc b/test/decompiler/reference/jak3/engine/math/euler-h_REF.gc new file mode 100644 index 0000000000..96c946642d --- /dev/null +++ b/test/decompiler/reference/jak3/engine/math/euler-h_REF.gc @@ -0,0 +1,46 @@ +;;-*-Lisp-*- +(in-package goal) + +;; definition for symbol EulSafe, type (array int32) +(define EulSafe + "Maybe euler angle storage orders? +What is this naming convention?" + (new 'static 'boxed-array :type int32 0 1 2 0) + ) + +;; definition for symbol EulNext, type (array int32) +(define EulNext (new 'static 'boxed-array :type int32 1 2 0 1)) + +;; definition of type euler-angles +(deftype euler-angles (vector) + "Just uses the same xyzw and data array as vector. +The `w` stores an integer that seems to have +bitfields for... something? Like maybe the order? +Euler angles are mostly unused, and the code is a bit of disaster." + () + ) + +;; definition for method 3 of type euler-angles +;; INFO: Used lq/sq +(defmethod inspect ((this euler-angles)) + (when (not this) + (set! this this) + (goto cfg-4) + ) + (format #t "[~8x] ~A~%" this 'euler-angles) + (format #t "~1Tdata[4] @ #x~X~%" (&-> this x)) + (format #t "~1Tx: ~f~%" (-> this x)) + (format #t "~1Ty: ~f~%" (-> this y)) + (format #t "~1Tz: ~f~%" (-> this z)) + (format #t "~1Tw: ~f~%" (-> this w)) + (format #t "~1Tquad: ~D~%" (-> this quad)) + (label cfg-4) + this + ) + +;; failed to figure out what this is: +0 + + + + diff --git a/test/decompiler/reference/jak3/engine/math/euler_REF.gc b/test/decompiler/reference/jak3/engine/math/euler_REF.gc new file mode 100644 index 0000000000..efff8e2f11 --- /dev/null +++ b/test/decompiler/reference/jak3/engine/math/euler_REF.gc @@ -0,0 +1,219 @@ +;;-*-Lisp-*- +(in-package goal) + +;; definition for function set-eul! +(defun set-eul! ((arg0 euler-angles) (arg1 float) (arg2 float) (arg3 float) (arg4 int)) + "Set euler angles and the flag bits." + (set! (-> arg0 x) arg1) + (set! (-> arg0 y) arg2) + (set! (-> arg0 z) arg3) + (set! (-> arg0 w) (the float arg4)) + arg0 + ) + +;; definition for function eul->matrix +;; INFO: Used lq/sq +(defun eul->matrix ((arg0 matrix) (arg1 euler-angles)) + "Convert from euler angles to 4x4 matrix." + (matrix-identity! arg0) + (let ((s5-0 (new 'stack-no-clear 'vector))) + (set! (-> s5-0 quad) (-> arg1 quad)) + (when (= (logand (the int (-> s5-0 w)) 1) 1) + (let ((f0-2 (-> s5-0 x))) + (set! (-> s5-0 x) (-> s5-0 z)) + (set! (-> s5-0 z) f0-2) + ) + ) + (when (= (logand (/ (the int (-> s5-0 w)) 4) 1) 1) + (set! (-> s5-0 x) (- (-> s5-0 x))) + (set! (-> s5-0 y) (- (-> s5-0 y))) + (set! (-> s5-0 z) (- (-> s5-0 z))) + ) + (let* ((f26-0 (cos (-> s5-0 x))) + (f30-0 (cos (-> s5-0 y))) + (f22-0 (cos (-> s5-0 z))) + (f24-0 (sin (-> s5-0 x))) + (f28-0 (sin (-> s5-0 y))) + (f4-0 (sin (-> s5-0 z))) + (f0-17 (* f26-0 f22-0)) + (f1-1 (* f26-0 f4-0)) + (f2-0 (* f24-0 f22-0)) + (f3-0 (* f24-0 f4-0)) + ) + 0 + 0 + 0 + (let* ((v1-12 (logand (/ (the int (-> s5-0 w)) 4) 1)) + (a1-2 (-> EulSafe (logand (/ (the int (-> s5-0 w)) 8) 3))) + (a0-21 (-> EulNext (+ a1-2 v1-12))) + (v1-17 (-> EulNext (+ (- 1 v1-12) a1-2))) + ) + (cond + ((= (logand (/ (the int (-> s5-0 w)) 2) 1) 1) + (set! (-> (the-as (pointer float) (+ (+ (* a1-2 16) (* a1-2 4)) (the-as int arg0)))) f30-0) + (set! (-> (the-as (pointer float) (+ (+ (* a1-2 16) (* a0-21 4)) (the-as int arg0)))) (* f28-0 f24-0)) + (set! (-> (the-as (pointer float) (+ (+ (* a1-2 16) (* v1-17 4)) (the-as int arg0)))) (* f28-0 f26-0)) + (set! (-> (the-as (pointer float) (+ (+ (* a0-21 16) (* a1-2 4)) (the-as int arg0)))) (* f28-0 f4-0)) + (set! (-> (the-as (pointer float) (+ (+ (* a0-21 16) (* a0-21 4)) (the-as int arg0)))) + (- f0-17 (* f30-0 f3-0)) + ) + (set! (-> (the-as (pointer float) (+ (+ (* a0-21 16) (* v1-17 4)) (the-as int arg0)))) + (- (- f2-0) (* f30-0 f1-1)) + ) + (set! (-> (the-as (pointer float) (+ (+ (* v1-17 16) (* a1-2 4)) (the-as int arg0)))) (- (* f28-0 f22-0))) + (set! (-> (the-as (pointer float) (+ (+ (* v1-17 16) (* a0-21 4)) (the-as int arg0)))) + (+ f1-1 (* f30-0 f2-0)) + ) + (set! (-> (the-as (pointer float) (+ (+ (* v1-17 16) (* v1-17 4)) (the-as int arg0)))) + (+ (- f3-0) (* f30-0 f0-17)) + ) + ) + (else + (set! (-> (the-as (pointer float) (+ (+ (* a1-2 16) (* a1-2 4)) (the-as int arg0)))) (* f30-0 f22-0)) + (set! (-> (the-as (pointer float) (+ (+ (* a1-2 16) (* a0-21 4)) (the-as int arg0)))) + (+ (- f1-1) (* f28-0 f2-0)) + ) + (set! (-> (the-as (pointer float) (+ (+ (* a1-2 16) (* v1-17 4)) (the-as int arg0)))) + (+ f3-0 (* f28-0 f0-17)) + ) + (set! (-> (the-as (pointer float) (+ (+ (* a0-21 16) (* a1-2 4)) (the-as int arg0)))) (* f30-0 f4-0)) + (set! (-> (the-as (pointer float) (+ (+ (* a0-21 16) (* a0-21 4)) (the-as int arg0)))) + (+ f0-17 (* f28-0 f3-0)) + ) + (set! (-> (the-as (pointer float) (+ (+ (* a0-21 16) (* v1-17 4)) (the-as int arg0)))) + (+ (- f2-0) (* f28-0 f1-1)) + ) + (set! (-> (the-as (pointer float) (+ (+ (* v1-17 16) (* a1-2 4)) (the-as int arg0)))) (- f28-0)) + (set! (-> (the-as (pointer float) (+ (+ (* v1-17 16) (* a0-21 4)) (the-as int arg0)))) (* f30-0 f24-0)) + (set! (-> (the-as (pointer float) (+ (+ (* v1-17 16) (* v1-17 4)) (the-as int arg0)))) (* f30-0 f26-0)) + ) + ) + ) + ) + ) + arg0 + ) + +;; definition for function matrix->eul +(defun matrix->eul ((arg0 euler-angles) (arg1 matrix) (arg2 int)) + "Convert matrix to euler angles with given order flag. +Not clear how this works if the matrix has more than just a rotation." + 0 + 0 + 0 + (let* ((v1-4 (logand (/ arg2 4) 1)) + (s3-0 (-> EulSafe (logand (/ arg2 8) 3))) + (s2-0 (-> EulNext (+ s3-0 v1-4))) + (s1-0 (-> EulNext (+ (- 1 v1-4) s3-0))) + ) + (cond + ((= (logand (/ arg2 2) 1) 1) + (let* ((f0-0 (-> (the-as (pointer float) (+ (+ (* s2-0 4) (* s3-0 16)) (the-as int arg1))))) + (f0-2 (* f0-0 f0-0)) + (f1-0 (-> (the-as (pointer float) (+ (+ (* s1-0 4) (* s3-0 16)) (the-as int arg1))))) + (f30-0 (sqrtf (+ f0-2 (* f1-0 f1-0)))) + ) + (cond + ((< 0.00000000001 f30-0) + (set! (-> arg0 x) (atan + (-> (the-as (pointer float) (+ (+ (* s2-0 4) (* s3-0 16)) (the-as int arg1)))) + (-> (the-as (pointer float) (+ (+ (* s1-0 4) (* s3-0 16)) (the-as int arg1)))) + ) + ) + (set! (-> arg0 y) (atan f30-0 (-> (the-as (pointer float) (+ (+ (* s3-0 4) (* s3-0 16)) (the-as int arg1)))))) + (set! (-> arg0 z) (atan + (-> (the-as (pointer float) (+ (+ (* s3-0 4) (* s2-0 16)) (the-as int arg1)))) + (- (-> (the-as (pointer float) (+ (+ (* s3-0 4) (* s1-0 16)) (the-as int arg1))))) + ) + ) + ) + (else + (set! (-> arg0 x) (atan + (- (-> (the-as (pointer float) (+ (+ (* s1-0 4) (* s2-0 16)) (the-as int arg1))))) + (-> (the-as (pointer float) (+ (+ (* s2-0 4) (* s2-0 16)) (the-as int arg1)))) + ) + ) + (set! (-> arg0 y) (atan f30-0 (-> (the-as (pointer float) (+ (+ (* s3-0 4) (* s3-0 16)) (the-as int arg1)))))) + (set! (-> arg0 z) 0.0) + ) + ) + ) + ) + (else + (let* ((f0-21 (-> (the-as (pointer float) (+ (+ (* s3-0 4) (* s3-0 16)) (the-as int arg1))))) + (f0-23 (* f0-21 f0-21)) + (f1-3 (-> (the-as (pointer float) (+ (+ (* s3-0 4) (* s2-0 16)) (the-as int arg1))))) + (f30-1 (sqrtf (+ f0-23 (* f1-3 f1-3)))) + ) + (cond + ((< 0.00000000001 f30-1) + (set! (-> arg0 x) + (atan + (-> (the-as (pointer float) (+ (+ (* s2-0 4) (* s1-0 16)) (the-as int arg1)))) + (-> (the-as (pointer float) (+ (+ (* s1-0 4) (* s1-0 16)) (the-as int arg1)))) + ) + ) + (set! (-> arg0 y) + (atan (- (-> (the-as (pointer float) (+ (+ (* s3-0 4) (* s1-0 16)) (the-as int arg1))))) f30-1) + ) + (set! (-> arg0 z) (atan + (-> (the-as (pointer float) (+ (+ (* s3-0 4) (* s2-0 16)) (the-as int arg1)))) + (-> (the-as (pointer float) (+ (+ (* s3-0 4) (* s3-0 16)) (the-as int arg1)))) + ) + ) + ) + (else + (set! (-> arg0 x) + (atan + (- (-> (the-as (pointer float) (+ (+ (* s1-0 4) (* s2-0 16)) (the-as int arg1))))) + (-> (the-as (pointer float) (+ (+ (* s2-0 4) (* s2-0 16)) (the-as int arg1)))) + ) + ) + (set! (-> arg0 y) + (atan (- (-> (the-as (pointer float) (+ (+ (* s3-0 4) (* s1-0 16)) (the-as int arg1))))) f30-1) + ) + (set! (-> arg0 z) 0.0) + ) + ) + ) + ) + ) + ) + (when (= (logand (/ arg2 4) 1) 1) + (set! (-> arg0 x) (- (-> arg0 x))) + (set! (-> arg0 y) (- (-> arg0 y))) + (set! (-> arg0 z) (- (-> arg0 z))) + ) + (when (= (logand arg2 1) 1) + (let ((f0-49 (-> arg0 x))) + (set! (-> arg0 x) (-> arg0 z)) + (set! (-> arg0 z) f0-49) + ) + ) + (set! (-> arg0 w) (the float arg2)) + arg0 + ) + +;; definition for function eul->quat +(defun eul->quat ((arg0 quaternion) (arg1 euler-angles)) + "Convert euler angles to quaternion, not very efficient." + (let ((s5-0 (new 'stack-no-clear 'matrix))) + (eul->matrix s5-0 arg1) + (matrix->quaternion arg0 s5-0) + ) + arg0 + ) + +;; definition for function quat->eul +(defun quat->eul ((arg0 euler-angles) (arg1 quaternion) (arg2 int)) + "Convert quaternion to euler angles with given order, not very efficient." + (let ((s5-0 (new 'stack-no-clear 'matrix))) + (quaternion->matrix s5-0 arg1) + (matrix->eul arg0 s5-0 arg2) + ) + arg0 + ) + + + + diff --git a/test/decompiler/reference/jak3/engine/math/math_REF.gc b/test/decompiler/reference/jak3/engine/math/math_REF.gc new file mode 100644 index 0000000000..9db1fe7ae5 --- /dev/null +++ b/test/decompiler/reference/jak3/engine/math/math_REF.gc @@ -0,0 +1,771 @@ +;;-*-Lisp-*- +(in-package goal) + +;; definition for function truncate +(defun truncate ((arg0 float)) + "Round (toward zero) to an integer. +@param arg0 float to truncate" + (the float (the int arg0)) + ) + +;; definition for function round +(defun round ((arg0 float)) + "Round to the nearest integer" + (the float (the int (+ 0.5 arg0))) + ) + +;; definition for function floor +(defun floor ((arg0 float)) + "Round (down) to an integer" + (let ((f0-3 (the float (the int arg0)))) + (if (or (>= arg0 0.0) (= arg0 f0-3)) + f0-3 + (+ -1.0 f0-3) + ) + ) + ) + +;; definition for function ceil +(defun ceil ((arg0 float)) + "Round (up) to an integer" + (let ((f0-3 (the float (the int arg0)))) + (if (or (>= 0.0 arg0) (= arg0 f0-3)) + f0-3 + (+ 1.0 f0-3) + ) + ) + ) + +;; definition for function integral? +(defun integral? ((arg0 float)) + "Is this number an integer?" + (= (the float (the int arg0)) arg0) + ) + +;; definition for function fractional-part +(defun fractional-part ((arg0 float)) + "Get the fractional part of a float." + (- arg0 (the float (the int arg0))) + ) + +;; definition for function odd? +(defun odd? ((arg0 int)) + "Is the number odd?" + (= (logand arg0 1) 1) + ) + +;; definition for function even? +(defun even? ((arg0 int)) + "Is the number even?" + (not (odd? arg0)) + ) + +;; definition for function sawtooth-wave +(defun sawtooth-wave ((arg0 float)) + "Sample a sawtooth with period 1. In range (0, 1)" + (let ((f0-2 (- arg0 (the float (the int arg0))))) + (if (< f0-2 0.0) + (set! f0-2 (+ 1.0 f0-2)) + ) + f0-2 + ) + ) + +;; definition for function triangle-wave +(defun triangle-wave ((arg0 float)) + "Sample a triangle wave. Period is 4, in range (-1, 1) (so slope is 1 or -1)." + (let* ((f0-1 (* 0.25 (+ -1.0 arg0))) + (f0-3 (- f0-1 (the float (the int f0-1)))) + ) + (if (< f0-3 0.0) + (set! f0-3 (+ 1.0 f0-3)) + ) + (+ -1.0 (fabs (+ -2.0 (* 4.0 f0-3)))) + ) + ) + +;; definition for function log-x-plus-1-order9 +(defun log-x-plus-1-order9 ((arg0 float)) + "Fast approximation of ln(x + 1). Probably only accurate for x in [0, 1]." + (* arg0 + (+ 1.0 + (* arg0 + (+ -0.5 + (* arg0 + (+ 0.33333334 + (* arg0 + (+ -0.25 + (* arg0 (+ 0.2 (* arg0 (+ -0.16666666 (* arg0 (+ 0.14285715 (* arg0 (+ -0.125 (* 0.11111111 arg0))))))))) + ) + ) + ) + ) + ) + ) + ) + ) + ) + +;; definition for function logf +(defun logf ((arg0 float)) + "Natural log." + (let ((v1-1 (the-as int (+ (shr (the-as int arg0) 23) -126))) + (a0-2 (the-as number (logior #x3f000000 (logand (the-as uint #x807fffff) (the-as uint arg0))))) + ) + (when (< (the-as float (gpr->fpr (the-as int a0-2))) 0.70710677) + (set! a0-2 (+ (the-as float (gpr->fpr (the-as int a0-2))) (the-as float (gpr->fpr (the-as int a0-2))))) + (set! v1-1 (the-as int (+ (the-as uint v1-1) -1))) + ) + (let ((f0-5 (+ -1.0 (the-as float (gpr->fpr a0-2))))) + (+ (* f0-5 + (+ 1.0 + (* f0-5 + (+ -0.5 + (* f0-5 + (+ 0.33333334 + (* f0-5 + (+ -0.25 + (* f0-5 (+ 0.2 (* f0-5 (+ -0.16666666 (* f0-5 (+ 0.14285715 (* f0-5 (+ -0.125 (* 0.11111111 f0-5))))))))) + ) + ) + ) + ) + ) + ) + ) + ) + (* 0.6931472 (the float v1-1)) + ) + ) + ) + ) + +;; definition for function log2f +(defun log2f ((arg0 float)) + "Log base 2." + (let ((v1-1 (the-as int (+ (shr (the-as int arg0) 23) -126))) + (a0-2 (the-as number (logior #x3f000000 (logand (the-as uint #x807fffff) (the-as uint arg0))))) + ) + (when (< (the-as float (gpr->fpr (the-as int a0-2))) 0.70710677) + (set! a0-2 (+ (the-as float (gpr->fpr (the-as int a0-2))) (the-as float (gpr->fpr (the-as int a0-2))))) + (set! v1-1 (the-as int (+ (the-as uint v1-1) -1))) + ) + (let* ((f0-5 (+ -1.0 (the-as float (gpr->fpr a0-2)))) + (f0-7 + (* f0-5 + (+ 1.0 + (* f0-5 + (+ -0.5 + (* f0-5 + (+ 0.33333334 + (* f0-5 + (+ -0.25 + (* f0-5 (+ 0.2 (* f0-5 (+ -0.16666666 (* f0-5 (+ 0.14285715 (* f0-5 (+ -0.125 (* 0.11111111 f0-5))))))))) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + (+ (* 1.442695 f0-7) (the float v1-1)) + ) + ) + ) + +;; definition of type float-type +(deftype float-type (uint32) + () + ) + +;; definition for symbol exp-slead, type (pointer float) +(define exp-slead (new 'static 'array float 32 + 1.0 + 1.0218964 + 1.0442734 + 1.0671387 + 1.0905075 + 1.1143799 + 1.1387863 + 1.1637192 + 1.1892014 + 1.2152405 + 1.2418518 + 1.2690506 + 1.2968369 + 1.3252335 + 1.354248 + 1.3839035 + 1.4142075 + 1.4451752 + 1.4768219 + 1.5091629 + 1.5422058 + 1.5759735 + 1.6104889 + 1.645752 + 1.6817856 + 1.7186127 + 1.7562485 + 1.7947083 + 1.8340073 + 1.8741608 + 1.9151993 + 1.9571381 + ) + ) + +;; definition for symbol exp-strail, type (pointer float) +(define exp-strail (new 'static 'array float 32 + 0.0 + 0.0000007863494 + 0.00000040596257 + 0.0000017288019 + 0.00000022534104 + 0.0000068597833 + 0.0000023188388 + 0.0000056815315 + 0.0000057600223 + 0.0000068814647 + 0.000006005433 + 0.0000003590472 + 0.0000027016238 + 0.000003183687 + 0.000007500062 + 0.000006378546 + 0.000006103877 + 0.0000056360786 + 0.0000042465254 + 0.0000015247614 + 0.000005014861 + 0.000007334366 + 0.0000014403477 + 0.000003525029 + 0.000007247011 + 0.000006627224 + 0.0000036862523 + 0.00000082304996 + 0.0000008232258 + 0.0000068675085 + 0.000007281612 + 0.000006062652 + ) + ) + +;; definition for function exp +;; ERROR: function was not converted to expressions. Cannot decompile. + +;; definition for function pow +(defun pow ((arg0 float) (arg1 float)) + "Compute arg0^arg1" + (exp (* arg1 (logf arg0))) + ) + +;; definition for function print-exp +;; WARN: Return type mismatch int vs none. +(defun print-exp ((arg0 float)) + "Print in the format AeB where A is in the range (1, 10)" + (let* ((f30-1 (floor (/ (logf (fabs arg0)) (logf 10.0)))) + (f0-4 (pow 10.0 f30-1)) + ) + (format #t "~fe~d" (/ arg0 f0-4) (the int f30-1)) + ) + 0 + (none) + ) + +;; definition of type rgba +(deftype rgba (uint32) + () + ) + +;; definition of type xyzw +(deftype xyzw (uint128) + () + ) + +;; definition of type xyzwh +(deftype xyzwh (uint128) + () + ) + +;; definition for function print-time +;; WARN: Return type mismatch int vs none. +(defun print-time ((arg0 object) (arg1 time-frame)) + "Print a [[time-frame]] as h:mm:ss." + 0 + 0 + 0 + (let* ((f0-1 (* 0.0033333334 (the float arg1))) + (a2-0 (the int (* 0.016666668 f0-1))) + (f0-2 (- f0-1 (* 60.0 (the float a2-0)))) + (a3-0 (the int f0-2)) + (f0-3 (- f0-2 (the float a3-0))) + (t0-0 (the int (* 100.0 f0-3))) + ) + (format arg0 "~d:~2,'0,d:~2,'0,d" a2-0 a3-0 t0-0) + ) + 0 + (none) + ) + +;; definition for function log2 +;; WARN: Return type mismatch uint vs int. +(defun log2 ((arg0 int)) + "Log base 2." + (the-as int (+ (sar (the-as int (the float arg0)) 23) -127)) + ) + +;; definition for function seek +(defun seek ((arg0 float) (arg1 float) (arg2 float)) + "Move arg0 toward arg1 by at most arg2." + (let ((f2-0 (- arg1 arg0))) + (cond + ((>= arg2 (fabs f2-0)) + arg1 + ) + ((>= f2-0 0.0) + (+ arg0 arg2) + ) + (else + (- arg0 arg2) + ) + ) + ) + ) + +;; definition for function seek-ease +(defun seek-ease ((arg0 float) (arg1 float) (arg2 float) (arg3 float) (arg4 float)) + "Move arg0 toward arg1, and slow down before reaching the end. +When farther than arg3 away, move by at most arg2. +When closer than arg3, linearly ramp down the movement amount from arg2 to 0 but no lower than arg4." + (let ((f2-0 (- arg1 arg0))) + (when (>= arg3 (fabs f2-0)) + (set! arg2 (* arg2 (- 1.0 (/ (- arg3 (fabs f2-0)) arg3)))) + (if (< arg2 arg4) + (set! arg2 arg4) + ) + ) + (cond + ((>= arg2 (fabs f2-0)) + arg1 + ) + ((>= f2-0 0.0) + (+ arg0 arg2) + ) + (else + (- arg0 arg2) + ) + ) + ) + ) + +;; definition for function seek-ease-in-out +(defun seek-ease-in-out ((arg0 float) (arg1 float) (arg2 float) (arg3 float) (arg4 float) (arg5 float) (arg6 float)) + "Move arg0 toward arg2, and slow down at the start and end. +When within arg4 of arg1 (at the beginning of movement), ramp up speed, with a minimum speed of arg6 +When within arg5 of arg2 (at the end of movement), ramp down speed, with a minimum speed of arg5 +Normally, move at most arg3" + (let ((f2-0 (- arg2 arg0))) + (let ((f4-1 (- arg0 arg1))) + (when (>= arg4 (fabs f4-1)) + (set! arg3 (* arg3 (- 1.0 (/ (- arg4 (fabs f4-1)) arg4)))) + (if (< arg3 arg6) + (set! arg3 arg6) + ) + ) + ) + (when (>= arg5 (fabs f2-0)) + (set! arg3 (* arg3 (- 1.0 (/ (- arg5 (fabs f2-0)) arg5)))) + (if (< arg3 arg6) + (set! arg3 arg6) + ) + ) + (cond + ((>= arg3 (fabs f2-0)) + arg2 + ) + ((>= f2-0 0.0) + (+ arg0 arg3) + ) + (else + (- arg0 arg3) + ) + ) + ) + ) + +;; definition for function lerp +(defun lerp ((arg0 float) (arg1 float) (arg2 float)) + "Linearly interpolate between arg0 and arg1." + (+ arg0 (* arg2 (- arg1 arg0))) + ) + +;; definition (debug) for function lerp-scale-old +(defun-debug lerp-scale-old ((arg0 float) (arg1 float) (arg2 float) (arg3 float) (arg4 float)) + "Linearly remap arg2 in [arg3, arg4] to [arg0, arg1]. +This is the jak 1 implementation, which I claimed was a bad implementation..." + (let ((f0-1 (fmax 0.0 (fmin 1.0 (/ (- arg2 arg3) (- arg4 arg3)))))) + (+ (* (- 1.0 f0-1) arg0) (* f0-1 arg1)) + ) + ) + +;; definition for function lerp-scale +;; ERROR: Unsupported inline assembly instruction kind - [mula.s f0, f2] +;; ERROR: Unsupported inline assembly instruction kind - [madd.s f0, f1, f3] +(defun lerp-scale ((arg0 float) (arg1 float) (arg2 float) (arg3 float) (arg4 float)) + "Linearly remap arg2 in [arg3, arg4] to [arg0, arg1]. +More efficient than the -old version." + (local-vars (f0-2 float)) + (let* ((v1-0 1.0) + (f1-0 0.0) + (f0-0 v1-0) + (f4-0 arg2) + (f2-0 arg3) + (f3-0 arg4) + (f1-2 (fmin (fmax (/ (- f4-0 f2-0) (- f3-0 f2-0)) f1-0) f0-0)) + (f0-1 (- f0-0 f1-2)) + (f2-3 arg0) + (f3-1 arg1) + ) + (.mula.s f0-1 f2-3) + (.madd.s f0-2 f1-2 f3-1) + ) + f0-2 + ) + +;; definition for function lerp-scale-clamp +(defun lerp-scale-clamp ((arg0 float) (arg1 float) (arg2 float) (arg3 float) (arg4 float)) + "Clamp the input, then linearly remap arg2 in [arg3, arg4] to [arg0, arg1]." + (let ((a2-1 (fmax (fmin arg2 arg4) arg3))) + (lerp-scale arg0 arg1 a2-1 arg3 arg4) + ) + ) + +;; definition for function lerp-clamp +(defun lerp-clamp ((arg0 float) (arg1 float) (arg2 float)) + "Linearly interpolate between arg0 and arg1. arg2 is clamped to [0, 1]" + (cond + ((>= 0.0 arg2) + arg0 + ) + ((>= arg2 1.0) + arg1 + ) + (else + (+ (* (- 1.0 arg2) arg0) (* arg2 arg1)) + ) + ) + ) + +;; definition for function rgba-lerp +;; WARN: Return type mismatch int vs rgba. +(defun rgba-lerp ((arg0 rgba) (arg1 rgba) (arg2 rgba)) + (local-vars + (v0-0 uint128) + (v1-0 uint128) + (v1-1 uint128) + (a0-1 uint128) + (a0-2 uint128) + (a1-1 uint128) + (a2-1 uint128) + ) + (rlet ((acc :class vf) + (vf0 :class vf) + (vf1 :class vf) + (vf2 :class vf) + (vf3 :class vf) + ) + (init-vf0-vector) + (.pextlb v1-0 0 arg0) + (.pextlb a0-1 0 arg1) + (.pextlh v1-1 0 v1-0) + (.pextlh a0-2 0 a0-1) + (.mov vf1 v1-1) + (.mov vf2 a0-2) + (.mov vf3 arg2) + (.itof.vf vf1 vf1) + (.itof.vf vf2 vf2) + (.mul.w.vf acc vf1 vf0) + (.add.mul.x.vf acc vf2 vf3 acc) + (.sub.mul.x.vf vf1 vf1 vf3 acc) + (.ftoi.vf vf3 vf1) + (.mov a1-1 vf3) + (.ppach a2-1 (the-as uint128 0) a1-1) + (.ppacb v0-0 (the-as uint128 0) a2-1) + (the-as rgba v0-0) + ) + ) + +;; definition for function seekl +(defun seekl ((arg0 int) (arg1 int) (arg2 int)) + "Move arg0 toward arg1, by at most arg2." + (let* ((v1-0 (- arg1 arg0)) + (a3-0 (abs v1-0)) + ) + (cond + ((>= arg2 a3-0) + arg1 + ) + ((>= v1-0 0) + (+ arg0 arg2) + ) + (else + (- arg0 arg2) + ) + ) + ) + ) + +;; definition for function rand-vu-init +;; WARN: Return type mismatch int vs float. +;; ERROR: Unsupported inline assembly instruction kind - [ctc2.i vi_R, a0] +;; ERROR: Unsupported inline assembly instruction kind - [cfc2.i v0, vi_R] +(defun rand-vu-init ((arg0 float)) + "Initialize the VU0 random generator." + (local-vars (v0-0 int)) + (.ctc2.i vi_R arg0) + (.cfc2.i v0-0 vi_R) + (the-as float v0-0) + ) + +;; failed to figure out what this is: +(rand-vu-init 1.418091) + +;; definition for function rand-vu +;; ERROR: Inline assembly instruction marked with TODO - [TODO.VRGET] +;; ERROR: Inline assembly instruction marked with TODO - [TODO.VRXOR] +;; ERROR: Inline assembly instruction marked with TODO - [TODO.VRNEXT] +(defun rand-vu () + "Get a random number in [0, 1) and advance the random generator." + (local-vars (v0-0 float)) + (rlet ((Q :class vf) + (vf0 :class vf) + (vf1 :class vf) + (vf2 :class vf) + ) + (init-vf0-vector) + (TODO.VRGET vf1) + (.sqrt.vf Q vf1 :ftf #b0) + (.add.vf vf2 vf0 Q :mask #b1) + (TODO.VRXOR vf2) + (TODO.VRNEXT vf1) + (.sub.w.vf vf1 vf1 vf0) + (.mov v0-0 vf1) + v0-0 + ) + ) + +;; definition for function rand-vu-nostep +;; ERROR: Inline assembly instruction marked with TODO - [TODO.VRGET] +(defun rand-vu-nostep () + "Get the number currently in the random generator. +This will be equal to the last call of (rand-vu). +This will not update the random generator." + (local-vars (v0-0 float)) + (rlet ((vf0 :class vf) + (vf1 :class vf) + ) + (init-vf0-vector) + (TODO.VRGET vf1) + (.sub.w.vf vf1 vf1 vf0) + (.mov v0-0 vf1) + v0-0 + ) + ) + +;; definition for function rand-vu-float-range +(defun rand-vu-float-range ((arg0 float) (arg1 float)) + "Get a random float in between arg0 and arg1." + (+ arg0 (* (rand-vu) (- arg1 arg0))) + ) + +;; definition for function rand-vu-percent? +(defun rand-vu-percent? ((arg0 float)) + "Get a boolean that's true with the given probability (in 0, 1)." + (>= arg0 (rand-vu)) + ) + +;; definition for function rand-vu-int-range +(defun rand-vu-int-range ((arg0 int) (arg1 int)) + "Get an integer in the given range (inclusive)." + (if (< arg0 arg1) + (set! arg1 (+ arg1 1)) + (set! arg0 (+ arg0 1)) + ) + (let ((f0-4 (rand-vu-float-range (the float arg0) (the float arg1)))) + (if (< f0-4 0.0) + (set! f0-4 (+ -1.0 f0-4)) + ) + (the int f0-4) + ) + ) + +;; definition for function rand-vu-int-count +(defun rand-vu-int-count ((arg0 int)) + "Get an integer in the range [0, max)." + (the int (* (rand-vu) (the float arg0))) + ) + +;; definition for function rand-vu-int-count-excluding +;; WARN: new jak 2 until loop case, check carefully +(defun rand-vu-int-count-excluding ((arg0 int) (arg1 int)) + "Get an integer in the range [0, arg0). +If bit n is set in arg1, exclude this value from being returned." + (let ((s4-0 0) + (s5-0 0) + ) + (let ((v1-0 1)) + (while (nonzero? arg0) + (+! arg0 -1) + (if (not (logtest? arg1 v1-0)) + (+! s4-0 1) + ) + (set! v1-0 (* v1-0 2)) + ) + ) + (when (> s4-0 0) + (let ((v1-4 (the int (* (rand-vu) (the float s4-0)))) + (a0-1 1) + ) + (until #f + (while (logtest? arg1 a0-1) + (nop!) + (nop!) + (+! s5-0 1) + (set! a0-1 (* a0-1 2)) + ) + (if (zero? v1-4) + (goto cfg-14) + ) + (+! v1-4 -1) + (+! s5-0 1) + (set! a0-1 (* a0-1 2)) + ) + ) + #f + ) + (label cfg-14) + s5-0 + ) + ) + +;; definition for function rand-vu-int-range-exclude +;; WARN: new jak 2 until loop case, check carefully +(defun rand-vu-int-range-exclude ((arg0 int) (arg1 int) (arg2 int)) + "Get an integer in the range [0, arg0), excluding arg2. +Note that this doesn't use bits like rand-vu-int-count-excluding." + (until #f + (let ((v1-0 (rand-vu-int-range arg0 arg1))) + (if (!= v1-0 arg2) + (return v1-0) + ) + ) + ) + (the-as int #f) + ) + +;; definition of type random-generator +(deftype random-generator (basic) + ((seed uint32) + ) + ) + +;; definition for method 3 of type random-generator +(defmethod inspect ((this random-generator)) + (when (not this) + (set! this this) + (goto cfg-4) + ) + (format #t "[~8x] ~A~%" this (-> this type)) + (format #t "~1Tseed: ~D~%" (-> this seed)) + (label cfg-4) + this + ) + +;; definition for symbol *random-generator*, type random-generator +(define *random-generator* (new 'global 'random-generator)) + +;; failed to figure out what this is: +(set! (-> *random-generator* seed) (the-as uint #x666edd1e)) + +;; definition for function rand-uint31-gen +;; ERROR: function was not converted to expressions. Cannot decompile. + +;; definition for function cube-root +(defun cube-root ((arg0 float)) + "Cube root with cool trick that I don't understand." + (cond + ((!= arg0 0.0) + (let* ((v1-0 arg0) + (a1-2 (+ (logand (shr (the-as int v1-0) 23) 255) -127)) + (f0-1 + (the-as + number + (gpr->fpr + (logior (logand (the-as uint #x807fffff) (the-as uint v1-0)) (shl (+ (/ (the-as int a1-2) 3) 127) 23)) + ) + ) + ) + ) + (dotimes (v1-3 6) + (set! f0-1 (- (the-as float f0-1) + (/ (- (* (the-as float (* (the-as float f0-1) (the-as float f0-1))) (the-as float f0-1)) arg0) + (* 3.0 (the-as float f0-1) (the-as float f0-1)) + ) + ) + ) + ) + (the-as float f0-1) + ) + ) + (else + 0.0 + ) + ) + ) + +;; definition for function int-noise +(defun int-noise ((arg0 int)) + "Generate random-ish floats in range -1, 1." + (let ((v1-1 (logxor (shl arg0 13) arg0))) + (- 1.0 (* 0.0000000009313226 + (the float (logand #x7fffffff (+ #x5208dd0d (* v1-1 (+ #xc0ae5 (* (* #x3d73 v1-1) v1-1)))))) + ) + ) + ) + ) + +;; definition for function smooth-step +(defun smooth-step ((arg0 float)) + "Interpolate between 0, 1 with a cubic polynomial. +These are picked so f(0) = 0, f(1) = 1, f'(0) = f'(1) = 0." + (cond + ((>= 0.0 arg0) + 0.0 + ) + ((>= arg0 1.0) + 1.0 + ) + (else + (* arg0 arg0 (+ 3.0 (* -2.0 arg0))) + ) + ) + ) + +;; definition for function smooth-interp +(defun smooth-interp ((arg0 float) (arg1 float) (arg2 float) (arg3 float) (arg4 float)) + "Remap arg2 from (arg3, arg4) to (arg0, arg1), using cubic interpolation. +Satisfies: +- f(arg3) = arg0 +- f(arg4) = arg1 +- f'(arg3) = f'(arg4) = 0" + (+ arg0 (* (- arg1 arg0) (smooth-step (/ (- arg2 arg3) (- arg4 arg3))))) + ) + + + + diff --git a/test/decompiler/reference/jak3/engine/math/matrix-compose_REF.gc b/test/decompiler/reference/jak3/engine/math/matrix-compose_REF.gc new file mode 100644 index 0000000000..1d5ae3aeb3 --- /dev/null +++ b/test/decompiler/reference/jak3/engine/math/matrix-compose_REF.gc @@ -0,0 +1,132 @@ +;;-*-Lisp-*- +(in-package goal) + +;; definition for function matrix-fur-compose +;; INFO: Used lq/sq +(defun matrix-fur-compose ((arg0 matrix) (arg1 vector) (arg2 vector) (arg3 vector)) + (set! (-> arg0 rvec quad) (-> arg3 quad)) + (set! (-> arg0 uvec quad) (-> arg2 quad)) + (set! (-> arg0 fvec quad) (-> arg1 quad)) + arg0 + ) + +;; definition for function matrix-fu-compose +;; INFO: Used lq/sq +(defun matrix-fu-compose ((arg0 matrix) (arg1 vector) (arg2 vector) (arg3 vector)) + (set! (-> arg0 fvec quad) (-> arg1 quad)) + (set! (-> arg0 uvec quad) (-> arg2 quad)) + (vector-cross! (-> arg0 rvec) arg2 arg1) + arg0 + ) + +;; definition for function matrix-fr-compose +;; INFO: Used lq/sq +(defun matrix-fr-compose ((arg0 matrix) (arg1 vector) (arg2 vector) (arg3 vector)) + (set! (-> arg0 fvec quad) (-> arg1 quad)) + (set! (-> arg0 rvec quad) (-> arg2 quad)) + (vector-cross! (-> arg0 uvec) arg1 arg2) + arg0 + ) + +;; definition for function matrix-ur-compose +;; INFO: Used lq/sq +(defun matrix-ur-compose ((arg0 matrix) (arg1 vector) (arg2 vector) (arg3 vector)) + (set! (-> arg0 rvec quad) (-> arg2 quad)) + (set! (-> arg0 uvec quad) (-> arg1 quad)) + (vector-cross! (-> arg0 fvec) arg1 arg2) + arg0 + ) + +;; definition for function matrix-f-u-compose +;; INFO: Used lq/sq +(defun matrix-f-u-compose ((arg0 matrix) (arg1 vector) (arg2 vector) (arg3 vector)) + (set! (-> arg0 fvec quad) (-> arg1 quad)) + (vector-cross! (-> arg0 rvec) arg2 arg1) + (vector-normalize! (-> arg0 rvec) 1.0) + (vector-cross! (-> arg0 uvec) arg1 (-> arg0 rvec)) + arg0 + ) + +;; definition for function matrix-f-r-compose +;; INFO: Used lq/sq +(defun matrix-f-r-compose ((arg0 matrix) (arg1 vector) (arg2 vector) (arg3 vector)) + (set! (-> arg0 fvec quad) (-> arg1 quad)) + (vector-cross! (-> arg0 uvec) arg1 arg2) + (vector-normalize! (-> arg0 uvec) 1.0) + (vector-cross! (-> arg0 rvec) (-> arg0 uvec) arg1) + arg0 + ) + +;; definition for function matrix-u-f-compose +;; INFO: Used lq/sq +(defun matrix-u-f-compose ((arg0 matrix) (arg1 vector) (arg2 vector) (arg3 vector)) + (set! (-> arg0 uvec quad) (-> arg1 quad)) + (vector-cross! (-> arg0 rvec) arg1 arg2) + (vector-normalize! (-> arg0 rvec) 1.0) + (vector-cross! (-> arg0 fvec) (-> arg0 rvec) arg1) + arg0 + ) + +;; definition for function matrix-u-r-compose +;; INFO: Used lq/sq +(defun matrix-u-r-compose ((arg0 matrix) (arg1 vector) (arg2 vector) (arg3 vector)) + (set! (-> arg0 uvec quad) (-> arg1 quad)) + (vector-cross! (-> arg0 fvec) arg2 arg1) + (vector-normalize! (-> arg0 fvec) 1.0) + (vector-cross! (-> arg0 rvec) arg1 (-> arg0 fvec)) + arg0 + ) + +;; definition for function matrix-r-f-compose +;; INFO: Used lq/sq +(defun matrix-r-f-compose ((arg0 matrix) (arg1 vector) (arg2 vector) (arg3 vector)) + (set! (-> arg0 rvec quad) (-> arg1 quad)) + (vector-cross! (-> arg0 uvec) arg2 arg1) + (vector-normalize! (-> arg0 uvec) 1.0) + (vector-cross! (-> arg0 fvec) arg1 (-> arg0 uvec)) + arg0 + ) + +;; definition for function matrix-r-u-compose +;; INFO: Used lq/sq +(defun matrix-r-u-compose ((arg0 matrix) (arg1 vector) (arg2 vector) (arg3 vector)) + (set! (-> arg0 rvec quad) (-> arg1 quad)) + (vector-cross! (-> arg0 fvec) arg1 arg2) + (vector-normalize! (-> arg0 fvec) 1.0) + (vector-cross! (-> arg0 uvec) (-> arg0 fvec) arg1) + arg0 + ) + +;; definition for function matrix-f-compose +;; INFO: Used lq/sq +(defun matrix-f-compose ((arg0 matrix) (arg1 vector) (arg2 vector) (arg3 vector)) + (set! (-> arg0 fvec quad) (-> arg1 quad)) + (let ((a2-1 (vector-get-unique! (new 'stack-no-clear 'vector) arg1))) + (matrix-f-u-compose arg0 arg1 a2-1 arg3) + ) + arg0 + ) + +;; definition for function matrix-u-compose +;; INFO: Used lq/sq +(defun matrix-u-compose ((arg0 matrix) (arg1 vector) (arg2 vector) (arg3 vector)) + (set! (-> arg0 uvec quad) (-> arg1 quad)) + (let ((a2-1 (vector-get-unique! (new 'stack-no-clear 'vector) arg1))) + (matrix-u-f-compose arg0 arg1 a2-1 arg3) + ) + arg0 + ) + +;; definition for function matrix-r-compose +;; INFO: Used lq/sq +(defun matrix-r-compose ((arg0 matrix) (arg1 vector) (arg2 vector) (arg3 vector)) + (set! (-> arg0 rvec quad) (-> arg1 quad)) + (let ((a2-1 (vector-get-unique! (new 'stack-no-clear 'vector) arg1))) + (matrix-r-f-compose arg0 arg1 a2-1 arg3) + ) + arg0 + ) + + + + diff --git a/test/decompiler/reference/jak3/engine/math/matrix-h_REF.gc b/test/decompiler/reference/jak3/engine/math/matrix-h_REF.gc new file mode 100644 index 0000000000..7dbc7ece49 --- /dev/null +++ b/test/decompiler/reference/jak3/engine/math/matrix-h_REF.gc @@ -0,0 +1,151 @@ +;;-*-Lisp-*- +(in-package goal) + +;; definition of type matrix +(deftype matrix (structure) + "A 4x4 matrix, stored in row-major order. +some, but not all, functions assume that a matrix is an affine transform. +others assume that the rotation has no scale or shear (and that its inverse is its transpose)." + ((data float 16) + (vector vector 4 :overlay-at (-> data 0)) + (quad uint128 4 :overlay-at (-> data 0)) + (rvec vector :inline :overlay-at (-> data 0)) + (uvec vector :inline :overlay-at (-> data 4)) + (fvec vector :inline :overlay-at (-> data 8)) + (trans vector :inline :overlay-at (-> data 12)) + ) + (:methods + (transform-vectors! (_type_ (inline-array vector) (inline-array vector) int) none) + ) + ) + +;; definition for method 3 of type matrix +(defmethod inspect ((this matrix)) + (when (not this) + (set! this this) + (goto cfg-4) + ) + (format #t "[~8x] ~A~%" this 'matrix) + (format #t "~1Tdata[16] @ #x~X~%" (-> this rvec)) + (format #t "~1Tvector[4] @ #x~X~%" (-> this rvec)) + (format #t "~1Tquad[4] @ #x~X~%" (-> this rvec)) + (format #t "~1Trvec: #~%" (-> this rvec)) + (format #t "~1Tuvec: #~%" (-> this uvec)) + (format #t "~1Tfvec: #~%" (-> this fvec)) + (format #t "~1Ttrans: #~%" (-> this trans)) + (label cfg-4) + this + ) + +;; definition of type matrix3 +(deftype matrix3 (structure) + "A 3x3 matrix, stored in row-major order. +NOTE: the rows each have an extra 4-bytes of padding, +so this is really a 3x4 matrix. +This type is rarely used." + ((data float 12) + (vector vector 3 :inline :overlay-at (-> data 0)) + (quad uint128 3 :overlay-at (-> data 0)) + ) + ) + +;; definition for method 3 of type matrix3 +(defmethod inspect ((this matrix3)) + (when (not this) + (set! this this) + (goto cfg-4) + ) + (format #t "[~8x] ~A~%" this 'matrix3) + (format #t "~1Tdata[12] @ #x~X~%" (-> this vector)) + (format #t "~1Tvector[3] @ #x~X~%" (-> this vector)) + (format #t "~1Tquad[3] @ #x~X~%" (-> this vector)) + (label cfg-4) + this + ) + +;; definition of type matrix4h +(deftype matrix4h (structure) + "A matrix stored using 16-bit integers. +Note that these usually have different scaling for the 4th row which +contains the translation in an affine transform. +So you generally should not unpack these to floats without knowing where they came from +and how they were originally packed (for example, in tie/shrub)." + ((data int16 16) + (vector4h vector4h 4 :overlay-at (-> data 0)) + (long int64 4 :overlay-at (-> data 0)) + ) + ) + +;; definition for method 3 of type matrix4h +(defmethod inspect ((this matrix4h)) + (when (not this) + (set! this this) + (goto cfg-4) + ) + (format #t "[~8x] ~A~%" this 'matrix4h) + (format #t "~1Tdata[16] @ #x~X~%" (-> this vector4h)) + (format #t "~1Tvector4h[4] @ #x~X~%" (-> this vector4h)) + (format #t "~1Tlong[4] @ #x~X~%" (-> this vector4h)) + (label cfg-4) + this + ) + +;; definition for function matrix-copy! +;; INFO: Used lq/sq +(defun matrix-copy! ((arg0 matrix) (arg1 matrix)) + "Copy arg1 to arg0" + (let ((v1-0 (-> arg1 rvec quad)) + (a2-0 (-> arg1 uvec quad)) + (a3-0 (-> arg1 fvec quad)) + (a1-1 (-> arg1 trans quad)) + ) + (set! (-> arg0 rvec quad) v1-0) + (set! (-> arg0 uvec quad) a2-0) + (set! (-> arg0 fvec quad) a3-0) + (set! (-> arg0 trans quad) a1-1) + ) + arg0 + ) + +;; definition for function matrix<-vector-yz-exact! +;; INFO: Used lq/sq +(defun matrix<-vector-yz-exact! ((arg0 matrix) (arg1 vector) (arg2 vector)) + (set! (-> arg0 fvec quad) (-> arg1 quad)) + (set! (-> arg0 uvec quad) (-> arg2 quad)) + (vector-cross! (-> arg0 rvec) (-> arg0 uvec) arg1) + arg0 + ) + +;; definition for function matrix<-vector-yz! +;; INFO: Used lq/sq +(defun matrix<-vector-yz! ((arg0 matrix) (arg1 vector) (arg2 vector)) + (set! (-> arg0 fvec quad) (-> arg1 quad)) + (vector-cross! (-> arg0 rvec) arg2 arg1) + (vector-normalize! (-> arg0 rvec) 1.0) + (vector-cross! (-> arg0 uvec) arg1 (-> arg0 rvec)) + (set! (-> arg0 rvec w) 1.0) + (set! (-> arg0 uvec w) 1.0) + (set! (-> arg0 fvec w) 1.0) + arg0 + ) + +;; definition for function matrix<-vector-z! +;; INFO: Used lq/sq +(defun matrix<-vector-z! ((arg0 matrix) (arg1 vector)) + (let* ((s3-0 (new 'stack-no-clear 'vector)) + (v1-0 (vector-get-closest-perpendicular! s3-0 arg1 (vector-get-unique! (new 'stack-no-clear 'vector) arg1))) + (s4-1 arg0) + ) + (set! (-> s4-1 fvec quad) (-> arg1 quad)) + (set! (-> s4-1 uvec quad) (-> v1-0 quad)) + (vector-cross! (-> s4-1 rvec) (-> s4-1 uvec) arg1) + ) + arg0 + ) + +;; failed to figure out what this is: +0 + + + + diff --git a/test/decompiler/reference/jak3/engine/math/matrix_REF.gc b/test/decompiler/reference/jak3/engine/math/matrix_REF.gc new file mode 100644 index 0000000000..8567e44c0c --- /dev/null +++ b/test/decompiler/reference/jak3/engine/math/matrix_REF.gc @@ -0,0 +1,1907 @@ +;;-*-Lisp-*- +(in-package goal) + +;; definition for method 3 of type matrix +(defmethod inspect ((this matrix)) + (format #t "[~8x] matrix~%" this) + (format #t "~T[~F] [~F] [~F] [~F]~%" (-> this rvec x) (-> this rvec y) (-> this rvec z) (-> this rvec w)) + (format #t "~T[~F] [~F] [~F] [~F]~%" (-> this uvec x) (-> this uvec y) (-> this uvec z) (-> this uvec w)) + (format #t "~T[~F] [~F] [~F] [~F]~%" (-> this fvec x) (-> this fvec y) (-> this fvec z) (-> this fvec w)) + (format #t "~T[~F] [~F] [~F] [~F]~%" (-> this trans x) (-> this trans y) (-> this trans z) (-> this trans w)) + this + ) + +;; definition for method 3 of type matrix3 +(defmethod inspect ((this matrix3)) + (format #t "[~8x] matrix3~%" this) + (format #t "~T[~F] [~F] [~F]~%" (-> this vector 0 x) (-> this vector 0 y) (-> this vector 0 z)) + (format #t "~T[~F] [~F] [~F]~%" (-> this vector 1 x) (-> this vector 1 y) (-> this vector 1 z)) + (format #t "~T[~F] [~F] [~F]~%" (-> this vector 2 x) (-> this vector 2 y) (-> this vector 2 z)) + this + ) + +;; definition for function matrix-identity! +;; INFO: Used lq/sq +(defun matrix-identity! ((arg0 matrix)) + "Set dst to the identity matrix." + (set! (-> arg0 rvec quad) (the-as uint128 0)) + (set! (-> arg0 uvec quad) (the-as uint128 0)) + (set! (-> arg0 fvec quad) (the-as uint128 0)) + (set! (-> arg0 trans quad) (the-as uint128 0)) + (let ((f0-0 1.0)) + (set! (-> arg0 trans w) f0-0) + (set! (-> arg0 fvec z) f0-0) + (set! (-> arg0 uvec y) f0-0) + (set! (-> arg0 rvec x) f0-0) + ) + arg0 + ) + +;; definition for symbol *identity-matrix*, type matrix +(define *identity-matrix* (matrix-identity! (new 'global 'matrix))) + +;; definition for symbol *hermite-matrix*, type matrix +(define *hermite-matrix* (new 'static 'matrix + :rvec (new 'static 'vector :x 2.0 :y -2.0 :z 1.0 :w 1.0) + :uvec (new 'static 'vector :x -3.0 :y 3.0 :z -2.0 :w -1.0) + :fvec (new 'static 'vector :z 1.0) + :trans (new 'static 'vector :x 1.0) + ) + ) + +;; definition for function matrix+! +(defun matrix+! ((arg0 matrix) (arg1 matrix) (arg2 matrix)) + "Set dst = src1 + src2. It is okay for any arguments to be the same data. +This is not an efficient implementation." + (dotimes (v1-0 16) + (set! (-> arg0 rvec data v1-0) (+ (-> arg1 rvec data v1-0) (-> arg2 rvec data v1-0))) + ) + arg0 + ) + +;; definition for function matrix-! +(defun matrix-! ((arg0 matrix) (arg1 matrix) (arg2 matrix)) + "Set dst = src1 - src1. It is okay for any arugments to be the same data. +This is not an efficient implementation." + (dotimes (v1-0 16) + (set! (-> arg0 rvec data v1-0) (- (-> arg1 rvec data v1-0) (-> arg2 rvec data v1-0))) + ) + arg0 + ) + +;; definition for function matrix*! +(defun matrix*! ((arg0 matrix) (arg1 matrix) (arg2 matrix)) + "Set dst = src1 * src2. It is okay for any arguments to be the same data. +This is a moderately efficient implementation." + (rlet ((acc :class vf) + (vf10 :class vf) + (vf11 :class vf) + (vf12 :class vf) + (vf13 :class vf) + (vf14 :class vf) + (vf15 :class vf) + (vf16 :class vf) + (vf17 :class vf) + (vf18 :class vf) + (vf19 :class vf) + (vf20 :class vf) + (vf21 :class vf) + ) + (.lvf vf10 (&-> arg1 rvec quad)) + (.lvf vf14 (&-> arg2 rvec quad)) + (.lvf vf15 (&-> arg2 uvec quad)) + (.lvf vf16 (&-> arg2 fvec quad)) + (.lvf vf17 (&-> arg2 trans quad)) + (.lvf vf11 (&-> arg1 uvec quad)) + (.lvf vf12 (&-> arg1 fvec quad)) + (.lvf vf13 (&-> arg1 trans quad)) + (.mul.x.vf acc vf14 vf10) + (.add.mul.y.vf acc vf15 vf10 acc) + (.add.mul.z.vf acc vf16 vf10 acc) + (.add.mul.w.vf vf18 vf17 vf10 acc) + (.mul.x.vf acc vf14 vf11) + (.add.mul.y.vf acc vf15 vf11 acc) + (.add.mul.z.vf acc vf16 vf11 acc) + (.add.mul.w.vf vf19 vf17 vf11 acc) + (.mul.x.vf acc vf14 vf12) + (.add.mul.y.vf acc vf15 vf12 acc) + (.add.mul.z.vf acc vf16 vf12 acc) + (.add.mul.w.vf vf20 vf17 vf12 acc) + (.mul.x.vf acc vf14 vf13) + (.add.mul.y.vf acc vf15 vf13 acc) + (.add.mul.z.vf acc vf16 vf13 acc) + (.add.mul.w.vf vf21 vf17 vf13 acc) + (.svf (&-> arg0 rvec quad) vf18) + (.svf (&-> arg0 uvec quad) vf19) + (.svf (&-> arg0 fvec quad) vf20) + (.svf (&-> arg0 trans quad) vf21) + arg0 + ) + ) + +;; definition for function matrixp*! +;; INFO: Used lq/sq +(defun matrixp*! ((arg0 matrix) (arg1 matrix) (arg2 matrix)) + "Set dst = src1 * src2. NOTE: this function is a wrapper around matrix*! +that adds no additional functionality. It seems to be a leftover from +a time when matrix*! wasn't safe to use in place. This is unused." + (let ((s5-0 (new 'stack-no-clear 'matrix))) + (set! (-> s5-0 rvec quad) (the-as uint128 0)) + (set! (-> s5-0 uvec quad) (the-as uint128 0)) + (set! (-> s5-0 fvec quad) (the-as uint128 0)) + (set! (-> s5-0 trans quad) (the-as uint128 0)) + (matrix*! s5-0 arg1 arg2) + (set! (-> arg0 rvec quad) (-> s5-0 rvec quad)) + (set! (-> arg0 uvec quad) (-> s5-0 uvec quad)) + (set! (-> arg0 fvec quad) (-> s5-0 fvec quad)) + (set! (-> arg0 trans quad) (-> s5-0 trans quad)) + ) + arg0 + ) + +;; definition for function vector-matrix*! +(defun vector-matrix*! ((arg0 vector) (arg1 vector) (arg2 matrix)) + "Set dst = vec * mat. dst may be equal to src." + (rlet ((acc :class vf) + (vf1 :class vf) + (vf2 :class vf) + (vf3 :class vf) + (vf4 :class vf) + (vf5 :class vf) + ) + (.lvf vf1 (&-> arg2 rvec quad)) + (.lvf vf2 (&-> arg2 uvec quad)) + (.lvf vf3 (&-> arg2 fvec quad)) + (.lvf vf4 (&-> arg2 trans quad)) + (.lvf vf5 (&-> arg1 quad)) + (.mul.x.vf acc vf1 vf5) + (.add.mul.y.vf acc vf2 vf5 acc) + (.add.mul.z.vf acc vf3 vf5 acc) + (.add.mul.w.vf vf5 vf4 vf5 acc) + (.svf (&-> arg0 quad) vf5) + arg0 + ) + ) + +;; definition for function vector-norm-matrix*! +(defun vector-norm-matrix*! ((arg0 vector) (arg1 vector) (arg2 matrix)) + (rlet ((acc :class vf) + (Q :class vf) + (vf0 :class vf) + (vf1 :class vf) + (vf2 :class vf) + (vf3 :class vf) + (vf4 :class vf) + (vf5 :class vf) + ) + (init-vf0-vector) + (.lvf vf1 (&-> arg2 rvec quad)) + (.lvf vf2 (&-> arg2 uvec quad)) + (.lvf vf3 (&-> arg2 fvec quad)) + (.lvf vf4 (&-> arg2 trans quad)) + (.lvf vf5 (&-> arg1 quad)) + (.mul.x.vf acc vf1 vf5) + (.add.mul.y.vf acc vf2 vf5 acc) + (.add.mul.z.vf acc vf3 vf5 acc) + (.add.mul.w.vf vf5 vf4 vf5 acc) + (.div.vf Q vf0 vf5 :fsf #b11 :ftf #b11) + (.wait.vf) + (.mul.vf vf5 vf5 Q :mask #b111) + (.nop.vf) + (.nop.vf) + (.mov.vf vf5 vf0 :mask #b1000) + (.svf (&-> arg0 quad) vf5) + arg0 + ) + ) + +;; definition for function vector-rotate*! +(defun vector-rotate*! ((arg0 vector) (arg1 vector) (arg2 matrix)) + "Set dst to be the input vector rotated by the rotation part of mat. +The input matrix should be a homogeneous transform with a rotation matrix as its upper-left 3x3. +dst may be equal to src." + (rlet ((acc :class vf) + (vf1 :class vf) + (vf2 :class vf) + (vf3 :class vf) + (vf4 :class vf) + (vf5 :class vf) + ) + (nop!) + (nop!) + (.lvf vf5 (&-> arg1 quad)) + (nop!) + (.lvf vf1 (&-> arg2 rvec quad)) + (nop!) + (.lvf vf2 (&-> arg2 uvec quad)) + (.mul.x.vf acc vf1 vf5) + (.lvf vf3 (&-> arg2 fvec quad)) + (.add.mul.y.vf acc vf2 vf5 acc) + (.lvf vf4 (&-> arg2 trans quad)) + (.add.mul.z.vf vf5 vf3 vf5 acc) + (nop!) + (nop!) + (.svf (&-> arg0 quad) vf5) + arg0 + ) + ) + +;; definition for function vector3s-matrix*! +;; INFO: Used lq/sq +(defun vector3s-matrix*! ((arg0 vector3s) (arg1 vector3s) (arg2 matrix)) + "Set dst to be ([src 1.0] * mat).xyz. Doesn't touch the w of dst. +dst and vec can be the same memory" + (let ((s5-0 (new-stack-vector0))) + (set-vector! s5-0 (-> arg1 x) (-> arg1 y) (-> arg1 z) 1.0) + (vector-matrix*! s5-0 s5-0 arg2) + (set! (-> arg0 x) (-> s5-0 x)) + (set! (-> arg0 y) (-> s5-0 y)) + (set! (-> arg0 z) (-> s5-0 z)) + ) + arg0 + ) + +;; definition for function vector3s-rotate*! +;; INFO: Used lq/sq +(defun vector3s-rotate*! ((arg0 vector3s) (arg1 vector3s) (arg2 matrix)) + "Set dst to vec rotated by the rotation in the homogeneous transform mat. +mat should not have a scale/shear (the upper 3x3 should be a pure rotation)." + (let ((s5-0 (new-stack-vector0))) + (set-vector! s5-0 (-> arg1 x) (-> arg1 y) (-> arg1 z) 1.0) + (vector-rotate*! s5-0 s5-0 arg2) + (set! (-> arg0 x) (-> s5-0 x)) + (set! (-> arg0 y) (-> s5-0 y)) + (set! (-> arg0 z) (-> s5-0 z)) + ) + arg0 + ) + +;; definition for function matrix-transpose! +;; INFO: Used lq/sq +(defun matrix-transpose! ((dst matrix) (src matrix)) + "Set dst = src^T. src and dst can be the same." + (local-vars (v1-0 uint128) (v1-1 uint128) (v1-2 uint128) (a1-1 uint128) (a2-1 uint128) (t0-1 uint128)) + (nop!) + (nop!) + (let ((t0-0 (-> src rvec quad))) + (nop!) + (let ((t1-0 (-> src uvec quad))) + (nop!) + (let ((a2-0 (-> src fvec quad))) + (.pextlw v1-0 t1-0 t0-0) + (let ((a3-0 (-> src trans quad))) + (.pextuw a1-1 t1-0 t0-0) + (nop!) + (.pextlw t0-1 a3-0 a2-0) + (nop!) + (.pextuw a2-1 a3-0 a2-0) + ) + ) + ) + ) + (nop!) + (let ((a3-1 (make-u128 t0-1 v1-0))) + (nop!) + (.pcpyud v1-1 v1-0 t0-1) + (set! (-> dst rvec quad) (the-as uint128 a3-1)) + ) + (let ((a3-2 (make-u128 a2-1 a1-1))) + (set! (-> dst uvec quad) v1-1) + (.pcpyud v1-2 a1-1 a2-1) + (set! (-> dst fvec quad) (the-as uint128 a3-2)) + ) + (nop!) + (set! (-> dst trans quad) v1-2) + dst + ) + +;; definition for function matrix-inverse-of-rot-trans! +(defun matrix-inverse-of-rot-trans! ((arg0 matrix) (arg1 matrix)) + "Set dst = src^-1, assuming src is a homogeneous tranform with only rotation/translation. +NOTE: THIS FUNCTION REQUIRES dst != src" + (rlet ((acc :class vf) + (vf0 :class vf) + (vf1 :class vf) + (vf2 :class vf) + (vf3 :class vf) + (vf4 :class vf) + (vf8 :class vf) + ) + (init-vf0-vector) + (matrix-transpose! arg0 arg1) + (.lvf vf1 (&-> arg0 rvec quad)) + (.lvf vf2 (&-> arg0 uvec quad)) + (.lvf vf3 (&-> arg0 fvec quad)) + (.sub.vf vf1 vf1 vf1 :mask #b1000) + (.sub.vf vf2 vf2 vf2 :mask #b1000) + (.sub.vf vf3 vf3 vf3 :mask #b1000) + (.lvf vf8 (&-> arg1 trans quad)) + (.mul.x.vf acc vf1 vf8) + (.add.mul.y.vf acc vf2 vf8 acc) + (.add.mul.z.vf vf4 vf3 vf8 acc) + (.sub.vf vf4 vf0 vf4) + (.mov.vf vf4 vf0 :mask #b1000) + (.svf (&-> arg0 rvec quad) vf1) + (.svf (&-> arg0 uvec quad) vf2) + (.svf (&-> arg0 fvec quad) vf3) + (.svf (&-> arg0 trans quad) vf4) + arg0 + ) + ) + +;; definition for function matrix-4x4-inverse! +;; ERROR: Bad vector register dependency: vf3 +;; ERROR: Bad vector register dependency: vf4 +;; ERROR: Bad vector register dependency: vf5 +(defun matrix-4x4-inverse! ((arg0 matrix) (arg1 matrix)) + "Invert a 4x4 matrix. This assumes that the input is a homogeneous transform. +Src and dst can be the same." + (rlet ((acc :class vf) + (Q :class vf) + (vf0 :class vf) + (vf1 :class vf) + (vf10 :class vf) + (vf11 :class vf) + (vf12 :class vf) + (vf13 :class vf) + (vf14 :class vf) + (vf15 :class vf) + (vf16 :class vf) + (vf17 :class vf) + (vf18 :class vf) + (vf19 :class vf) + (vf2 :class vf) + (vf20 :class vf) + (vf23 :class vf) + (vf24 :class vf) + (vf25 :class vf) + (vf26 :class vf) + (vf27 :class vf) + (vf28 :class vf) + (vf29 :class vf) + (vf3 :class vf) + (vf30 :class vf) + (vf31 :class vf) + (vf4 :class vf) + (vf5 :class vf) + (vf6 :class vf) + (vf7 :class vf) + (vf8 :class vf) + (vf9 :class vf) + ) + (init-vf0-vector) + (nop!) + (nop!) + (.lvf vf23 (&-> arg1 rvec quad)) + (nop!) + (.lvf vf24 (&-> arg1 uvec quad)) + (nop!) + (.lvf vf25 (&-> arg1 fvec quad)) + (nop!) + (.lvf vf1 (&-> arg1 trans quad)) + (.mul.x.vf vf7 vf24 vf23) + (nop!) + (.mul.y.vf vf8 vf24 vf23) + (nop!) + (.mul.z.vf vf9 vf24 vf23) + (nop!) + (.mul.x.vf vf10 vf25 vf23) + (nop!) + (.mul.y.vf vf11 vf25 vf23) + (nop!) + (.mul.z.vf vf12 vf25 vf23) + (nop!) + (.mul.x.vf vf13 vf25 vf24) + (nop!) + (.mul.y.vf vf14 vf25 vf24) + (nop!) + (.mul.z.vf vf15 vf25 vf24) + (nop!) + (.mul.z.vf vf26 vf7 vf25 :mask #b10) + (nop!) + (.mul.z.vf vf27 vf11 vf24 :mask #b1) + (nop!) + (.mul.y.vf vf28 vf9 vf25 :mask #b1) + (nop!) + (.mul.z.vf vf29 vf14 vf23 :mask #b1) + (nop!) + (.mul.z.vf vf30 vf8 vf25 :mask #b1) + (nop!) + (.mul.y.vf vf31 vf7 vf25 :mask #b100) + (nop!) + (.add.y.vf vf16 vf27 vf26 :mask #b1) + (nop!) + (.sub.vf vf1 vf0 vf1) + (nop!) + (.add.x.vf vf17 vf29 vf30 :mask #b1) + (nop!) + (.sub.z.vf vf18 vf28 vf31 :mask #b1) + (nop!) + (.sub.y.vf vf23 vf14 vf15 :mask #b100) + (nop!) + (.sub.z.vf vf26 vf15 vf13 :mask #b1) + (nop!) + (.sub.x.vf vf29 vf13 vf14 :mask #b10) + (nop!) + (.sub.vf vf19 vf16 vf17 :mask #b1) + (nop!) + (.sub.z.vf vf24 vf12 vf11 :mask #b10) + (nop!) + (.sub.x.vf vf27 vf10 vf12 :mask #b100) + (nop!) + (.sub.y.vf vf30 vf11 vf10 :mask #b1) + (nop!) + (.add.vf vf20 vf19 vf18 :mask #b1) + (nop!) + (.sub.y.vf vf25 vf8 vf9 :mask #b100) + (nop!) + (.sub.z.vf vf28 vf9 vf7 :mask #b1) + (nop!) + (.sub.x.vf vf31 vf7 vf8 :mask #b10) + (nop!) + (.div.vf Q vf0 vf20 :fsf #b11 :ftf #b0) + (nop!) + (.sub.w.vf vf3 vf3 vf3 :mask #b1000) + (nop!) + (.sub.w.vf vf4 vf4 vf4 :mask #b1000) + (nop!) + (.sub.w.vf vf5 vf5 vf5 :mask #b1000) + (nop!) + (.mov.vf vf6 vf0 :mask #b1000) + (nop!) + (.wait.vf) + (nop!) + (.add.vf vf2 vf0 Q :mask #b1) + (nop!) + (.add.x.vf vf2 vf0 vf2 :mask #b111) + (nop!) + (.mul.z.vf vf3 vf2 vf23 :mask #b1) + (nop!) + (.mul.x.vf vf4 vf2 vf26 :mask #b1) + (nop!) + (.mul.y.vf vf5 vf2 vf29 :mask #b1) + (nop!) + (.mul.y.vf vf3 vf2 vf24 :mask #b10) + (nop!) + (.mul.z.vf vf4 vf2 vf27 :mask #b10) + (nop!) + (.mul.x.vf vf5 vf2 vf30 :mask #b10) + (nop!) + (.mul.z.vf vf3 vf2 vf25 :mask #b100) + (nop!) + (.mul.x.vf vf4 vf2 vf28 :mask #b100) + (nop!) + (.mul.y.vf vf5 vf2 vf31 :mask #b100) + (nop!) + (.mul.x.vf acc vf3 vf1) + (.svf (&-> arg0 rvec quad) vf3) + (.add.mul.y.vf acc vf4 vf1 acc) + (.svf (&-> arg0 uvec quad) vf4) + (.add.mul.z.vf vf6 vf5 vf1 acc :mask #b111) + (.svf (&-> arg0 fvec quad) vf5) + (nop!) + (.svf (&-> arg0 trans quad) vf6) + arg0 + ) + ) + +;; definition for function matrix-translate! +(defun matrix-translate! ((arg0 matrix) (arg1 vector)) + "Set dst to a homogeneous transform with only a translation of trans." + (matrix-identity! arg0) + (set! (-> arg0 trans x) (-> arg1 x)) + (set! (-> arg0 trans y) (-> arg1 y)) + (set! (-> arg0 trans z) (-> arg1 z)) + arg0 + ) + +;; definition for function matrix-translate+! +;; INFO: Used lq/sq +(defun matrix-translate+! ((arg0 matrix) (arg1 matrix) (arg2 vector)) + "Add the given translation to the translation of homogenous transform mat src +and store in dst. It is okay for dst = src." + (set! (-> arg0 trans x) (+ (-> arg1 trans x) (-> arg2 x))) + (set! (-> arg0 trans y) (+ (-> arg1 trans y) (-> arg2 y))) + (set! (-> arg0 trans z) (+ (-> arg1 trans z) (-> arg2 z))) + (when (!= arg0 arg1) + (set! (-> arg0 rvec quad) (-> arg1 rvec quad)) + (set! (-> arg0 uvec quad) (-> arg1 uvec quad)) + (set! (-> arg0 fvec quad) (-> arg1 fvec quad)) + ) + arg0 + ) + +;; definition for function matrix-scale! +;; INFO: Used lq/sq +(defun matrix-scale! ((arg0 matrix) (arg1 vector)) + "Set dst to a homogenous transform with only a scale. The x,y,z components +of scale become the x,y,z scaling factors" + (set! (-> arg0 rvec quad) (the-as uint128 0)) + (set! (-> arg0 uvec quad) (the-as uint128 0)) + (set! (-> arg0 fvec quad) (the-as uint128 0)) + (set! (-> arg0 trans quad) (the-as uint128 0)) + (set! (-> arg0 rvec x) (-> arg1 x)) + (set! (-> arg0 uvec y) (-> arg1 y)) + (set! (-> arg0 fvec z) (-> arg1 z)) + (set! (-> arg0 trans w) 1.0) + arg0 + ) + +;; definition for function scale-matrix! +(defun scale-matrix! ((arg0 matrix) (arg1 vector) (arg2 matrix)) + "Scale an existing matrix. Okay for dst = src. The scaling is applied per row. +This means the x component of scale is used to scale the first row of src. +The w component of scale is used." + (rlet ((vf4 :class vf) + (vf5 :class vf) + (vf6 :class vf) + (vf7 :class vf) + (vf8 :class vf) + ) + (.lvf vf4 (&-> arg1 quad)) + (.lvf vf5 (&-> arg2 rvec quad)) + (.lvf vf6 (&-> arg2 uvec quad)) + (.lvf vf7 (&-> arg2 fvec quad)) + (.lvf vf8 (&-> arg2 trans quad)) + (.mul.x.vf vf5 vf5 vf4) + (.mul.y.vf vf6 vf6 vf4) + (.mul.z.vf vf7 vf7 vf4) + (.mul.w.vf vf8 vf8 vf4) + (.svf (&-> arg0 rvec quad) vf5) + (.svf (&-> arg0 uvec quad) vf6) + (.svf (&-> arg0 fvec quad) vf7) + (.svf (&-> arg0 trans quad) vf8) + arg0 + ) + ) + +;; definition for function matrix-inv-scale! +;; INFO: Used lq/sq +(defun matrix-inv-scale! ((arg0 matrix) (arg1 vector)) + "Set dst to a homogeneous transform with only a scale. +The x,y,z components of scale are inverted and used as the x,y,z scaling factors" + (set! (-> arg0 rvec quad) (the-as uint128 0)) + (set! (-> arg0 uvec quad) (the-as uint128 0)) + (set! (-> arg0 fvec quad) (the-as uint128 0)) + (set! (-> arg0 trans quad) (the-as uint128 0)) + (set! (-> arg0 rvec x) (/ 1.0 (-> arg1 x))) + (set! (-> arg0 uvec y) (/ 1.0 (-> arg1 y))) + (set! (-> arg0 fvec z) (/ 1.0 (-> arg1 z))) + (set! (-> arg0 trans w) 1.0) + arg0 + ) + +;; definition for function column-scale-matrix! +(defun column-scale-matrix! ((arg0 matrix) (arg1 vector) (arg2 matrix)) + "Scale an existing matrix. Okay for dst = src. The scaling is applied column-wise. +Meaning the x component of scale will scale the first column of src." + (rlet ((vf4 :class vf) + (vf5 :class vf) + (vf6 :class vf) + (vf7 :class vf) + (vf8 :class vf) + ) + (.lvf vf4 (&-> arg1 quad)) + (.lvf vf5 (&-> arg2 rvec quad)) + (.lvf vf6 (&-> arg2 uvec quad)) + (.lvf vf7 (&-> arg2 fvec quad)) + (.lvf vf8 (&-> arg2 trans quad)) + (.mul.vf vf5 vf5 vf4) + (.mul.vf vf6 vf6 vf4) + (.mul.vf vf7 vf7 vf4) + (.mul.vf vf8 vf8 vf4) + (.svf (&-> arg0 rvec quad) vf5) + (.svf (&-> arg0 uvec quad) vf6) + (.svf (&-> arg0 fvec quad) vf7) + (.svf (&-> arg0 trans quad) vf8) + arg0 + ) + ) + +;; definition for function matrix-rotate-x! +;; INFO: Used lq/sq +(defun matrix-rotate-x! ((arg0 matrix) (arg1 float)) + "Set dst to a homogeneous transform matrix for a rotation around the x-axis (degrees)." + (let ((f30-0 (sin arg1)) + (f0-0 (cos arg1)) + ) + (set! (-> arg0 rvec quad) (the-as uint128 0)) + (set! (-> arg0 uvec quad) (the-as uint128 0)) + (set! (-> arg0 fvec quad) (the-as uint128 0)) + (set! (-> arg0 trans quad) (the-as uint128 0)) + (set! (-> arg0 rvec x) 1.0) + (set! (-> arg0 uvec y) f0-0) + (set! (-> arg0 uvec z) f30-0) + (set! (-> arg0 fvec y) (- f30-0)) + (set! (-> arg0 fvec z) f0-0) + ) + (set! (-> arg0 trans w) 1.0) + arg0 + ) + +;; definition for function matrix-rotate-y! +;; INFO: Used lq/sq +(defun matrix-rotate-y! ((arg0 matrix) (arg1 float)) + "Set dst to a homoegeneous transform matrix for a rotation around the y axis (degrees)." + (let ((f30-0 (sin arg1)) + (f0-0 (cos arg1)) + ) + (set! (-> arg0 rvec quad) (the-as uint128 0)) + (set! (-> arg0 uvec quad) (the-as uint128 0)) + (set! (-> arg0 fvec quad) (the-as uint128 0)) + (set! (-> arg0 trans quad) (the-as uint128 0)) + (set! (-> arg0 rvec x) f0-0) + (set! (-> arg0 rvec z) (- f30-0)) + (set! (-> arg0 uvec y) 1.0) + (set! (-> arg0 fvec x) f30-0) + (set! (-> arg0 fvec z) f0-0) + ) + (set! (-> arg0 trans w) 1.0) + arg0 + ) + +;; definition for function matrix-rotate-z! +;; INFO: Used lq/sq +(defun matrix-rotate-z! ((arg0 matrix) (arg1 float)) + "Set dst to a homogeneous transform matrix for a rotation around the z-axis (degrees)." + (let ((f30-0 (sin arg1)) + (f0-0 (cos arg1)) + ) + (set! (-> arg0 rvec quad) (the-as uint128 0)) + (set! (-> arg0 uvec quad) (the-as uint128 0)) + (set! (-> arg0 fvec quad) (the-as uint128 0)) + (set! (-> arg0 trans quad) (the-as uint128 0)) + (set! (-> arg0 rvec x) f0-0) + (set! (-> arg0 rvec y) f30-0) + (set! (-> arg0 uvec x) (- f30-0)) + (set! (-> arg0 uvec y) f0-0) + ) + (set! (-> arg0 fvec z) 1.0) + (set! (-> arg0 trans w) 1.0) + arg0 + ) + +;; definition for function matrix-rotate-zyx! +;; INFO: Used lq/sq +(defun matrix-rotate-zyx! ((arg0 matrix) (arg1 vector)) + "Rotate in z,y,x order." + (let ((gp-0 (new 'stack-no-clear 'matrix))) + (set! (-> gp-0 rvec quad) (the-as uint128 0)) + (set! (-> gp-0 uvec quad) (the-as uint128 0)) + (set! (-> gp-0 fvec quad) (the-as uint128 0)) + (set! (-> gp-0 trans quad) (the-as uint128 0)) + (let ((s5-0 (new 'stack-no-clear 'matrix))) + (set! (-> s5-0 rvec quad) (the-as uint128 0)) + (set! (-> s5-0 uvec quad) (the-as uint128 0)) + (set! (-> s5-0 fvec quad) (the-as uint128 0)) + (set! (-> s5-0 trans quad) (the-as uint128 0)) + (matrix-rotate-x! arg0 (-> arg1 x)) + (matrix-rotate-y! gp-0 (-> arg1 y)) + (matrix*! s5-0 gp-0 arg0) + (matrix-rotate-z! gp-0 (-> arg1 z)) + (matrix*! arg0 gp-0 s5-0) + ) + ) + arg0 + ) + +;; definition (debug) for function matrix-rotate-xyz-2! +(defun-debug matrix-rotate-xyz-2! ((arg0 matrix) (arg1 vector)) + "Jak 1 version of matrix-rotate-xyz. Slower than the one below." + (let ((gp-0 (new 'stack-no-clear 'matrix)) + (s5-0 (new 'stack-no-clear 'matrix)) + ) + (matrix-rotate-z! arg0 (-> arg1 z)) + (matrix-rotate-y! gp-0 (-> arg1 y)) + (matrix*! s5-0 gp-0 arg0) + (matrix-rotate-x! gp-0 (-> arg1 x)) + (matrix*! arg0 gp-0 s5-0) + ) + arg0 + ) + +;; definition for function matrix-rotate-xyz! +(defun matrix-rotate-xyz! ((arg0 matrix) (arg1 vector)) + "Rotate in x,y,z order." + (rlet ((vf0 :class vf)) + (init-vf0-vector) + (let ((s4-0 (new 'stack-no-clear 'vector)) + (s5-0 (new 'stack-no-clear 'vector)) + ) + (vector-sincos! s4-0 s5-0 arg1) + (let ((f2-0 (-> s4-0 x)) + (f5-0 (-> s4-0 y)) + (f3-0 (-> s4-0 z)) + (f0-0 (-> s5-0 x)) + (f1-0 (-> s5-0 y)) + ) + (let ((f4-0 (-> s5-0 z))) + (set! (-> arg0 rvec x) (* f1-0 f4-0)) + (set! (-> arg0 rvec y) (* f1-0 f3-0)) + (set! (-> arg0 rvec z) (- f5-0)) + (set! (-> arg0 rvec w) 0.0) + (let ((f6-4 (* f2-0 f5-0)) + (f5-1 (* f0-0 f5-0)) + ) + (set! (-> arg0 uvec x) (- (* f6-4 f4-0) (* f0-0 f3-0))) + (set! (-> arg0 uvec y) (+ (* f6-4 f3-0) (* f0-0 f4-0))) + (set! (-> arg0 uvec z) (* f2-0 f1-0)) + (set! (-> arg0 uvec w) 0.0) + (set! (-> arg0 fvec x) (+ (* f2-0 f3-0) (* f5-1 f4-0))) + (set! (-> arg0 fvec y) (- (* f5-1 f3-0) (* f2-0 f4-0))) + ) + ) + (set! (-> arg0 fvec z) (* f0-0 f1-0)) + ) + ) + (set! (-> arg0 fvec w) 0.0) + (.svf (&-> arg0 trans quad) vf0) + arg0 + ) + ) + +;; definition for function matrix-rotate-zxy! +;; INFO: Used lq/sq +(defun matrix-rotate-zxy! ((arg0 matrix) (arg1 vector)) + "Rotate in z,x,y order." + (let ((gp-0 (new 'stack-no-clear 'matrix))) + (set! (-> gp-0 rvec quad) (the-as uint128 0)) + (set! (-> gp-0 uvec quad) (the-as uint128 0)) + (set! (-> gp-0 fvec quad) (the-as uint128 0)) + (set! (-> gp-0 trans quad) (the-as uint128 0)) + (let ((s5-0 (new 'stack-no-clear 'matrix))) + (set! (-> s5-0 rvec quad) (the-as uint128 0)) + (set! (-> s5-0 uvec quad) (the-as uint128 0)) + (set! (-> s5-0 fvec quad) (the-as uint128 0)) + (set! (-> s5-0 trans quad) (the-as uint128 0)) + (matrix-rotate-y! arg0 (-> arg1 y)) + (matrix-rotate-x! gp-0 (-> arg1 x)) + (matrix*! s5-0 gp-0 arg0) + (matrix-rotate-z! gp-0 (-> arg1 z)) + (matrix*! arg0 gp-0 s5-0) + ) + ) + arg0 + ) + +;; definition for function matrix-rotate-yxz! +;; INFO: Used lq/sq +(defun matrix-rotate-yxz! ((arg0 matrix) (arg1 vector)) + "Rotate in y,x,z order." + (let ((gp-0 (new 'stack-no-clear 'matrix))) + (set! (-> gp-0 rvec quad) (the-as uint128 0)) + (set! (-> gp-0 uvec quad) (the-as uint128 0)) + (set! (-> gp-0 fvec quad) (the-as uint128 0)) + (set! (-> gp-0 trans quad) (the-as uint128 0)) + (let ((s5-0 (new 'stack-no-clear 'matrix))) + (set! (-> s5-0 rvec quad) (the-as uint128 0)) + (set! (-> s5-0 uvec quad) (the-as uint128 0)) + (set! (-> s5-0 fvec quad) (the-as uint128 0)) + (set! (-> s5-0 trans quad) (the-as uint128 0)) + (matrix-rotate-z! arg0 (-> arg1 z)) + (matrix-rotate-x! gp-0 (-> arg1 x)) + (matrix*! s5-0 gp-0 arg0) + (matrix-rotate-y! gp-0 (-> arg1 y)) + (matrix*! arg0 gp-0 s5-0) + ) + ) + arg0 + ) + +;; definition for function matrix-rotate-yzx! +;; INFO: Used lq/sq +(defun matrix-rotate-yzx! ((arg0 matrix) (arg1 vector)) + "Rotate in y,z,x order." + (let ((gp-0 (new 'stack-no-clear 'matrix))) + (set! (-> gp-0 rvec quad) (the-as uint128 0)) + (set! (-> gp-0 uvec quad) (the-as uint128 0)) + (set! (-> gp-0 fvec quad) (the-as uint128 0)) + (set! (-> gp-0 trans quad) (the-as uint128 0)) + (let ((s5-0 (new 'stack-no-clear 'matrix))) + (set! (-> s5-0 rvec quad) (the-as uint128 0)) + (set! (-> s5-0 uvec quad) (the-as uint128 0)) + (set! (-> s5-0 fvec quad) (the-as uint128 0)) + (set! (-> s5-0 trans quad) (the-as uint128 0)) + (matrix-rotate-z! arg0 (-> arg1 x)) + (matrix-rotate-x! gp-0 (-> arg1 z)) + (matrix*! s5-0 gp-0 arg0) + (matrix-rotate-y! gp-0 (-> arg1 y)) + (matrix*! arg0 gp-0 s5-0) + ) + ) + arg0 + ) + +;; definition for function matrix-rotate-yxy! +(defun matrix-rotate-yxy! ((arg0 matrix) (arg1 vector)) + "Rotate. I believe in yxy order? Compared to the other rotations, this one +is quite a bit more optimized and avoid repeated trig operations." + (let ((a2-0 (new 'stack-no-clear 'vector)) + (s5-0 (new 'stack-no-clear 'vector)) + (s4-0 (new 'stack-no-clear 'vector)) + ) + (set-vector! a2-0 (-> arg1 x) (- (-> arg1 y) (-> arg1 z)) (-> arg1 z) 1.0) + (vector-sincos! s5-0 s4-0 a2-0) + (let ((f1-1 (-> s4-0 y)) + (f0-5 (-> s5-0 y)) + (f2-0 (-> s4-0 x)) + (f5-0 (-> s5-0 x)) + (f3-0 (-> s4-0 z)) + (f4-0 (-> s5-0 z)) + ) + (set! (-> arg0 rvec x) (- (* f1-1 f3-0) (* f0-5 f2-0 f4-0))) + (set! (-> arg0 rvec y) (* f0-5 f5-0)) + (set! (-> arg0 rvec z) (- (+ (* f1-1 f4-0) (* f0-5 f2-0 f3-0)))) + (set! (-> arg0 rvec w) 0.0) + (set! (-> arg0 uvec x) (* f5-0 f4-0)) + (set! (-> arg0 uvec y) f2-0) + (set! (-> arg0 uvec z) (* f5-0 f3-0)) + (set! (-> arg0 uvec w) 0.0) + (set! (-> arg0 fvec x) (+ (* f0-5 f3-0) (* f1-1 f2-0 f4-0))) + (set! (-> arg0 fvec y) (- (* f1-1 f5-0))) + (set! (-> arg0 fvec z) (- (* f1-1 f2-0 f3-0) (* f0-5 f4-0))) + ) + ) + (set! (-> arg0 fvec w) 0.0) + (set! (-> arg0 trans x) 0.0) + (set! (-> arg0 trans y) 0.0) + (set! (-> arg0 trans z) 0.0) + (set! (-> arg0 trans w) 1.0) + arg0 + ) + +;; definition for function matrix-rotate-yx! +;; INFO: Used lq/sq +(defun matrix-rotate-yx! ((arg0 matrix) (arg1 float) (arg2 float)) + "Rotate by y then x." + (matrix-rotate-y! arg0 arg1) + (let ((t9-1 matrix-rotate-x!) + (a0-2 (new 'stack-no-clear 'matrix)) + ) + (set! (-> a0-2 rvec quad) (the-as uint128 0)) + (set! (-> a0-2 uvec quad) (the-as uint128 0)) + (set! (-> a0-2 fvec quad) (the-as uint128 0)) + (set! (-> a0-2 trans quad) (the-as uint128 0)) + (let ((a1-2 (t9-1 a0-2 arg2))) + (matrix*! arg0 a1-2 arg0) + ) + ) + arg0 + ) + +;; definition for function matrix-axis-sin-cos-vu! +;; INFO: Used lq/sq +;; WARN: Return type mismatch matrix vs none. +;; ERROR: Unsupported inline assembly instruction kind - [prot3w a1, v1] +;; ERROR: Unsupported inline assembly instruction kind - [prot3w a2, a1] +(defun matrix-axis-sin-cos-vu! ((arg0 matrix) (arg1 vector) (arg2 float) (arg3 float)) + "Create an axis-angle rotation matrix. But given the sin/cos of the angle. Uses the VU." + (local-vars (a1-2 uint128) (a2-1 uint128) (a3-1 uint128) (a3-2 uint128)) + (rlet ((vf0 :class vf) + (vf1 :class vf) + (vf10 :class vf) + (vf11 :class vf) + (vf2 :class vf) + (vf3 :class vf) + (vf4 :class vf) + (vf5 :class vf) + (vf6 :class vf) + (vf7 :class vf) + (vf8 :class vf) + (vf9 :class vf) + ) + (init-vf0-vector) + (nop!) + (let* ((t0-0 #xffff) + (v1-0 (-> arg1 quad)) + (a1-1 (shl t0-0 48)) + ) + (.mov vf6 arg3) + (.pceqw a3-1 v1-0 0) + (nop!) + (.ppach a3-2 (the-as uint128 0) a3-1) + (nop!) + (nop!) + (.mov vf1 v1-0) + (let ((v1-1 (logior a3-2 a1-1))) + (.mov vf5 arg2) + (let ((v1-2 (+ v1-1 1))) + (.sub.x.vf vf5 vf0 vf6 :mask #b1000) + (b! (zero? v1-2) cfg-2 :delay (.add.x.vf vf5 vf0 vf6 :mask #b10)) + ) + ) + ) + (.sub.w.vf vf2 vf0 vf0 :mask #b1000) + (nop!) + (.sub.w.vf vf3 vf0 vf0 :mask #b1000) + (nop!) + (.sub.w.vf vf4 vf0 vf0 :mask #b1000) + (nop!) + (.mul.x.vf vf11 vf1 vf5 :mask #b111) + (nop!) + (.add.y.vf vf7 vf0 vf5 :mask #b1) + (nop!) + (.add.y.vf vf8 vf0 vf5 :mask #b10) + (nop!) + (.add.y.vf vf9 vf0 vf5 :mask #b100) + (nop!) + (.mul.w.vf vf10 vf1 vf5 :mask #b111) + (nop!) + (.sub.z.vf vf7 vf0 vf11 :mask #b10) + (nop!) + (.add.y.vf vf7 vf0 vf11 :mask #b100) + (nop!) + (.add.z.vf vf8 vf0 vf11 :mask #b1) + (nop!) + (.sub.x.vf vf8 vf0 vf11 :mask #b100) + (nop!) + (.mul.x.vf vf2 vf10 vf1 :mask #b111) + (nop!) + (.mul.y.vf vf3 vf10 vf1 :mask #b111) + (nop!) + (.mul.z.vf vf4 vf10 vf1 :mask #b111) + (nop!) + (.sub.y.vf vf9 vf0 vf11 :mask #b1) + (nop!) + (.add.x.vf vf9 vf0 vf11 :mask #b10) + (nop!) + (.add.vf vf2 vf2 vf7 :mask #b111) + (nop!) + (.add.vf vf3 vf3 vf8 :mask #b111) + (nop!) + (nop!) + (nop!) + (.add.vf vf4 vf4 vf9 :mask #b111) + (nop!) + (nop!) + (.svf (&-> arg0 rvec quad) vf2) + (nop!) + (.svf (&-> arg0 uvec quad) vf3) + (nop!) + (.svf (&-> arg0 trans quad) vf0) + (b! #t cfg-3 :delay (.svf (&-> arg0 fvec quad) vf4)) + (label cfg-2) + (let ((v1-3 #x3f800000)) + (.svf (&-> arg0 trans quad) vf0) + (let ((v1-4 (the-as uint128 (make-u128 0 v1-3)))) + (nop!) + (.prot3w a1-2 (the-as uint v1-4)) + (nop!) + (.prot3w a2-1 (the-as int a1-2)) + (set! (-> arg0 rvec quad) v1-4) + ) + ) + (nop!) + (set! (-> arg0 fvec quad) a1-2) + (nop!) + (set! (-> arg0 uvec quad) a2-1) + (label cfg-3) + (none) + ) + ) + +;; definition for function matrix-axis-sin-cos! +;; INFO: Used lq/sq +;; ERROR: Unsupported inline assembly instruction kind - [prot3w a0, v1] +;; ERROR: Unsupported inline assembly instruction kind - [prot3w a1, a0] +(defun matrix-axis-sin-cos! ((dst matrix) (axis vector) (s float) (c float)) + "Create an axis-angle rotation matrix. But given the sin/cos of the angle." + (local-vars (a0-4 uint128) (a1-2 uint128) (a1-3 uint128) (a1-4 uint128)) + (rlet ((vf0 :class vf) + (vf1 :class vf) + (vf10 :class vf) + (vf11 :class vf) + (vf2 :class vf) + (vf3 :class vf) + (vf4 :class vf) + (vf5 :class vf) + (vf6 :class vf) + (vf7 :class vf) + (vf8 :class vf) + (vf9 :class vf) + ) + (init-vf0-vector) + (let ((v0-0 dst)) + (let ((v1-0 axis) + (f0-0 s) + (f1-0 c) + ) + (nop!) + (let* ((a0-1 #xffff) + (v1-1 (-> v1-0 quad)) + (a0-2 (shl a0-1 48)) + ) + (let ((a1-1 f1-0)) + (.mov vf6 a1-1) + ) + (.pceqw a1-2 v1-1 0) + (nop!) + (.ppach a1-3 (the-as uint128 0) a1-2) + (nop!) + (nop!) + (.mov vf1 v1-1) + (let ((v1-2 (logior a1-3 a0-2))) + (let ((a0-3 f0-0)) + (.mov vf5 a0-3) + ) + (let ((v1-3 (+ v1-2 1))) + (.sub.x.vf vf5 vf0 vf6 :mask #b1000) + (b! (zero? v1-3) cfg-2 :delay (.add.x.vf vf5 vf0 vf6 :mask #b10)) + ) + ) + ) + ) + (.sub.w.vf vf2 vf0 vf0 :mask #b1000) + (nop!) + (.sub.w.vf vf3 vf0 vf0 :mask #b1000) + (nop!) + (.sub.w.vf vf4 vf0 vf0 :mask #b1000) + (nop!) + (.mul.x.vf vf11 vf1 vf5 :mask #b111) + (nop!) + (.add.y.vf vf7 vf0 vf5 :mask #b1) + (nop!) + (.add.y.vf vf8 vf0 vf5 :mask #b10) + (nop!) + (.add.y.vf vf9 vf0 vf5 :mask #b100) + (nop!) + (.mul.w.vf vf10 vf1 vf5 :mask #b111) + (nop!) + (.sub.z.vf vf7 vf0 vf11 :mask #b10) + (nop!) + (.add.y.vf vf7 vf0 vf11 :mask #b100) + (nop!) + (.add.z.vf vf8 vf0 vf11 :mask #b1) + (nop!) + (.sub.x.vf vf8 vf0 vf11 :mask #b100) + (nop!) + (.mul.x.vf vf2 vf10 vf1 :mask #b111) + (nop!) + (.mul.y.vf vf3 vf10 vf1 :mask #b111) + (nop!) + (.mul.z.vf vf4 vf10 vf1 :mask #b111) + (nop!) + (.sub.y.vf vf9 vf0 vf11 :mask #b1) + (nop!) + (.add.x.vf vf9 vf0 vf11 :mask #b10) + (nop!) + (.add.vf vf2 vf2 vf7 :mask #b111) + (nop!) + (.add.vf vf3 vf3 vf8 :mask #b111) + (nop!) + (nop!) + (nop!) + (.add.vf vf4 vf4 vf9 :mask #b111) + (nop!) + (nop!) + (.svf (&-> v0-0 rvec quad) vf2) + (nop!) + (.svf (&-> v0-0 uvec quad) vf3) + (nop!) + (.svf (&-> v0-0 trans quad) vf0) + (b! #t cfg-3 :delay (.svf (&-> v0-0 fvec quad) vf4)) + (label cfg-2) + (let ((v1-4 #x3f800000)) + (.svf (&-> v0-0 trans quad) vf0) + (let ((v1-5 (the-as uint128 (make-u128 0 v1-4)))) + (nop!) + (.prot3w a0-4 (the-as uint v1-5)) + (nop!) + (.prot3w a1-4 (the-as int a0-4)) + (set! (-> v0-0 rvec quad) v1-5) + ) + ) + (nop!) + (set! (-> v0-0 fvec quad) a0-4) + (nop!) + (set! (-> v0-0 uvec quad) a1-4) + (label cfg-3) + v0-0 + ) + ) + ) + +;; definition for function matrix-axis-angle! +(defun matrix-axis-angle! ((arg0 matrix) (arg1 vector) (arg2 float)) + "Create an axis-angle rotation matrix." + (matrix-axis-sin-cos! arg0 arg1 (sin arg2) (cos arg2)) + ) + +;; definition for function matrix-lerp! +(defun matrix-lerp! ((arg0 matrix) (arg1 matrix) (arg2 matrix) (arg3 float)) + "Lerp an entire matrix, coefficient-wise." + (rlet ((vf1 :class vf) + (vf2 :class vf) + (vf3 :class vf) + (vf4 :class vf) + (vf5 :class vf) + (vf6 :class vf) + (vf7 :class vf) + (vf8 :class vf) + (vf9 :class vf) + ) + (.mov vf9 arg3) + (.lvf vf1 (&-> arg1 rvec quad)) + (.lvf vf2 (&-> arg1 uvec quad)) + (.lvf vf3 (&-> arg1 fvec quad)) + (.lvf vf4 (&-> arg1 trans quad)) + (.lvf vf5 (&-> arg2 rvec quad)) + (.lvf vf6 (&-> arg2 uvec quad)) + (.lvf vf7 (&-> arg2 fvec quad)) + (.lvf vf8 (&-> arg2 trans quad)) + (.sub.vf vf5 vf5 vf1) + (.sub.vf vf6 vf6 vf2) + (.sub.vf vf7 vf7 vf3) + (.sub.vf vf8 vf8 vf4) + (.mul.x.vf vf5 vf5 vf9) + (.mul.x.vf vf6 vf6 vf9) + (.mul.x.vf vf7 vf7 vf9) + (.mul.x.vf vf8 vf8 vf9) + (.add.vf vf1 vf1 vf5) + (.add.vf vf2 vf2 vf6) + (.add.vf vf3 vf3 vf7) + (.add.vf vf4 vf4 vf8) + (.svf (&-> arg0 rvec quad) vf1) + (.svf (&-> arg0 uvec quad) vf2) + (.svf (&-> arg0 fvec quad) vf3) + (.svf (&-> arg0 trans quad) vf4) + arg0 + ) + ) + +;; definition for function matrix-3x3-determinant +(defun matrix-3x3-determinant ((arg0 matrix)) + "Compute the determinant of a 3x3 matrix." + (let ((f8-0 (-> arg0 rvec x)) + (f1-0 (-> arg0 rvec y)) + (f4-0 (-> arg0 rvec z)) + (f2-0 (-> arg0 uvec x)) + (f5-0 (-> arg0 uvec y)) + (f9-0 (-> arg0 uvec z)) + (f3-0 (-> arg0 fvec x)) + (f6-0 (-> arg0 fvec y)) + (f0-0 (-> arg0 fvec z)) + ) + (- (+ (* f8-0 f5-0 f0-0) (* f1-0 f9-0 f3-0) (* f4-0 f2-0 f6-0)) + (+ (* f8-0 f9-0 f6-0) (* f4-0 f5-0 f3-0) (* f1-0 f2-0 f0-0)) + ) + ) + ) + +;; definition for function matrix3-determinant +(defun matrix3-determinant ((arg0 matrix)) + "Unused. Not sure if this has limitations compared to the above version." + (local-vars (v0-0 float)) + (rlet ((acc :class vf) + (vf10 :class vf) + (vf11 :class vf) + (vf12 :class vf) + (vf13 :class vf) + ) + (.lvf vf11 (&-> arg0 uvec quad)) + (.lvf vf12 (&-> arg0 fvec quad)) + (.lvf vf10 (&-> arg0 rvec quad)) + (.outer.product.a.vf acc vf11 vf12) + (.outer.product.b.vf vf13 vf12 vf11 acc) + (.mul.vf vf13 vf13 vf10 :mask #b111) + (.add.y.vf vf13 vf13 vf13 :mask #b1) + (.add.z.vf vf13 vf13 vf13 :mask #b1) + (.mov v0-0 vf13) + v0-0 + ) + ) + +;; definition for function matrix-3x3-inverse! +(defun matrix-3x3-inverse! ((arg0 matrix) (arg1 matrix)) + "Compute the inverse of a 3x3 matrix. Not very efficient. +Requires src != dst." + (let ((f0-0 (matrix-3x3-determinant arg1))) + (set! (-> arg0 rvec x) + (/ (- (* (-> arg1 uvec y) (-> arg1 fvec z)) (* (-> arg1 uvec z) (-> arg1 fvec y))) f0-0) + ) + (set! (-> arg0 uvec x) + (/ (- (* (-> arg1 uvec z) (-> arg1 fvec x)) (* (-> arg1 uvec x) (-> arg1 fvec z))) f0-0) + ) + (set! (-> arg0 fvec x) + (/ (- (* (-> arg1 uvec x) (-> arg1 fvec y)) (* (-> arg1 uvec y) (-> arg1 fvec x))) f0-0) + ) + (set! (-> arg0 rvec y) + (/ (- (* (-> arg1 fvec y) (-> arg1 rvec z)) (* (-> arg1 fvec z) (-> arg1 rvec y))) f0-0) + ) + (set! (-> arg0 uvec y) + (/ (- (* (-> arg1 fvec z) (-> arg1 rvec x)) (* (-> arg1 fvec x) (-> arg1 rvec z))) f0-0) + ) + (set! (-> arg0 fvec y) + (/ (- (* (-> arg1 fvec x) (-> arg1 rvec y)) (* (-> arg1 fvec y) (-> arg1 rvec x))) f0-0) + ) + (set! (-> arg0 rvec z) + (/ (- (* (-> arg1 rvec y) (-> arg1 uvec z)) (* (-> arg1 rvec z) (-> arg1 uvec y))) f0-0) + ) + (set! (-> arg0 uvec z) + (/ (- (* (-> arg1 rvec z) (-> arg1 uvec x)) (* (-> arg1 rvec x) (-> arg1 uvec z))) f0-0) + ) + (set! (-> arg0 fvec z) + (/ (- (* (-> arg1 rvec x) (-> arg1 uvec y)) (* (-> arg1 rvec y) (-> arg1 uvec x))) f0-0) + ) + ) + arg0 + ) + +;; definition for function matrix-3x3-inverse-transpose! +(defun matrix-3x3-inverse-transpose! ((arg0 matrix) (arg1 matrix)) + "Invert and transpose. +Requires dst != src." + (let ((f0-0 (matrix-3x3-determinant arg1))) + (set! (-> arg0 rvec x) + (/ (- (* (-> arg1 uvec y) (-> arg1 fvec z)) (* (-> arg1 uvec z) (-> arg1 fvec y))) f0-0) + ) + (set! (-> arg0 rvec y) + (/ (- (* (-> arg1 uvec z) (-> arg1 fvec x)) (* (-> arg1 uvec x) (-> arg1 fvec z))) f0-0) + ) + (set! (-> arg0 rvec z) + (/ (- (* (-> arg1 uvec x) (-> arg1 fvec y)) (* (-> arg1 uvec y) (-> arg1 fvec x))) f0-0) + ) + (set! (-> arg0 uvec x) + (/ (- (* (-> arg1 fvec y) (-> arg1 rvec z)) (* (-> arg1 fvec z) (-> arg1 rvec y))) f0-0) + ) + (set! (-> arg0 uvec y) + (/ (- (* (-> arg1 fvec z) (-> arg1 rvec x)) (* (-> arg1 fvec x) (-> arg1 rvec z))) f0-0) + ) + (set! (-> arg0 uvec z) + (/ (- (* (-> arg1 fvec x) (-> arg1 rvec y)) (* (-> arg1 fvec y) (-> arg1 rvec x))) f0-0) + ) + (set! (-> arg0 fvec x) + (/ (- (* (-> arg1 rvec y) (-> arg1 uvec z)) (* (-> arg1 rvec z) (-> arg1 uvec y))) f0-0) + ) + (set! (-> arg0 fvec y) + (/ (- (* (-> arg1 rvec z) (-> arg1 uvec x)) (* (-> arg1 rvec x) (-> arg1 uvec z))) f0-0) + ) + (set! (-> arg0 fvec z) + (/ (- (* (-> arg1 rvec x) (-> arg1 uvec y)) (* (-> arg1 rvec y) (-> arg1 uvec x))) f0-0) + ) + ) + arg0 + ) + +;; definition for function matrix3-inverse-transpose! +(defun matrix3-inverse-transpose! ((arg0 matrix) (arg1 matrix)) + "Unused. Not sure if this has limitations compared to other version." + (rlet ((acc :class vf) + (Q :class vf) + (vf0 :class vf) + (vf1 :class vf) + (vf10 :class vf) + (vf11 :class vf) + (vf12 :class vf) + (vf13 :class vf) + (vf14 :class vf) + (vf15 :class vf) + ) + (init-vf0-vector) + (.lvf vf10 (&-> arg1 rvec quad)) + (.lvf vf11 (&-> arg1 uvec quad)) + (.lvf vf12 (&-> arg1 fvec quad)) + (.outer.product.a.vf acc vf11 vf12) + (.outer.product.b.vf vf13 vf12 vf11 acc) + (.outer.product.a.vf acc vf12 vf10) + (.outer.product.b.vf vf14 vf10 vf12 acc) + (.mul.vf vf1 vf10 vf13 :mask #b111) + (.outer.product.a.vf acc vf10 vf11) + (.outer.product.b.vf vf15 vf11 vf10 acc) + (.nop.vf) + (.add.y.vf vf1 vf1 vf1 :mask #b1) + (.nop.vf) + (.nop.vf) + (.nop.vf) + (.add.z.vf vf1 vf1 vf1 :mask #b1) + (.nop.vf) + (.nop.vf) + (.nop.vf) + (.div.vf Q vf0 vf1 :fsf #b11 :ftf #b0) + (.wait.vf) + (.mul.vf vf13 vf13 Q) + (.mul.vf vf14 vf14 Q) + (.mul.vf vf15 vf15 Q) + (.nop.vf) + (.nop.vf) + (.svf (&-> arg0 rvec quad) vf13) + (.svf (&-> arg0 uvec quad) vf14) + (.svf (&-> arg0 fvec quad) vf15) + arg0 + ) + ) + +;; definition for function matrix-3x3-normalize! +;; ERROR: Unsupported inline assembly instruction kind - [mula.s f2, f2] +;; ERROR: Unsupported inline assembly instruction kind - [madda.s f0, f0] +;; ERROR: Unsupported inline assembly instruction kind - [madd.s f0, f1, f1] +;; ERROR: Unsupported inline assembly instruction kind - [rsqrt.s f0, f2, f0] +(defun matrix-3x3-normalize! ((arg0 matrix) (arg1 matrix)) + "Unused." + (local-vars (f0-1 float) (f0-2 float)) + (rlet ((acc :class vf) + (Q :class vf) + (vf0 :class vf) + (vf10 :class vf) + (vf11 :class vf) + (vf12 :class vf) + (vf13 :class vf) + (vf14 :class vf) + (vf15 :class vf) + (vf16 :class vf) + ) + (init-vf0-vector) + (let ((f2-0 (-> arg1 rvec x)) + (f0-0 (-> arg1 rvec y)) + (f1-0 (-> arg1 rvec z)) + (v1-0 #x3f800000) + ) + (.lvf vf10 (&-> arg1 rvec quad)) + (.mula.s f2-0 f2-0) + (.lvf vf11 (&-> arg1 uvec quad)) + (let ((f2-1 (gpr->fpr v1-0))) + (.lvf vf12 (&-> arg1 fvec quad)) + (.madda.s f0-0 f0-0) + (.sub.w.vf vf13 vf0 vf0 :mask #b1000) + (.madd.s f0-1 f1-0 f1-0) + (.sub.w.vf vf14 vf0 vf0 :mask #b1000) + (.rsqrt.s f0-2 f2-1 f0-1) + ) + ) + (.sub.w.vf vf15 vf0 vf0 :mask #b1000) + (let ((v1-1 f0-2)) + (.mov vf16 v1-1) + ) + (.mul.x.vf vf13 vf10 vf16 :mask #b111) + (.outer.product.a.vf acc vf11 vf13) + (.outer.product.b.vf vf14 vf13 vf11 acc) + (.outer.product.a.vf acc vf13 vf14) + (.outer.product.b.vf vf14 vf14 vf13 acc) + (.mul.vf vf16 vf14 vf14 :mask #b111) + (.mul.x.vf acc vf0 vf16 :mask #b1000) + (.add.mul.y.vf acc vf0 vf16 acc :mask #b1000) + (.add.mul.z.vf vf16 vf0 vf16 acc :mask #b1000) + (.isqrt.vf Q vf0 vf16 :fsf #b11 :ftf #b11) + (.wait.vf) + (.mul.vf vf14 vf14 Q :mask #b111) + (.outer.product.a.vf acc vf13 vf14) + (.outer.product.b.vf vf15 vf14 vf13 acc) + (.svf (&-> arg0 rvec quad) vf13) + (.svf (&-> arg0 uvec quad) vf14) + (.svf (&-> arg0 fvec quad) vf15) + arg0 + ) + ) + +;; definition for function matrix-4x4-determinant +(defun matrix-4x4-determinant ((arg0 matrix)) + "Take the determinant of a 4x4 matrix, but this is wrong." + (let ((f15-0 (-> arg0 rvec x)) + (f14-0 (-> arg0 rvec y)) + (f10-0 (-> arg0 rvec z)) + (f2-0 (-> arg0 rvec w)) + (f9-0 (-> arg0 uvec x)) + (f6-0 (-> arg0 uvec y)) + (f3-0 (-> arg0 uvec z)) + (f11-0 (-> arg0 uvec w)) + (f5-0 (-> arg0 fvec x)) + (f1-0 (-> arg0 fvec y)) + (f8-0 (-> arg0 fvec z)) + (f13-0 (-> arg0 fvec w)) + (f0-0 (-> arg0 trans x)) + (f7-0 (-> arg0 trans y)) + (f4-0 (-> arg0 trans z)) + (f12-0 (-> arg0 trans w)) + ) + (- (+ (* f15-0 f6-0 f8-0 f12-0) + (* f15-0 f3-0 f13-0 f7-0) + (* f15-0 f11-0 f1-0 f4-0) + (* f14-0 f9-0 f13-0 f4-0) + (* f14-0 f3-0 f5-0 f4-0) + (* f14-0 f11-0 f8-0 f0-0) + (* f10-0 f9-0 f1-0 f12-0) + (* f10-0 f6-0 f13-0 f0-0) + (* f10-0 f11-0 f5-0 f7-0) + (* f2-0 f9-0 f1-0 f4-0) + (* f2-0 f6-0 f8-0 f0-0) + (* f2-0 f3-0 f5-0 f7-0) + ) + (+ (* f15-0 f6-0 f13-0 f4-0) + (* f15-0 f3-0 f1-0 f12-0) + (* f15-0 f11-0 f8-0 f7-0) + (* f14-0 f9-0 f8-0 f12-0) + (* f14-0 f3-0 f13-0 f0-0) + (* f14-0 f11-0 f5-0 f4-0) + (* f10-0 f9-0 f13-0 f7-0) + (* f10-0 f6-0 f5-0 f12-0) + (* f10-0 f11-0 f1-0 f0-0) + (* f2-0 f9-0 f8-0 f7-0) + (* f2-0 f6-0 f5-0 f4-0) + (* f2-0 f3-0 f1-0 f0-0) + ) + ) + ) + ) + +;; definition for function matrix-4x4-inverse-transpose! +(defun matrix-4x4-inverse-transpose! ((arg0 matrix) (arg1 matrix)) + "Invert and transpose an entire 4x4. I think has no restrictions, other than dst != src. Unused. +The answer is wrong. The determinant function is wrong." + (let ((f0-0 (matrix-4x4-determinant arg1))) + (let ((f9-0 (-> arg1 uvec y)) + (f2-0 (-> arg1 uvec z)) + (f5-0 (-> arg1 uvec w)) + (f3-0 (-> arg1 fvec y)) + (f6-0 (-> arg1 fvec z)) + (f10-0 (-> arg1 fvec w)) + (f4-0 (-> arg1 trans y)) + (f7-0 (-> arg1 trans z)) + (f1-0 (-> arg1 trans w)) + ) + (set! (-> arg0 rvec x) (/ (- (+ (* f9-0 f6-0 f1-0) (* f2-0 f10-0 f4-0) (* f5-0 f3-0 f7-0)) + (+ (* f9-0 f10-0 f7-0) (* f5-0 f6-0 f4-0) (* f2-0 f3-0 f1-0)) + ) + f0-0 + ) + ) + ) + (let ((f9-2 (-> arg1 uvec x)) + (f2-2 (-> arg1 uvec z)) + (f5-2 (-> arg1 uvec w)) + (f3-1 (-> arg1 fvec x)) + (f6-1 (-> arg1 fvec z)) + (f10-1 (-> arg1 fvec w)) + (f4-3 (-> arg1 trans x)) + (f7-2 (-> arg1 trans z)) + (f1-6 (-> arg1 trans w)) + ) + (set! (-> arg0 rvec y) (- (/ (- (+ (* f9-2 f6-1 f1-6) (* f2-2 f10-1 f4-3) (* f5-2 f3-1 f7-2)) + (+ (* f9-2 f10-1 f7-2) (* f5-2 f6-1 f4-3) (* f2-2 f3-1 f1-6)) + ) + f0-0 + ) + ) + ) + ) + (let ((f9-4 (-> arg1 uvec x)) + (f2-4 (-> arg1 uvec y)) + (f5-4 (-> arg1 uvec w)) + (f3-2 (-> arg1 fvec x)) + (f6-2 (-> arg1 fvec y)) + (f10-2 (-> arg1 fvec w)) + (f4-6 (-> arg1 trans x)) + (f7-4 (-> arg1 trans y)) + (f1-13 (-> arg1 trans w)) + ) + (set! (-> arg0 rvec z) (/ (- (+ (* f9-4 f6-2 f1-13) (* f2-4 f10-2 f4-6) (* f5-4 f3-2 f7-4)) + (+ (* f9-4 f10-2 f7-4) (* f5-4 f6-2 f4-6) (* f2-4 f3-2 f1-13)) + ) + f0-0 + ) + ) + ) + (let ((f9-6 (-> arg1 uvec x)) + (f2-6 (-> arg1 uvec y)) + (f5-6 (-> arg1 uvec z)) + (f3-3 (-> arg1 fvec x)) + (f6-3 (-> arg1 fvec y)) + (f10-3 (-> arg1 fvec z)) + (f4-9 (-> arg1 trans x)) + (f7-6 (-> arg1 trans y)) + (f1-19 (-> arg1 trans z)) + ) + (set! (-> arg0 rvec w) (- (/ (- (+ (* f9-6 f6-3 f1-19) (* f2-6 f10-3 f4-9) (* f5-6 f3-3 f7-6)) + (+ (* f9-6 f10-3 f7-6) (* f5-6 f6-3 f4-9) (* f2-6 f3-3 f1-19)) + ) + f0-0 + ) + ) + ) + ) + (let ((f9-8 (-> arg1 rvec y)) + (f2-8 (-> arg1 rvec z)) + (f5-8 (-> arg1 rvec w)) + (f3-4 (-> arg1 fvec y)) + (f6-4 (-> arg1 fvec z)) + (f10-4 (-> arg1 fvec w)) + (f4-12 (-> arg1 trans y)) + (f7-8 (-> arg1 trans z)) + (f1-26 (-> arg1 trans w)) + ) + (set! (-> arg0 uvec x) (- (/ (- (+ (* f9-8 f6-4 f1-26) (* f2-8 f10-4 f4-12) (* f5-8 f3-4 f7-8)) + (+ (* f9-8 f10-4 f7-8) (* f5-8 f6-4 f4-12) (* f2-8 f3-4 f1-26)) + ) + f0-0 + ) + ) + ) + ) + (let ((f9-10 (-> arg1 rvec x)) + (f2-10 (-> arg1 rvec z)) + (f5-10 (-> arg1 rvec w)) + (f3-5 (-> arg1 fvec x)) + (f6-5 (-> arg1 fvec z)) + (f10-5 (-> arg1 fvec w)) + (f4-15 (-> arg1 trans x)) + (f7-10 (-> arg1 trans z)) + (f1-33 (-> arg1 trans w)) + ) + (set! (-> arg0 uvec y) (/ (- (+ (* f9-10 f6-5 f1-33) (* f2-10 f10-5 f4-15) (* f5-10 f3-5 f7-10)) + (+ (* f9-10 f10-5 f7-10) (* f5-10 f6-5 f4-15) (* f2-10 f3-5 f1-33)) + ) + f0-0 + ) + ) + ) + (let ((f9-12 (-> arg1 rvec x)) + (f2-12 (-> arg1 rvec y)) + (f5-12 (-> arg1 rvec w)) + (f3-6 (-> arg1 fvec x)) + (f6-6 (-> arg1 fvec y)) + (f10-6 (-> arg1 fvec w)) + (f4-18 (-> arg1 trans x)) + (f7-12 (-> arg1 trans y)) + (f1-39 (-> arg1 trans w)) + ) + (set! (-> arg0 uvec z) (- (/ (- (+ (* f9-12 f6-6 f1-39) (* f2-12 f10-6 f4-18) (* f5-12 f3-6 f7-12)) + (+ (* f9-12 f10-6 f7-12) (* f5-12 f6-6 f4-18) (* f2-12 f3-6 f1-39)) + ) + f0-0 + ) + ) + ) + ) + (let ((f9-14 (-> arg1 rvec x)) + (f2-14 (-> arg1 rvec y)) + (f5-14 (-> arg1 rvec z)) + (f3-7 (-> arg1 fvec x)) + (f6-7 (-> arg1 fvec y)) + (f10-7 (-> arg1 fvec z)) + (f4-21 (-> arg1 trans x)) + (f7-14 (-> arg1 trans y)) + (f1-46 (-> arg1 trans z)) + ) + (set! (-> arg0 uvec w) (/ (- (+ (* f9-14 f6-7 f1-46) (* f2-14 f10-7 f4-21) (* f5-14 f3-7 f7-14)) + (+ (* f9-14 f10-7 f7-14) (* f5-14 f6-7 f4-21) (* f2-14 f3-7 f1-46)) + ) + f0-0 + ) + ) + ) + (let ((f9-16 (-> arg1 rvec y)) + (f2-16 (-> arg1 rvec z)) + (f5-16 (-> arg1 rvec w)) + (f3-8 (-> arg1 uvec y)) + (f6-8 (-> arg1 uvec z)) + (f10-8 (-> arg1 uvec w)) + (f4-24 (-> arg1 trans y)) + (f7-16 (-> arg1 trans z)) + (f1-52 (-> arg1 trans w)) + ) + (set! (-> arg0 fvec x) (/ (- (+ (* f9-16 f6-8 f1-52) (* f2-16 f10-8 f4-24) (* f5-16 f3-8 f7-16)) + (+ (* f9-16 f10-8 f7-16) (* f5-16 f6-8 f4-24) (* f2-16 f3-8 f1-52)) + ) + f0-0 + ) + ) + ) + (let ((f9-18 (-> arg1 rvec x)) + (f2-18 (-> arg1 rvec z)) + (f5-18 (-> arg1 rvec w)) + (f3-9 (-> arg1 uvec x)) + (f6-9 (-> arg1 uvec z)) + (f10-9 (-> arg1 uvec w)) + (f4-27 (-> arg1 trans x)) + (f7-18 (-> arg1 trans z)) + (f1-58 (-> arg1 trans w)) + ) + (set! (-> arg0 fvec y) (- (/ (- (+ (* f9-18 f6-9 f1-58) (* f2-18 f10-9 f4-27) (* f5-18 f3-9 f7-18)) + (+ (* f9-18 f10-9 f7-18) (* f5-18 f6-9 f4-27) (* f2-18 f3-9 f1-58)) + ) + f0-0 + ) + ) + ) + ) + (let ((f9-20 (-> arg1 rvec x)) + (f2-20 (-> arg1 rvec y)) + (f5-20 (-> arg1 rvec w)) + (f3-10 (-> arg1 uvec x)) + (f6-10 (-> arg1 uvec y)) + (f10-10 (-> arg1 uvec w)) + (f4-30 (-> arg1 trans x)) + (f7-20 (-> arg1 trans y)) + (f1-65 (-> arg1 trans w)) + ) + (set! (-> arg0 fvec z) (/ (- (+ (* f9-20 f6-10 f1-65) (* f2-20 f10-10 f4-30) (* f5-20 f3-10 f7-20)) + (+ (* f9-20 f10-10 f7-20) (* f5-20 f6-10 f4-30) (* f2-20 f3-10 f1-65)) + ) + f0-0 + ) + ) + ) + (let ((f9-22 (-> arg1 rvec x)) + (f2-22 (-> arg1 rvec y)) + (f5-22 (-> arg1 rvec z)) + (f3-11 (-> arg1 uvec x)) + (f6-11 (-> arg1 uvec y)) + (f10-11 (-> arg1 uvec z)) + (f4-33 (-> arg1 trans x)) + (f7-22 (-> arg1 trans y)) + (f1-71 (-> arg1 trans z)) + ) + (set! (-> arg0 fvec w) (- (/ (- (+ (* f9-22 f6-11 f1-71) (* f2-22 f10-11 f4-33) (* f5-22 f3-11 f7-22)) + (+ (* f9-22 f10-11 f7-22) (* f5-22 f6-11 f4-33) (* f2-22 f3-11 f1-71)) + ) + f0-0 + ) + ) + ) + ) + (let ((f9-24 (-> arg1 rvec y)) + (f2-24 (-> arg1 rvec z)) + (f5-24 (-> arg1 rvec w)) + (f3-12 (-> arg1 uvec y)) + (f6-12 (-> arg1 uvec z)) + (f10-12 (-> arg1 uvec w)) + (f4-36 (-> arg1 fvec y)) + (f7-24 (-> arg1 fvec z)) + (f1-78 (-> arg1 fvec w)) + ) + (set! (-> arg0 trans x) (- (/ (- (+ (* f9-24 f6-12 f1-78) (* f2-24 f10-12 f4-36) (* f5-24 f3-12 f7-24)) + (+ (* f9-24 f10-12 f7-24) (* f5-24 f6-12 f4-36) (* f2-24 f3-12 f1-78)) + ) + f0-0 + ) + ) + ) + ) + (let ((f9-26 (-> arg1 rvec x)) + (f2-26 (-> arg1 rvec z)) + (f5-26 (-> arg1 rvec w)) + (f3-13 (-> arg1 uvec x)) + (f6-13 (-> arg1 uvec z)) + (f10-13 (-> arg1 uvec w)) + (f4-39 (-> arg1 fvec x)) + (f7-26 (-> arg1 fvec z)) + (f1-85 (-> arg1 fvec w)) + ) + (set! (-> arg0 trans y) (/ (- (+ (* f9-26 f6-13 f1-85) (* f2-26 f10-13 f4-39) (* f5-26 f3-13 f7-26)) + (+ (* f9-26 f10-13 f7-26) (* f5-26 f6-13 f4-39) (* f2-26 f3-13 f1-85)) + ) + f0-0 + ) + ) + ) + (let ((f9-28 (-> arg1 rvec x)) + (f2-28 (-> arg1 rvec y)) + (f5-28 (-> arg1 rvec w)) + (f3-14 (-> arg1 uvec x)) + (f6-14 (-> arg1 uvec y)) + (f10-14 (-> arg1 uvec w)) + (f4-42 (-> arg1 fvec x)) + (f7-28 (-> arg1 fvec y)) + (f1-91 (-> arg1 fvec w)) + ) + (set! (-> arg0 trans z) (- (/ (- (+ (* f9-28 f6-14 f1-91) (* f2-28 f10-14 f4-42) (* f5-28 f3-14 f7-28)) + (+ (* f9-28 f10-14 f7-28) (* f5-28 f6-14 f4-42) (* f2-28 f3-14 f1-91)) + ) + f0-0 + ) + ) + ) + ) + (let ((f8-60 (-> arg1 rvec x)) + (f1-98 (-> arg1 rvec y)) + (f5-30 (-> arg1 rvec z)) + (f2-30 (-> arg1 uvec x)) + (f6-15 (-> arg1 uvec y)) + (f9-30 (-> arg1 uvec z)) + (f4-45 (-> arg1 fvec x)) + (f7-30 (-> arg1 fvec y)) + (f3-15 (-> arg1 fvec z)) + ) + (set! (-> arg0 trans w) (/ (- (+ (* f8-60 f6-15 f3-15) (* f1-98 f9-30 f4-45) (* f5-30 f2-30 f7-30)) + (+ (* f8-60 f9-30 f7-30) (* f5-30 f6-15 f4-45) (* f1-98 f2-30 f3-15)) + ) + f0-0 + ) + ) + ) + ) + arg0 + ) + +;; definition for function matrix-y-angle +(defun matrix-y-angle ((arg0 matrix)) + "If mat has its upper 3x3 as a rotation, gets the y axis rotation." + (let ((v1-0 (-> arg0 fvec))) + (atan (-> v1-0 x) (-> v1-0 z)) + ) + ) + +;; definition for function matrix->trans +(defun matrix->trans ((arg0 matrix) (arg1 vector)) + "Multiply xyz by 1/w." + (rlet ((Q :class vf) + (vf0 :class vf) + (vf2 :class vf) + ) + (init-vf0-vector) + (.lvf vf2 (&-> arg0 trans quad)) + (.div.vf Q vf0 vf2 :fsf #b11 :ftf #b11) + (.wait.vf) + (.mul.vf vf2 vf2 Q :mask #b111) + (.nop.vf) + (.nop.vf) + (.mov.vf vf2 vf0 :mask #b1000) + (.svf (&-> arg1 quad) vf2) + arg1 + ) + ) + +;; definition for function matrix<-trans +;; INFO: Used lq/sq +(defun matrix<-trans ((arg0 matrix) (arg1 vector)) + "Set the translation." + (set! (-> arg0 trans quad) (-> arg1 quad)) + arg0 + ) + +;; definition for function matrix->scale +(defun matrix->scale ((arg0 matrix) (arg1 vector)) + "Get the scale of a matrix." + (set! (-> arg1 x) (vector-length (-> arg0 rvec))) + (set! (-> arg1 y) (vector-length (-> arg0 uvec))) + (set! (-> arg1 z) (vector-length (-> arg0 fvec))) + (set! (-> arg1 w) 1.0) + arg1 + ) + +;; definition for function matrix<-scale +(defun matrix<-scale ((arg0 matrix) (arg1 vector)) + "Set the scale of a matrix by rescaling." + (vector-normalize! (-> arg0 rvec) (-> arg1 x)) + (vector-normalize! (-> arg0 uvec) (-> arg1 y)) + (vector-normalize! (-> arg0 fvec) (-> arg1 z)) + arg0 + ) + +;; definition for function matrix->quat +;; INFO: Used lq/sq +(defun matrix->quat ((arg0 matrix) (arg1 quaternion)) + "Convert matrix to quaternion, works for matrix with scale. +unlike matrix->quaternion." + (let ((s5-0 (new 'stack-no-clear 'matrix))) + (let* ((a2-0 arg0) + (v1-0 (-> a2-0 rvec quad)) + (a0-1 (-> a2-0 uvec quad)) + (a1-1 (-> a2-0 fvec quad)) + (a2-1 (-> a2-0 trans quad)) + ) + (set! (-> s5-0 rvec quad) v1-0) + (set! (-> s5-0 uvec quad) a0-1) + (set! (-> s5-0 fvec quad) a1-1) + (set! (-> s5-0 trans quad) a2-1) + ) + (vector-reset! (-> s5-0 trans)) + (vector-normalize! (-> s5-0 rvec) 1.0) + (vector-normalize! (-> s5-0 uvec) 1.0) + (vector-normalize! (-> s5-0 fvec) 1.0) + (matrix->quaternion arg1 s5-0) + ) + ) + +;; definition for function matrix<-quat +(defun matrix<-quat ((arg0 matrix) (arg1 quaternion)) + "Modify the rotation part of a transform." + (let ((s5-0 (matrix->scale arg0 (new 'stack-no-clear 'vector))) + (s4-1 (quaternion->matrix (new 'stack-no-clear 'matrix) arg1)) + ) + (vector-normalize-copy! (-> arg0 rvec) (-> s4-1 rvec) (-> s5-0 x)) + (vector-normalize-copy! (-> arg0 uvec) (-> s4-1 uvec) (-> s5-0 y)) + (vector-normalize-copy! (-> arg0 fvec) (-> s4-1 fvec) (-> s5-0 z)) + ) + (set! (-> arg0 rvec w) 0.0) + (set! (-> arg0 uvec w) 0.0) + (set! (-> arg0 fvec w) 0.0) + arg0 + ) + +;; definition for function matrix->transformq +;; INFO: Used lq/sq +(defun matrix->transformq ((arg0 transformq) (arg1 matrix)) + "Create a transformq from a matrix. Allowing scale, etc." + (rlet ((Q :class vf) + (vf0 :class vf) + (vf2 :class vf) + ) + (init-vf0-vector) + (.lvf vf2 (&-> arg1 trans quad)) + (.div.vf Q vf0 vf2 :fsf #b11 :ftf #b11) + (.wait.vf) + (.mul.vf vf2 vf2 Q :mask #b111) + (.nop.vf) + (.nop.vf) + (.mov.vf vf2 vf0 :mask #b1000) + (.svf (&-> arg0 trans quad) vf2) + (let ((s4-0 (new 'stack-no-clear 'matrix))) + (let* ((a2-0 arg1) + (v1-0 (-> a2-0 rvec quad)) + (a0-1 (-> a2-0 uvec quad)) + (a1-1 (-> a2-0 fvec quad)) + (a2-1 (-> a2-0 trans quad)) + ) + (set! (-> s4-0 rvec quad) v1-0) + (set! (-> s4-0 uvec quad) a0-1) + (set! (-> s4-0 fvec quad) a1-1) + (set! (-> s4-0 trans quad) a2-1) + ) + (vector-normalize! (-> s4-0 rvec) 1.0) + (vector-normalize! (-> s4-0 uvec) 1.0) + (vector-normalize! (-> s4-0 fvec) 1.0) + (vector-cross! (-> s4-0 fvec) (-> s4-0 rvec) (-> s4-0 uvec)) + (vector-cross! (-> s4-0 uvec) (-> s4-0 fvec) (-> s4-0 rvec)) + (matrix->quaternion (the-as quaternion (-> arg0 rot)) s4-0) + ) + (set-vector! + (-> arg0 scale) + (vector-length (-> arg1 rvec)) + (vector-length (-> arg1 uvec)) + (vector-length (-> arg1 fvec)) + 1.0 + ) + arg0 + ) + ) + +;; definition for method 9 of type matrix +;; ERROR: function was not converted to expressions. Cannot decompile. + +;; definition for function matrix-mirror! +(defun matrix-mirror! ((arg0 matrix) (arg1 vector) (arg2 vector)) + "Make a matrix that mirrors. Arguments are unclear." + (let ((f10-0 -2.0) + (f0-0 1.0) + ) + (let* ((f1-0 0.0) + (f9-0 (-> arg2 x)) + (f12-0 (-> arg2 y)) + (f11-0 (-> arg2 z)) + (f6-0 (-> arg1 x)) + (f5-0 (-> arg1 y)) + (f2-0 (-> arg1 z)) + (f3-2 (+ f0-0 (* f10-0 f9-0 f9-0))) + (f4-2 (+ f0-0 (* f10-0 f12-0 f12-0))) + (f7-2 (+ f0-0 (* f10-0 f11-0 f11-0))) + (f8-1 (* f10-0 f9-0 f12-0)) + (f9-2 (* f10-0 f9-0 f11-0)) + (f10-2 (* f10-0 f12-0 f11-0)) + (f11-4 (- f6-0 (+ (* f6-0 f3-2) (* f5-0 f8-1) (* f2-0 f9-2)))) + (f12-6 (- f5-0 (+ (* f6-0 f8-1) (* f5-0 f4-2) (* f2-0 f10-2)))) + (f2-1 (- f2-0 (+ (* f6-0 f9-2) (* f5-0 f10-2) (* f2-0 f7-2)))) + ) + (set! (-> arg0 rvec x) f3-2) + (set! (-> arg0 rvec y) f8-1) + (set! (-> arg0 rvec z) f9-2) + (set! (-> arg0 rvec w) f1-0) + (set! (-> arg0 uvec x) f8-1) + (set! (-> arg0 uvec y) f4-2) + (set! (-> arg0 uvec z) f10-2) + (set! (-> arg0 uvec w) f1-0) + (set! (-> arg0 fvec x) f9-2) + (set! (-> arg0 fvec y) f10-2) + (set! (-> arg0 fvec z) f7-2) + (set! (-> arg0 fvec w) f1-0) + (set! (-> arg0 trans x) f11-4) + (set! (-> arg0 trans y) f12-6) + (set! (-> arg0 trans z) f2-1) + ) + (set! (-> arg0 trans w) f0-0) + ) + arg0 + ) + + + + diff --git a/test/decompiler/reference/jak3/engine/math/quaternion-h_REF.gc b/test/decompiler/reference/jak3/engine/math/quaternion-h_REF.gc new file mode 100644 index 0000000000..663d685dd2 --- /dev/null +++ b/test/decompiler/reference/jak3/engine/math/quaternion-h_REF.gc @@ -0,0 +1,44 @@ +;;-*-Lisp-*- +(in-package goal) + +;; definition of type quaternion +(deftype quaternion (structure) + "Quaternion. Stored in xyzw order." + ((data float 4) + (x float :overlay-at (-> data 0)) + (y float :overlay-at (-> data 1)) + (z float :overlay-at (-> data 2)) + (w float :overlay-at (-> data 3)) + (vec vector :inline :overlay-at (-> data 0)) + (quad uint128 :overlay-at (-> data 0)) + ) + ) + +;; definition for method 3 of type quaternion +;; INFO: Used lq/sq +(defmethod inspect ((this quaternion)) + (when (not this) + (set! this this) + (goto cfg-4) + ) + (format #t "[~8x] ~A~%" this 'quaternion) + (format #t "~1Tdata[4] @ #x~X~%" (&-> this x)) + (format #t "~1Tx: ~f~%" (-> this x)) + (format #t "~1Ty: ~f~%" (-> this y)) + (format #t "~1Tz: ~f~%" (-> this z)) + (format #t "~1Tw: ~f~%" (-> this w)) + (format #t "~1Tvec: #~%" (&-> this x)) + (format #t "~1Tquad: ~D~%" (-> this quad)) + (label cfg-4) + this + ) + +;; definition for symbol *unity-quaternion*, type quaternion +(define *unity-quaternion* (new 'static 'quaternion :w 1.0)) + +;; failed to figure out what this is: +0 + + + + diff --git a/test/decompiler/reference/jak3/engine/math/quaternion_REF.gc b/test/decompiler/reference/jak3/engine/math/quaternion_REF.gc new file mode 100644 index 0000000000..66f7a29a46 --- /dev/null +++ b/test/decompiler/reference/jak3/engine/math/quaternion_REF.gc @@ -0,0 +1,1092 @@ +;;-*-Lisp-*- +(in-package goal) + +;; definition for method 3 of type quaternion +(defmethod inspect ((this quaternion)) + (format #t "[~8x] quaternion~%" this) + (format #t "~T[~F] [~F] [~F] [~F]~%" (-> this x) (-> this y) (-> this z) (-> this w)) + (let ((f0-5 (/ 1.0 (sqrtf (+ (* (-> this x) (-> this x)) (* (-> this y) (-> this y)) (* (-> this z) (-> this z)))))) + ) + (format #t "~Taxis: ~F ~F ~F" (* f0-5 (-> this x)) (* f0-5 (-> this y)) (* f0-5 (-> this z))) + ) + (let ((f0-9 (* 2.0 (acos (-> this w))))) + (format #t "~T~Tangle: (deg ~R)~%" f0-9) + ) + (format #t "~T(static-quaternion ~f ~f ~f ~f)~%" (-> this x) (-> this y) (-> this z) (-> this w)) + this + ) + +;; definition for function quaternion-axis-angle! +(defun quaternion-axis-angle! ((arg0 quaternion) (arg1 float) (arg2 float) (arg3 float) (arg4 float)) + "Construct a quaternion from an axis and angle. The axis should be normalized." + (let ((s5-0 (new 'stack-no-clear 'vector))) + (sincos! s5-0 (* 0.5 arg4)) + (let ((f0-2 (-> s5-0 x))) + (set! (-> arg0 x) (* arg1 f0-2)) + (set! (-> arg0 y) (* arg2 f0-2)) + (set! (-> arg0 z) (* arg3 f0-2)) + ) + (set! (-> arg0 w) (-> s5-0 y)) + ) + arg0 + ) + +;; definition for function quaternion-vector-angle! +(defun quaternion-vector-angle! ((arg0 quaternion) (arg1 vector) (arg2 float)) + "Construct a quaternion from an axis and angle. The axis should be normalized." + (let ((s5-0 (new 'stack-no-clear 'vector))) + (sincos! s5-0 (* 0.5 arg2)) + (let ((f0-2 (-> s5-0 x))) + (set! (-> arg0 x) (* (-> arg1 x) f0-2)) + (set! (-> arg0 y) (* (-> arg1 y) f0-2)) + (set! (-> arg0 z) (* (-> arg1 z) f0-2)) + ) + (set! (-> arg0 w) (-> s5-0 y)) + ) + arg0 + ) + +;; definition for function vector-angle<-quaternion! +(defun vector-angle<-quaternion! ((arg0 vector) (arg1 quaternion)) + "Convert the quaternion arg1 to axis-angle form and store in arg0 (angle goes in w)" + (let* ((f0-0 1.0) + (f1-0 1.0) + (f2-0 (-> arg1 w)) + (f30-0 (/ f0-0 (sqrtf (- f1-0 (* f2-0 f2-0))))) + (f0-3 (* 2.0 (acos-rad (-> arg1 w)))) + ) + (set! (-> arg0 x) (* (-> arg1 x) f30-0)) + (set! (-> arg0 y) (* (-> arg1 y) f30-0)) + (set! (-> arg0 z) (* (-> arg1 z) f30-0)) + (set! (-> arg0 w) f0-3) + ) + arg0 + ) + +;; definition for function quaternion-look-at! +;; INFO: Used lq/sq +(defun quaternion-look-at! ((arg0 quaternion) (arg1 vector) (arg2 vector)) + "Look along arg1, with arg2 as up." + (let ((s5-0 (new 'stack-no-clear 'matrix))) + (vector-cross! (-> s5-0 rvec) arg2 arg1) + (vector-cross! (-> s5-0 uvec) arg1 (-> s5-0 rvec)) + (set! (-> s5-0 fvec quad) (-> arg1 quad)) + (quaternion-normalize! (matrix->quaternion arg0 s5-0)) + ) + ) + +;; definition for function quaternion-zero! +;; INFO: Used lq/sq +(defun quaternion-zero! ((arg0 quaternion)) + "Set quaternion to all 0's." + (set! (-> arg0 quad) (the-as uint128 0)) + arg0 + ) + +;; definition for function quaternion-identity! +;; INFO: Used lq/sq +(defun quaternion-identity! ((arg0 quaternion)) + "Set quaternion to 0,0,0,1 (identity)." + (set! (-> arg0 quad) (the-as uint128 0)) + (set! (-> arg0 w) 1.0) + arg0 + ) + +;; definition for function quaternion-i! +;; INFO: Used lq/sq +(defun quaternion-i! ((arg0 quaternion)) + "Create unit i quaternion." + (set! (-> arg0 quad) (the-as uint128 0)) + (set! (-> arg0 x) 1.0) + arg0 + ) + +;; definition for function quaternion-j! +;; INFO: Used lq/sq +(defun quaternion-j! ((arg0 quaternion)) + "Create unit j quaternion." + (set! (-> arg0 quad) (the-as uint128 0)) + (set! (-> arg0 y) 1.0) + arg0 + ) + +;; definition for function quaternion-k! +;; INFO: Used lq/sq +(defun quaternion-k! ((arg0 quaternion)) + "Create unit k quaternion." + (set! (-> arg0 quad) (the-as uint128 0)) + (set! (-> arg0 z) 1.0) + arg0 + ) + +;; definition for function quaternion-copy! +;; INFO: Used lq/sq +(defun quaternion-copy! ((arg0 quaternion) (arg1 quaternion)) + "Set arg0 = arg1." + (set! (-> arg0 quad) (-> arg1 quad)) + arg0 + ) + +;; definition for function quaternion-set! +(defun quaternion-set! ((arg0 quaternion) (arg1 float) (arg2 float) (arg3 float) (arg4 float)) + "Set arg0 = [arg1, arg2, arg3, arg4]." + (set! (-> arg0 x) arg1) + (set! (-> arg0 y) arg2) + (set! (-> arg0 z) arg3) + (set! (-> arg0 w) arg4) + arg0 + ) + +;; definition for function quaternion+! +(defun quaternion+! ((arg0 quaternion) (arg1 quaternion) (arg2 quaternion)) + "Add quaternions as vectors." + (rlet ((vf1 :class vf) + (vf2 :class vf) + ) + (.lvf vf1 (&-> arg1 quad)) + (.lvf vf2 (&-> arg2 quad)) + (.add.vf vf1 vf1 vf2) + (.svf (&-> arg0 quad) vf1) + arg0 + ) + ) + +;; definition for function quaternion-! +(defun quaternion-! ((arg0 quaternion) (arg1 quaternion) (arg2 quaternion)) + "Subtract quaternions as vectors." + (rlet ((vf1 :class vf) + (vf2 :class vf) + ) + (.lvf vf1 (&-> arg1 quad)) + (.lvf vf2 (&-> arg2 quad)) + (.sub.vf vf1 vf1 vf2) + (.svf (&-> arg0 quad) vf1) + arg0 + ) + ) + +;; definition for function quaternion-negate! +;; ERROR: Bad vector register dependency: vf2 +(defun quaternion-negate! ((arg0 quaternion) (arg1 quaternion)) + "Set arg0 = -arg1." + (rlet ((vf1 :class vf) + (vf2 :class vf) + ) + (.lvf vf1 (&-> arg1 quad)) + (.sub.vf vf2 vf2 vf2) + (.sub.vf vf1 vf2 vf1) + (.svf (&-> arg0 quad) vf1) + arg0 + ) + ) + +;; definition for function quaternion-conjugate! +;; ERROR: Bad vector register dependency: vf2 +(defun quaternion-conjugate! ((arg0 quaternion) (arg1 quaternion)) + "Set arg0 to the conjugate of arg1 (negate only ijk). +If arg1 is normalized, this is equivalent to the inverse +NOTE: this gives you the inverse rotation." + (rlet ((vf1 :class vf) + (vf2 :class vf) + ) + (.lvf vf1 (&-> arg1 quad)) + (.sub.vf vf2 vf2 vf2) + (.sub.vf vf2 vf2 vf1 :mask #b111) + (.add.vf vf2 vf2 vf1 :mask #b1000) + (.svf (&-> arg0 quad) vf2) + arg0 + ) + ) + +;; definition for function quaternion-float*! +(defun quaternion-float*! ((arg0 quaternion) (arg1 quaternion) (arg2 float)) + "Multiply each element." + (rlet ((vf1 :class vf) + (vf2 :class vf) + ) + (.lvf vf1 (&-> arg1 quad)) + (.mov vf2 arg2) + (.mul.x.vf vf1 vf1 vf2) + (.svf (&-> arg0 quad) vf1) + arg0 + ) + ) + +;; definition for function quaternion-float/! +(defun quaternion-float/! ((arg0 quaternion) (arg1 quaternion) (arg2 float)) + "Divide each element." + (let ((f0-1 (/ 1.0 arg2))) + (quaternion-float*! arg0 arg1 f0-1) + ) + arg0 + ) + +;; definition for function quaternion-norm2 +(defun quaternion-norm2 ((arg0 quaternion)) + "Get the squared norm of a quaternion." + (local-vars (v0-0 float)) + (rlet ((acc :class vf) + (vf0 :class vf) + (vf1 :class vf) + ) + (init-vf0-vector) + (.lvf vf1 (&-> arg0 quad)) + (.mul.vf vf1 vf1 vf1) + (.add.z.vf acc vf1 vf1 :mask #b1000) + (.add.mul.y.vf acc vf0 vf1 acc :mask #b1000) + (.add.mul.x.vf vf1 vf0 vf1 acc :mask #b1000) + (.add.w.vf vf1 vf0 vf1) + (.mov v0-0 vf1) + v0-0 + ) + ) + +;; definition for function quaternion-norm +(defun quaternion-norm ((arg0 quaternion)) + "Get the norm of a quaternion." + (local-vars (v1-1 float)) + (rlet ((acc :class vf) + (vf0 :class vf) + (vf1 :class vf) + ) + (init-vf0-vector) + (.lvf vf1 (&-> arg0 quad)) + (.mul.vf vf1 vf1 vf1) + (.add.z.vf acc vf1 vf1 :mask #b1000) + (.add.mul.y.vf acc vf0 vf1 acc :mask #b1000) + (.add.mul.x.vf vf1 vf0 vf1 acc :mask #b1000) + (.add.w.vf vf1 vf0 vf1) + (.mov v1-1 vf1) + (sqrtf v1-1) + ) + ) + +;; definition for function quaternion-normalize! +(defun quaternion-normalize! ((arg0 quaternion)) + "Normalize a quaternion." + (rlet ((acc :class vf) + (Q :class vf) + (vf0 :class vf) + (vf1 :class vf) + (vf2 :class vf) + ) + (init-vf0-vector) + (.lvf vf1 (&-> arg0 quad)) + (.mul.vf vf2 vf1 vf1) + (.add.z.vf acc vf2 vf2 :mask #b1000) + (.add.mul.y.vf acc vf0 vf2 acc :mask #b1000) + (.add.mul.x.vf vf2 vf0 vf2 acc :mask #b1000) + (.isqrt.vf Q vf0 vf2 :fsf #b11 :ftf #b11) + (.wait.vf) + (.mul.vf vf2 vf1 Q) + (.nop.vf) + (.nop.vf) + (.svf (&-> arg0 quad) vf2) + arg0 + ) + ) + +;; definition for function quaternion-inverse! +;; ERROR: Bad vector register dependency: vf3 +(defun quaternion-inverse! ((arg0 quaternion) (arg1 quaternion)) + "Invert a quaternion. The inverse will satisfy q * q^-1 = identity, even if q is not normalized. +If your quaternion is normalized, it is faster/more accurate to do quaternion-conjugate!" + (rlet ((acc :class vf) + (Q :class vf) + (vf0 :class vf) + (vf1 :class vf) + (vf2 :class vf) + (vf3 :class vf) + ) + (init-vf0-vector) + (.lvf vf1 (&-> arg1 quad)) + (.mul.vf vf2 vf1 vf1) + (.sub.vf vf3 vf3 vf3) + (.add.z.vf acc vf2 vf2 :mask #b1000) + (.add.mul.y.vf acc vf0 vf2 acc :mask #b1000) + (.add.mul.x.vf vf2 vf0 vf2 acc :mask #b1000) + (.sub.vf vf3 vf3 vf1 :mask #b111) + (.div.vf Q vf0 vf2 :fsf #b11 :ftf #b11) + (.add.vf vf3 vf3 vf1 :mask #b1000) + (.wait.vf) + (.mul.vf vf3 vf3 Q) + (.nop.vf) + (.nop.vf) + (.svf (&-> arg0 quad) vf3) + arg0 + ) + ) + +;; definition for function quaternion-dot +(defun quaternion-dot ((arg0 quaternion) (arg1 quaternion)) + "Treat quaternions as vectors and take the dot product." + (local-vars (v0-0 float)) + (rlet ((acc :class vf) + (vf0 :class vf) + (vf1 :class vf) + (vf2 :class vf) + ) + (init-vf0-vector) + (.lvf vf1 (&-> arg0 quad)) + (.lvf vf2 (&-> arg1 quad)) + (.mul.vf vf1 vf1 vf2) + (.add.z.vf acc vf1 vf1 :mask #b1000) + (.add.mul.y.vf acc vf0 vf1 acc :mask #b1000) + (.add.mul.x.vf vf1 vf0 vf1 acc :mask #b1000) + (.add.w.vf vf1 vf0 vf1) + (.mov v0-0 vf1) + v0-0 + ) + ) + +;; definition for function quaternion*! +(defun quaternion*! ((arg0 quaternion) (arg1 quaternion) (arg2 quaternion)) + "Real quaternion multiplication." + (rlet ((acc :class vf) + (vf0 :class vf) + (vf1 :class vf) + (vf2 :class vf) + (vf3 :class vf) + (vf4 :class vf) + ) + (init-vf0-vector) + (.lvf vf1 (&-> arg1 quad)) + (.lvf vf2 (&-> arg2 quad)) + (.sub.vf vf4 vf0 vf0 :mask #b1000) + (.mul.vf vf3 vf1 vf2) + (.outer.product.a.vf acc vf1 vf2) + (.outer.product.b.vf vf4 vf2 vf1 acc) + (.mul.w.vf acc vf1 vf2) + (.add.mul.w.vf acc vf2 vf1 acc) + (.sub.mul.w.vf acc vf0 vf3 acc :mask #b1000) + (.sub.mul.z.vf acc vf0 vf3 acc :mask #b1000) + (.sub.mul.y.vf acc vf0 vf3 acc :mask #b1000) + (.sub.mul.x.vf acc vf0 vf3 acc :mask #b1000) + (.add.mul.w.vf vf1 vf4 vf0 acc) + (.svf (&-> arg0 quad) vf1) + arg0 + ) + ) + +;; definition for function quaternion-right-mult-matrix! +(defun quaternion-right-mult-matrix! ((arg0 matrix) (arg1 quaternion)) + "Place quaternion coefficients into a matrix. +You can convert a quaternion to a matrix by taking the product of this +right-mult and left-mult matrix, but this method is not used. +Instead, quaternion->matrix is a more efficient implementation." + (let ((f3-0 (-> arg1 x)) + (f2-0 (-> arg1 y)) + (f1-0 (-> arg1 z)) + (f0-0 (-> arg1 w)) + ) + (set! (-> arg0 rvec x) f0-0) + (set! (-> arg0 rvec y) f1-0) + (set! (-> arg0 rvec z) (- f2-0)) + (set! (-> arg0 rvec w) f3-0) + (set! (-> arg0 uvec x) (- f1-0)) + (set! (-> arg0 uvec y) f0-0) + (set! (-> arg0 uvec z) f3-0) + (set! (-> arg0 uvec w) f2-0) + (set! (-> arg0 fvec x) f2-0) + (set! (-> arg0 fvec y) (- f3-0)) + (set! (-> arg0 fvec z) f0-0) + (set! (-> arg0 fvec w) f1-0) + (set! (-> arg0 trans x) (- f3-0)) + (set! (-> arg0 trans y) (- f2-0)) + (set! (-> arg0 trans z) (- f1-0)) + (set! (-> arg0 trans w) f0-0) + ) + arg0 + ) + +;; definition for function quaternion-left-mult-matrix! +(defun quaternion-left-mult-matrix! ((arg0 matrix) (arg1 quaternion)) + "Place quaternion coefficients into a matrix. Unused." + (let ((f2-0 (-> arg1 x)) + (f1-0 (-> arg1 y)) + (f0-0 (-> arg1 z)) + ) + (let ((f3-0 (-> arg1 w))) + (set! (-> arg0 rvec x) f2-0) + (set! (-> arg0 rvec y) f3-0) + (set! (-> arg0 rvec z) (- f0-0)) + (set! (-> arg0 rvec w) f1-0) + (set! (-> arg0 uvec x) f1-0) + (set! (-> arg0 uvec y) f0-0) + (set! (-> arg0 uvec z) f3-0) + (set! (-> arg0 uvec w) (- f3-0)) + (set! (-> arg0 fvec x) f0-0) + (set! (-> arg0 fvec y) (- f1-0)) + (set! (-> arg0 fvec z) f2-0) + (set! (-> arg0 fvec w) f3-0) + (set! (-> arg0 trans x) f3-0) + ) + (set! (-> arg0 trans y) (- f2-0)) + (set! (-> arg0 trans z) (- f1-0)) + (set! (-> arg0 trans w) (- f0-0)) + ) + arg0 + ) + +;; definition for function quaternion->matrix +(defun quaternion->matrix ((arg0 matrix) (arg1 quaternion)) + "Convert quaternion to matrix." + (rlet ((acc :class vf) + (vf0 :class vf) + (vf1 :class vf) + (vf2 :class vf) + (vf3 :class vf) + (vf4 :class vf) + (vf5 :class vf) + ) + (init-vf0-vector) + (.lvf vf1 (&-> arg1 quad)) + (.add.vf vf5 vf1 vf1) + (.add.w.vf vf2 vf0 vf1 :mask #b1) + (.add.z.vf vf2 vf0 vf1 :mask #b10) + (.sub.y.vf vf2 vf0 vf1 :mask #b100) + (.sub.w.vf vf2 vf0 vf0 :mask #b1000) + (.sub.z.vf vf3 vf0 vf1 :mask #b1) + (.add.w.vf vf3 vf0 vf1 :mask #b10) + (.add.x.vf vf3 vf0 vf1 :mask #b100) + (.sub.w.vf vf3 vf0 vf0 :mask #b1000) + (.add.y.vf vf4 vf0 vf1 :mask #b1) + (.sub.x.vf vf4 vf0 vf1 :mask #b10) + (.add.w.vf vf4 vf0 vf1 :mask #b100) + (.sub.w.vf vf4 vf0 vf0 :mask #b1000) + (.outer.product.a.vf acc vf5 vf2) + (.outer.product.b.vf vf2 vf2 vf5 acc) + (.outer.product.a.vf acc vf5 vf3) + (.outer.product.b.vf vf3 vf3 vf5 acc) + (.outer.product.a.vf acc vf5 vf4) + (.outer.product.b.vf vf4 vf4 vf5 acc) + (.add.w.vf vf2 vf2 vf0 :mask #b1) + (.add.w.vf vf3 vf3 vf0 :mask #b10) + (.add.w.vf vf4 vf4 vf0 :mask #b100) + (.svf (&-> arg0 trans quad) vf0) + (.svf (&-> arg0 rvec quad) vf2) + (.svf (&-> arg0 uvec quad) vf3) + (.svf (&-> arg0 fvec quad) vf4) + arg0 + ) + ) + +;; definition for function quaternion->matrix-2 +;; ERROR: function was not converted to expressions. Cannot decompile. + +;; definition for function matrix->quaternion +(defun matrix->quaternion ((arg0 quaternion) (arg1 matrix)) + "Convert a rotation matrix to a quaternion." + (let ((f0-2 (+ (-> arg1 rvec x) (-> arg1 uvec y) (-> arg1 fvec z)))) + (cond + ((< 0.0 f0-2) + (let ((f0-4 (sqrtf (+ 1.0 f0-2)))) + (set! (-> arg0 w) (* 0.5 f0-4)) + (let ((f0-5 (/ 0.5 f0-4))) + (set! (-> arg0 x) (* f0-5 (- (-> arg1 uvec z) (-> arg1 fvec y)))) + (set! (-> arg0 y) (* f0-5 (- (-> arg1 fvec x) (-> arg1 rvec z)))) + (set! (-> arg0 z) (* f0-5 (- (-> arg1 rvec y) (-> arg1 uvec x)))) + ) + ) + ) + (else + (let ((a2-0 0) + (a3-0 1) + (v1-4 2) + ) + (when (< (-> arg1 rvec x) (-> arg1 uvec y)) + (set! a2-0 1) + (set! a3-0 2) + (set! v1-4 0) + ) + (when (< (-> (the-as (pointer float) (+ (+ (* a2-0 4) (* a2-0 16)) (the-as int arg1)))) (-> arg1 fvec z)) + (set! a2-0 2) + (set! a3-0 0) + (set! v1-4 1) + ) + (let ((f0-12 + (sqrtf + (+ (- 1.0 + (+ (-> (the-as (pointer float) (+ (+ (* a3-0 4) (* a3-0 16)) (the-as int arg1)))) + (-> (the-as (pointer float) (+ (+ (* v1-4 4) (* v1-4 16)) (the-as int arg1)))) + ) + ) + (-> (the-as (pointer float) (+ (+ (* a2-0 4) (* a2-0 16)) (the-as int arg1)))) + ) + ) + ) + ) + (set! (-> arg0 data a2-0) (* 0.5 f0-12)) + (if (!= f0-12 0.0) + (set! f0-12 (/ 0.5 f0-12)) + ) + (set! (-> arg0 w) + (* (- (-> (the-as (pointer float) (+ (+ (* v1-4 4) (* a3-0 16)) (the-as int arg1)))) + (-> (the-as (pointer float) (+ (+ (* a3-0 4) (* v1-4 16)) (the-as int arg1)))) + ) + f0-12 + ) + ) + (set! (-> arg0 data a3-0) + (* (+ (-> (the-as (pointer float) (+ (+ (* a3-0 4) (* a2-0 16)) (the-as int arg1)))) + (-> (the-as (pointer float) (+ (+ (* a2-0 4) (* a3-0 16)) (the-as int arg1)))) + ) + f0-12 + ) + ) + (set! (-> arg0 data v1-4) + (* (+ (-> (the-as (pointer float) (+ (+ (* v1-4 4) (* a2-0 16)) (the-as int arg1)))) + (-> (the-as (pointer float) (+ (+ (* a2-0 4) (* v1-4 16)) (the-as int arg1)))) + ) + f0-12 + ) + ) + ) + ) + ) + ) + ) + arg0 + ) + +;; definition for function matrix-with-scale->quaternion +;; INFO: Used lq/sq +(defun matrix-with-scale->quaternion ((arg0 quaternion) (arg1 matrix)) + "Convert a matrix with a rotation and scale into a quaternion (just the rotation)." + (local-vars (a1-4 float)) + (rlet ((vf1 :class vf) + (vf2 :class vf) + (vf3 :class vf) + (vf4 :class vf) + (vf5 :class vf) + (vf6 :class vf) + (vf7 :class vf) + ) + (let ((v1-0 (new 'stack-no-clear 'matrix))) + (set! (-> v1-0 rvec quad) (the-as uint128 0)) + (set! (-> v1-0 uvec quad) (the-as uint128 0)) + (set! (-> v1-0 fvec quad) (the-as uint128 0)) + (set! (-> v1-0 trans quad) (the-as uint128 0)) + (let* ((f0-1 (vector-dot (-> arg1 rvec) (-> arg1 rvec))) + (f1-1 (vector-dot (-> arg1 uvec) (-> arg1 uvec))) + (f2-1 (vector-dot (-> arg1 fvec) (-> arg1 fvec))) + (f0-3 (/ 1.0 (sqrtf f0-1))) + (f1-3 (/ 1.0 (sqrtf f1-1))) + (f2-3 (/ 1.0 (sqrtf f2-1))) + ) + (.lvf vf1 (&-> arg1 rvec quad)) + (.lvf vf2 (&-> arg1 uvec quad)) + (.lvf vf3 (&-> arg1 fvec quad)) + (.lvf vf4 (&-> arg1 trans quad)) + (let ((a1-1 f0-3)) + (.mov vf5 a1-1) + ) + (let ((a1-2 f1-3)) + (.mov vf6 a1-2) + ) + (let ((a1-3 f2-3)) + (.mov vf7 a1-3) + ) + ) + (.mul.x.vf vf1 vf1 vf5) + (.mul.x.vf vf2 vf2 vf6) + (.mul.x.vf vf3 vf3 vf7) + (.svf (&-> v1-0 rvec quad) vf1) + (.svf (&-> v1-0 uvec quad) vf2) + (.svf (&-> v1-0 fvec quad) vf3) + (.svf (&-> v1-0 trans quad) vf4) + (.mov a1-4 vf4) + (matrix->quaternion arg0 v1-0) + ) + ) + ) + +;; definition for function quaternion-vector-len +(defun quaternion-vector-len ((arg0 quaternion)) + "Assuming quaternion is normalized, get the length of the xyz part." + (let ((f0-0 1.0) + (f1-0 (-> arg0 w)) + ) + (sqrtf (- f0-0 (* f1-0 f1-0))) + ) + ) + +;; definition for function quaternion-log! +(defun quaternion-log! ((arg0 quaternion) (arg1 quaternion)) + "Take the log of a quaternion. Unused." + (cond + ((= (-> arg1 w) 0.0) + (set! (-> arg0 x) (* 1.5707963 (-> arg1 x))) + (set! (-> arg0 y) (* 1.5707963 (-> arg1 y))) + (set! (-> arg0 z) (* 1.5707963 (-> arg1 z))) + ) + (else + (let* ((f30-0 (quaternion-vector-len arg1)) + (f0-9 (/ (atan2-rad (-> arg1 w) f30-0) f30-0)) + ) + (set! (-> arg0 x) (* (-> arg1 x) f0-9)) + (set! (-> arg0 y) (* (-> arg1 y) f0-9)) + (set! (-> arg0 z) (* (-> arg1 z) f0-9)) + ) + ) + ) + arg0 + ) + +;; definition for function quaternion-exp! +(defun quaternion-exp! ((arg0 quaternion) (arg1 quaternion)) + "Quaternion exponentiation. Unused." + (let ((f30-0 (vector-length (the-as vector arg1)))) + (cond + ((= f30-0 0.0) + (set! (-> arg0 x) 0.0) + (set! (-> arg0 y) 0.0) + (set! (-> arg0 z) 0.0) + (set! (-> arg0 w) 1.0) + ) + (else + (let ((s5-0 (new 'stack-no-clear 'vector))) + (sincos-rad! s5-0 f30-0) + (let ((f0-6 (/ (-> s5-0 x) f30-0))) + (set! (-> arg0 x) (* (-> arg1 x) f0-6)) + (set! (-> arg0 y) (* (-> arg1 y) f0-6)) + (set! (-> arg0 z) (* (-> arg1 z) f0-6)) + ) + (set! (-> arg0 w) (-> s5-0 y)) + ) + ) + ) + ) + arg0 + ) + +;; definition for function quaternion-slerp! +(defun quaternion-slerp! ((arg0 quaternion) (arg1 quaternion) (arg2 quaternion) (arg3 float)) + "Real quaternion slerp. Spherical-linear interpolation is a nice way to interpolate +between quaternions." + (local-vars (v1-15 float)) + (rlet ((acc :class vf) + (vf1 :class vf) + (vf2 :class vf) + (vf3 :class vf) + (vf4 :class vf) + ) + (let ((f0-0 (quaternion-dot arg1 arg2)) + (f30-0 1.0) + ) + (when (< f0-0 0.0) + (set! f0-0 (- f0-0)) + (set! f30-0 -1.0) + ) + (cond + ((< (- 1.0 f0-0) 0.0001) + (let ((v1-7 (- 1.0 arg3))) + (.mov vf1 v1-7) + ) + (let ((v1-8 (* arg3 f30-0))) + (.mov vf2 v1-8) + ) + (.lvf vf3 (&-> arg1 quad)) + (.lvf vf4 (&-> arg2 quad)) + (.mul.x.vf acc vf3 vf1) + (.add.mul.x.vf vf3 vf4 vf2 acc) + (.svf (&-> arg0 quad) vf3) + (quaternion-normalize! arg0) + ) + (else + (let* ((f1-4 1.0) + (f2-1 f0-0) + (f1-6 (sqrtf (- f1-4 (* f2-1 f2-1)))) + (f0-6 (/ (- f1-6 f0-0) (+ f1-6 f0-0))) + (f28-0 (/ 1.0 f1-6)) + ) + (let ((f0-7 (atan-series-rad f0-6)) + (s2-0 (new 'stack-no-clear 'vector)) + ) + (set! (-> s2-0 x) (* (- 1.0 arg3) f0-7)) + (set! (-> s2-0 y) (* arg3 f0-7 f30-0)) + (vector-sin-rad! s2-0 s2-0) + (.lvf vf1 (&-> s2-0 quad)) + ) + (let ((v1-14 f28-0)) + (.mov vf2 v1-14) + ) + ) + (.mul.x.vf vf1 vf1 vf2) + (.lvf vf3 (&-> arg1 quad)) + (.lvf vf4 (&-> arg2 quad)) + (.mul.x.vf acc vf3 vf1) + (.add.mul.y.vf vf3 vf4 vf1 acc) + (.svf (&-> arg0 quad) vf3) + (.mov v1-15 vf3) + ) + ) + ) + arg0 + ) + ) + +;; definition for function quaternion-pseudo-slerp! +(defun quaternion-pseudo-slerp! ((arg0 quaternion) (arg1 quaternion) (arg2 quaternion) (arg3 float)) + "This is a bad interpolation between quaternions. It lerps then normalizes. +It will behave extremely poorly for 180 rotations. +It is unused." + (rlet ((acc :class vf) + (vf1 :class vf) + (vf2 :class vf) + (vf3 :class vf) + (vf4 :class vf) + ) + (let ((f1-0 (quaternion-dot arg1 arg2)) + (f0-0 1.0) + ) + (when (< f1-0 0.0) + (- f1-0) + (set! f0-0 -1.0) + ) + (let ((v1-5 (- 1.0 arg3))) + (.mov vf1 v1-5) + ) + (let ((v1-6 (* arg3 f0-0))) + (.mov vf2 v1-6) + ) + ) + (.lvf vf3 (&-> arg1 quad)) + (.lvf vf4 (&-> arg2 quad)) + (.mul.x.vf acc vf3 vf1) + (.add.mul.x.vf vf3 vf4 vf2 acc) + (.svf (&-> arg0 quad) vf3) + (quaternion-normalize! arg0) + arg0 + ) + ) + +;; definition for function quaternion-pseudo-seek +(defun quaternion-pseudo-seek ((arg0 quaternion) (arg1 quaternion) (arg2 quaternion) (arg3 float)) + "Seek one quaternion toward another. Not using real slerp, so this is only good if the quaternions +are pretty similar." + (let ((s3-0 (new 'stack-no-clear 'quaternion))) + (let ((s5-0 (new 'stack-no-clear 'quaternion))) + (quaternion-copy! s3-0 arg2) + (if (< (quaternion-dot s3-0 arg1) 0.0) + (quaternion-negate! s3-0 s3-0) + ) + (quaternion-! s5-0 s3-0 arg1) + (let ((f0-1 (quaternion-norm2 s5-0)) + (f1-1 arg3) + ) + (if (< (* f1-1 f1-1) f0-1) + (quaternion-float*! s5-0 s5-0 (/ arg3 (sqrtf f0-1))) + ) + ) + (quaternion+! s3-0 arg1 s5-0) + ) + (quaternion-normalize! s3-0) + (quaternion-copy! arg0 s3-0) + ) + ) + +;; definition for function quaternion-smooth-seek! +(defun quaternion-smooth-seek! ((arg0 quaternion) (arg1 quaternion) (arg2 quaternion) (arg3 float)) + "Another hacky rotation interpolation." + (let ((gp-0 (new 'stack-no-clear 'quaternion))) + (quaternion-copy! (the-as quaternion (&-> gp-0 x)) arg2) + (if (< (quaternion-dot (the-as quaternion (&-> gp-0 x)) arg1) 0.0) + (quaternion-negate! (the-as quaternion (&-> gp-0 x)) (the-as quaternion (&-> gp-0 x))) + ) + (quaternion-! (&+ gp-0 16) (the-as quaternion (&-> gp-0 x)) arg1) + (quaternion-float*! (&+ gp-0 16) (&+ gp-0 16) (fmin 1.0 arg3)) + (quaternion+! (the-as quaternion (&-> gp-0 x)) arg1 (&+ gp-0 16)) + (quaternion-normalize! (the-as quaternion (&-> gp-0 x))) + (quaternion-copy! arg0 (the-as quaternion (&-> gp-0 x))) + ) + ) + +;; definition for function quaternion-zxy! +(defun quaternion-zxy! ((arg0 quaternion) (arg1 vector)) + "Make a quaternion from a sequence of z, x, y axis rotations." + (rlet ((acc :class vf) + (vf0 :class vf) + (vf1 :class vf) + (vf2 :class vf) + (vf3 :class vf) + (vf4 :class vf) + (vf5 :class vf) + (vf6 :class vf) + (vf7 :class vf) + ) + (init-vf0-vector) + (let ((s4-0 (new 'stack-no-clear 'vector)) + (gp-0 (new 'stack-no-clear 'vector)) + (s5-0 (new 'stack-no-clear 'vector)) + ) + (vector-rad<-vector-deg/2! s4-0 arg1) + (vector-sincos-rad! gp-0 s5-0 s4-0) + (.lvf vf1 (&-> gp-0 quad)) + (.lvf vf2 (&-> s5-0 quad)) + ) + (.mul.x.vf vf4 vf0 vf1 :mask #b1000) + (.add.vf vf4 vf0 vf2 :mask #b111) + (.sub.vf vf4 vf0 vf4 :mask #b110) + (.add.vf vf3 vf0 vf1 :mask #b111) + (.mul.x.vf vf3 vf0 vf2 :mask #b1000) + (.outer.product.a.vf acc vf1 vf1) + (.outer.product.b.vf vf6 vf0 vf0 acc) + (.outer.product.a.vf acc vf2 vf2) + (.outer.product.b.vf vf5 vf0 vf0 acc) + (.mul.x.vf vf6 vf0 vf6 :mask #b1000) + (.mul.x.vf vf5 vf0 vf5 :mask #b1000) + (.mul.vf acc vf6 vf4) + (.add.mul.vf vf7 vf5 vf3 acc) + (.svf (&-> arg0 quad) vf7) + arg0 + ) + ) + +;; definition for function vector-x-quaternion! +;; INFO: Used lq/sq +(defun vector-x-quaternion! ((arg0 vector) (arg1 quaternion)) + "Get the first row of the rotation matrix for this quaternion." + (let ((s5-0 (new 'stack-no-clear 'matrix))) + (set! (-> s5-0 rvec quad) (the-as uint128 0)) + (set! (-> s5-0 uvec quad) (the-as uint128 0)) + (set! (-> s5-0 fvec quad) (the-as uint128 0)) + (set! (-> s5-0 trans quad) (the-as uint128 0)) + (quaternion->matrix s5-0 arg1) + (set! (-> arg0 quad) (-> s5-0 rvec quad)) + ) + arg0 + ) + +;; definition for function vector-y-quaternion! +;; INFO: Used lq/sq +(defun vector-y-quaternion! ((arg0 vector) (arg1 quaternion)) + "Get the second row of the rotation matrix for this quaternion." + (let ((s5-0 (new 'stack-no-clear 'matrix))) + (set! (-> s5-0 rvec quad) (the-as uint128 0)) + (set! (-> s5-0 uvec quad) (the-as uint128 0)) + (set! (-> s5-0 fvec quad) (the-as uint128 0)) + (set! (-> s5-0 trans quad) (the-as uint128 0)) + (quaternion->matrix s5-0 arg1) + (set! (-> arg0 quad) (-> s5-0 uvec quad)) + ) + arg0 + ) + +;; definition for function vector-z-quaternion! +;; INFO: Used lq/sq +(defun vector-z-quaternion! ((arg0 vector) (arg1 quaternion)) + "Get the third row of the rotation matrix for this quaternion." + (let ((s5-0 (new 'stack-no-clear 'matrix))) + (set! (-> s5-0 rvec quad) (the-as uint128 0)) + (set! (-> s5-0 uvec quad) (the-as uint128 0)) + (set! (-> s5-0 fvec quad) (the-as uint128 0)) + (set! (-> s5-0 trans quad) (the-as uint128 0)) + (quaternion->matrix s5-0 arg1) + (set! (-> arg0 quad) (-> s5-0 fvec quad)) + ) + arg0 + ) + +;; definition for function quaternion-x-angle +(defun quaternion-x-angle ((arg0 quaternion)) + "Get the x rotation angle. Not very efficient." + (let ((v1-1 (vector-y-quaternion! (new 'stack-no-clear 'vector) arg0))) + (atan (-> v1-1 z) (-> v1-1 y)) + ) + ) + +;; definition for function quaternion-y-angle +(defun quaternion-y-angle ((arg0 quaternion)) + "Get the y rotation angle. Not very efficient." + (let ((v1-1 (vector-z-quaternion! (new 'stack-no-clear 'vector) arg0))) + (atan (-> v1-1 x) (-> v1-1 z)) + ) + ) + +;; definition for function quaternion-z-angle +(defun quaternion-z-angle ((arg0 quaternion)) + "Get the z rotation angle. Not very efficient." + (let ((v1-1 (vector-y-quaternion! (new 'stack-no-clear 'vector) arg0))) + (atan (-> v1-1 x) (-> v1-1 y)) + ) + ) + +;; definition for function quaternion-vector-y-angle +(defun quaternion-vector-y-angle ((arg0 quaternion) (arg1 vector)) + "Not sure. Angle between quaternion and axis, projected in xz plane?" + (let ((f30-0 (quaternion-y-angle arg0)) + (f0-2 (atan (-> arg1 x) (-> arg1 z))) + ) + (deg-diff f30-0 f0-2) + ) + ) + +;; definition for function quaternion-rotate-local-x! +;; INFO: Used lq/sq +(defun quaternion-rotate-local-x! ((arg0 quaternion) (arg1 quaternion) (arg2 float)) + "Rotate existing quaternion along x axis." + (let ((a2-1 (quaternion-vector-angle! (new-stack-quaternion0) (new 'static 'vector :x 1.0 :w 1.0) arg2))) + (quaternion-normalize! (quaternion*! arg0 arg1 a2-1)) + ) + ) + +;; definition for function quaternion-rotate-local-y! +;; INFO: Used lq/sq +(defun quaternion-rotate-local-y! ((arg0 quaternion) (arg1 quaternion) (arg2 float)) + "Rotate existing quaternion along y axis." + (let ((a2-1 (quaternion-vector-angle! (new-stack-quaternion0) (new 'static 'vector :y 1.0 :w 1.0) arg2))) + (quaternion-normalize! (quaternion*! arg0 arg1 a2-1)) + ) + ) + +;; definition for function quaternion-rotate-local-z! +;; INFO: Used lq/sq +(defun quaternion-rotate-local-z! ((arg0 quaternion) (arg1 quaternion) (arg2 float)) + "Rotate existing quaternion along z axis." + (let ((a2-1 (quaternion-vector-angle! (new-stack-quaternion0) (new 'static 'vector :z 1.0 :w 1.0) arg2))) + (quaternion-normalize! (quaternion*! arg0 arg1 a2-1)) + ) + ) + +;; definition for function quaternion-rotate-y! +;; INFO: Used lq/sq +(defun quaternion-rotate-y! ((arg0 quaternion) (arg1 quaternion) (arg2 float)) + "Rotate existing quaternion along y axis (right multiply)." + (let ((a1-2 (quaternion-vector-angle! (new-stack-quaternion0) (new 'static 'vector :y 1.0 :w 1.0) arg2))) + (quaternion-normalize! (quaternion*! arg0 a1-2 arg1)) + ) + ) + +;; definition for function quaternion-rotate-x! +;; INFO: Used lq/sq +(defun quaternion-rotate-x! ((arg0 quaternion) (arg1 quaternion) (arg2 float)) + "Rotate existing quaternion along x axis (right multiply)." + (let ((a1-3 (quaternion-vector-angle! (new-stack-quaternion0) (vector-x-quaternion! (new-stack-vector0) arg1) arg2)) + ) + (quaternion-normalize! (quaternion*! arg0 a1-3 arg1)) + ) + ) + +;; definition for function quaternion-rotate-z! +;; INFO: Used lq/sq +(defun quaternion-rotate-z! ((arg0 quaternion) (arg1 quaternion) (arg2 float)) + "Rotate existing quaternion along z axis (right multiply)." + (let ((a1-3 (quaternion-vector-angle! (new-stack-quaternion0) (vector-z-quaternion! (new-stack-vector0) arg1) arg2)) + ) + (quaternion-normalize! (quaternion*! arg0 a1-3 arg1)) + ) + ) + +;; definition for function quaternion-delta-y +(defun quaternion-delta-y ((arg0 quaternion) (arg1 quaternion)) + "Difference in yaw between two quaternions." + (acos (vector-dot + (vector-z-quaternion! (new 'stack-no-clear 'vector) arg0) + (vector-z-quaternion! (new 'stack-no-clear 'vector) arg1) + ) + ) + ) + +;; definition for function quaternion-rotate-y-to-vector! +(defun quaternion-rotate-y-to-vector! ((arg0 quaternion) (arg1 quaternion) (arg2 quaternion) (arg3 float)) + (let ((s5-0 (new 'stack-no-clear 'quaternion))) + (let ((t9-0 vector-xz-normalize!) + (a0-1 (new 'stack-no-clear 'vector)) + ) + (set! (-> a0-1 x) (-> arg2 x)) + (set! (-> a0-1 y) 0.0) + (set! (-> a0-1 z) (-> arg2 z)) + (set! (-> a0-1 w) 1.0) + (let ((s0-0 (t9-0 a0-1 1.0))) + (quaternion-from-two-vectors-max-angle! + s5-0 + (vector-z-quaternion! (new 'stack-no-clear 'vector) arg1) + s0-0 + arg3 + ) + ) + ) + (quaternion-normalize! (quaternion*! arg0 s5-0 arg1)) + ) + ) + +;; definition for function vector-rotate-around-axis! +(defun vector-rotate-around-axis! ((arg0 vector) (arg1 quaternion) (arg2 float) (arg3 vector)) + "Rotate along y so z-axis points to match another. Use arg3 as the max rotation amount." + (let ((a2-1 (quaternion-vector-angle! (new 'stack-no-clear 'quaternion) arg3 arg2))) + (vector-orient-by-quat! arg0 (the-as vector arg1) a2-1) + ) + ) + +;; definition for function vector-rotate-x! +(defun vector-rotate-x! ((arg0 vector) (arg1 vector) (arg2 float)) + "Rotate vector along x axis." + (vector-rotate-around-axis! arg0 (the-as quaternion arg1) arg2 *x-vector*) + ) + +;; definition for function vector-rotate-y! +(defun vector-rotate-y! ((arg0 vector) (arg1 vector) (arg2 float)) + "Rotate vector along y axis." + (vector-rotate-around-axis! arg0 (the-as quaternion arg1) arg2 *y-vector*) + ) + +;; definition for function vector-rotate-z! +(defun vector-rotate-z! ((arg0 vector) (arg1 vector) (arg2 float)) + "Rotate vector along z axis." + (vector-rotate-around-axis! arg0 (the-as quaternion arg1) arg2 *z-vector*) + ) + +;; definition for function vector-y-angle +(defun vector-y-angle ((arg0 vector)) + "Get the yaw angle of a vector." + (atan (-> arg0 x) (-> arg0 z)) + ) + +;; definition for function vector-x-angle +(defun vector-x-angle ((arg0 vector)) + "Get the pitch angle of a vector." + (atan (-> arg0 y) (vector-xz-length arg0)) + ) + +;; definition for function quaternion<-rotate-y-vector +(defun quaternion<-rotate-y-vector ((arg0 quaternion) (arg1 vector)) + "Create a quaternion representing only the yaw of the given vector." + (quaternion-vector-angle! arg0 (new 'static 'vector :y 1.0 :w 1.0) (vector-y-angle arg1)) + ) + +;; definition (debug) for function quaternion-validate +;; WARN: Return type mismatch int vs none. +(defun-debug quaternion-validate ((arg0 quaternion)) + "Verify that a quaternion is valid, print an error if the length is off by more than 1%.." + (with-pp + (let ((f0-0 (quaternion-norm arg0))) + (when (or (< 1.01 f0-0) (< f0-0 0.99)) + (format #t "WARNING: bad quaternion (magnitude ~F) process is " f0-0) + (if (and pp (type? pp process-tree)) + (format #t "~A~%" (-> pp name)) + (format #t "#f~%") + ) + ) + ) + 0 + (none) + ) + ) + +;; definition for function quaternion-xz-angle +(defun quaternion-xz-angle ((arg0 quaternion)) + "Yet another function to compute the yaw of a quaternion. This is a particularly inefficient version." + (let ((gp-0 (new 'stack-no-clear 'matrix)) + (s5-0 (new 'stack-no-clear 'vector)) + ) + (quaternion->matrix gp-0 arg0) + (set-vector! s5-0 0.0 0.0 1.0 1.0) + (vector-matrix*! s5-0 s5-0 gp-0) + (vector-y-angle s5-0) + ) + ) + + + + diff --git a/test/decompiler/reference/jak3/engine/math/transform-h_REF.gc b/test/decompiler/reference/jak3/engine/math/transform-h_REF.gc new file mode 100644 index 0000000000..ee9d2040c7 --- /dev/null +++ b/test/decompiler/reference/jak3/engine/math/transform-h_REF.gc @@ -0,0 +1,63 @@ +;;-*-Lisp-*- +(in-package goal) + +;; definition of type transform +(deftype transform (structure) + "Transformation. w components of vectors should be 1.0 +This can represent any rotation, translation, and scaling. +Note that the scaling is applied before rotation +(meaning it scales along the axes of the pre-transformed frame)." + ((trans vector :inline) + (rot vector :inline) + (scale vector :inline) + ) + ) + +;; definition for method 3 of type transform +(defmethod inspect ((this transform)) + (when (not this) + (set! this this) + (goto cfg-4) + ) + (format #t "[~8x] ~A~%" this 'transform) + (format #t "~1Ttrans: ~`vector`P~%" (-> this trans)) + (format #t "~1Trot: ~`vector`P~%" (-> this rot)) + (format #t "~1Tscale: ~`vector`P~%" (-> this scale)) + (label cfg-4) + this + ) + +;; definition of type trs +(deftype trs (basic) + "Like transform, but it's a basic. +Note that the trsq child type overrides this rotation with a quaternion. +usage of the plain trs is very limited, at least in Jak 1." + ((trans vector :inline) + (rot vector :inline) + (scale vector :inline) + ) + (:methods + (new (symbol type) _type_) + ) + ) + +;; definition for method 3 of type trs +(defmethod inspect ((this trs)) + (when (not this) + (set! this this) + (goto cfg-4) + ) + (format #t "[~8x] ~A~%" this (-> this type)) + (format #t "~1Ttrans: ~`vector`P~%" (-> this trans)) + (format #t "~1Trot: ~`vector`P~%" (-> this rot)) + (format #t "~1Tscale: ~`vector`P~%" (-> this scale)) + (label cfg-4) + this + ) + +;; failed to figure out what this is: +0 + + + + diff --git a/test/decompiler/reference/jak3/engine/math/transform_REF.gc b/test/decompiler/reference/jak3/engine/math/transform_REF.gc new file mode 100644 index 0000000000..f9aceb4513 --- /dev/null +++ b/test/decompiler/reference/jak3/engine/math/transform_REF.gc @@ -0,0 +1,89 @@ +;;-*-Lisp-*- +(in-package goal) + +;; definition for method 2 of type transform +(defmethod print ((this transform)) + (format #t "# this trans x) (-> this trans y) (-> this trans z) (-> this trans w)) + (format #t "~T~Trot: ~F ~F ~F ~F ~%" (-> this rot x) (-> this rot y) (-> this rot z) (-> this rot w)) + (format #t "~T~Tscale:~F ~F ~F ~F>" (-> this scale x) (-> this scale y) (-> this scale z) (-> this scale w)) + this + ) + +;; definition for method 0 of type trs +(defmethod new trs ((allocation symbol) (type-to-make type)) + (let ((gp-0 (object-new allocation type-to-make (the-as int (-> type-to-make size))))) + (set! (-> gp-0 trans w) 1.0) + (set! (-> gp-0 rot w) 1.0) + (vector-identity! (-> gp-0 scale)) + gp-0 + ) + ) + +;; definition for function transform-matrix-calc! +;; INFO: Used lq/sq +(defun transform-matrix-calc! ((arg0 transform) (arg1 matrix)) + "Convert a transform to matrix. Not efficient, and the output is the second arg." + (let ((s4-0 (new 'stack-no-clear 'matrix))) + (set! (-> s4-0 rvec quad) (the-as uint128 0)) + (set! (-> s4-0 uvec quad) (the-as uint128 0)) + (set! (-> s4-0 fvec quad) (the-as uint128 0)) + (set! (-> s4-0 trans quad) (the-as uint128 0)) + (let ((s3-0 (new 'stack-no-clear 'matrix))) + (set! (-> s3-0 rvec quad) (the-as uint128 0)) + (set! (-> s3-0 uvec quad) (the-as uint128 0)) + (set! (-> s3-0 fvec quad) (the-as uint128 0)) + (set! (-> s3-0 trans quad) (the-as uint128 0)) + (matrix-identity! arg1) + (matrix-translate! arg1 (-> arg0 trans)) + (matrix-rotate-y! s4-0 (-> arg0 rot y)) + (matrix*! s3-0 s4-0 arg1) + (matrix-rotate-x! s4-0 (-> arg0 rot x)) + (matrix*! arg1 s4-0 s3-0) + (matrix-rotate-z! s4-0 (-> arg0 rot z)) + (matrix*! s3-0 s4-0 arg1) + (matrix-scale! s4-0 (-> arg0 scale)) + (matrix*! arg1 s4-0 s3-0) + ) + ) + ) + +;; definition for function transform-matrix-parent-calc! +;; INFO: Used lq/sq +(defun transform-matrix-parent-calc! ((arg0 transform) (arg1 matrix) (arg2 vector)) + "Convert a transform to a matrix, applying an inverse scaling." + (let ((s4-0 (new 'stack-no-clear 'matrix))) + (set! (-> s4-0 rvec quad) (the-as uint128 0)) + (set! (-> s4-0 uvec quad) (the-as uint128 0)) + (set! (-> s4-0 fvec quad) (the-as uint128 0)) + (set! (-> s4-0 trans quad) (the-as uint128 0)) + (let ((s3-0 (new 'stack-no-clear 'matrix))) + (set! (-> s3-0 rvec quad) (the-as uint128 0)) + (set! (-> s3-0 uvec quad) (the-as uint128 0)) + (set! (-> s3-0 fvec quad) (the-as uint128 0)) + (set! (-> s3-0 trans quad) (the-as uint128 0)) + (matrix-identity! s3-0) + (matrix-translate! s3-0 (-> arg0 trans)) + (matrix-inv-scale! s4-0 arg2) + (matrix*! arg1 s4-0 s3-0) + (matrix-rotate-y! s4-0 (-> arg0 rot y)) + (matrix*! s3-0 s4-0 arg1) + (matrix-rotate-x! s4-0 (-> arg0 rot x)) + (matrix*! arg1 s4-0 s3-0) + (matrix-rotate-z! s4-0 (-> arg0 rot z)) + (matrix*! s3-0 s4-0 arg1) + (matrix-scale! s4-0 (-> arg0 scale)) + (matrix*! arg1 s4-0 s3-0) + ) + ) + ) + +;; definition for function trs-matrix-calc! +(defun trs-matrix-calc! ((arg0 trs) (arg1 matrix)) + "Convert a trs to a matrix." + (transform-matrix-calc! (the-as transform (-> arg0 trans)) arg1) + ) + + + + diff --git a/test/decompiler/reference/jak3/engine/math/transformq-h_REF.gc b/test/decompiler/reference/jak3/engine/math/transformq-h_REF.gc new file mode 100644 index 0000000000..06dc0ea508 --- /dev/null +++ b/test/decompiler/reference/jak3/engine/math/transformq-h_REF.gc @@ -0,0 +1,131 @@ +;;-*-Lisp-*- +(in-package goal) + +;; definition of type transformq +(deftype transformq (transform) + ((quat quaternion :inline :overlay-at (-> rot data 0)) + ) + ) + +;; definition for method 3 of type transformq +(defmethod inspect ((this transformq)) + (when (not this) + (set! this this) + (goto cfg-4) + ) + (format #t "[~8x] ~A~%" this 'transformq) + (format #t "~1Ttrans: ~`vector`P~%" (-> this trans)) + (format #t "~1Trot: ~`vector`P~%" (-> this rot)) + (format #t "~1Tscale: ~`vector`P~%" (-> this scale)) + (format #t "~1Tquat: #~%" (-> this rot)) + (label cfg-4) + this + ) + +;; definition of type trsq +(deftype trsq (trs) + ((quat quaternion :inline :overlay-at (-> rot data 0)) + ) + ) + +;; definition for method 3 of type trsq +(defmethod inspect ((this trsq)) + (when (not this) + (set! this this) + (goto cfg-4) + ) + (format #t "[~8x] ~A~%" this (-> this type)) + (format #t "~1Ttrans: ~`vector`P~%" (-> this trans)) + (format #t "~1Trot: ~`vector`P~%" (-> this rot)) + (format #t "~1Tscale: ~`vector`P~%" (-> this scale)) + (format #t "~1Tquat: #~%" (-> this rot)) + (label cfg-4) + this + ) + +;; definition of type trsqv +(deftype trsqv (trsq) + "A transform with: +- type information (child of [[basic]]) +- rotation stored as quaternion +- velocity information. +This is a very commonly used type to represent the position of an in-game object. +The `root` of a process-drawable (the parent 'in-game object' type) is a [[trsqv]]. +Additionally, the collision system uses [[trsqv]] as the parent type for foreground +collision objects ([[collide-shape]], [[collide-shape-moving]]). +As a result, this type has a lot of weird methods and extra stuff hidden in it." + ((pause-adjust-distance meters :offset 4) + (nav-radius meters :offset 8) + (transv vector :inline) + (rotv vector :inline) + (scalev vector :inline) + (dir-targ quaternion :inline) + (angle-change-time time-frame) + (old-y-angle-diff float) + ) + (:methods + (seek-toward-heading-vec! (_type_ vector float time-frame) quaternion) + (set-heading-vec! (_type_ vector) quaternion) + (seek-to-point-toward-point! (_type_ vector float time-frame) quaternion) + (point-toward-point! (_type_ vector) quaternion) + (seek-toward-yaw-angle! (_type_ float float time-frame) quaternion) + (set-yaw-angle-clear-roll-pitch! (_type_ float) quaternion) + (set-roll-to-grav! (_type_ float) quaternion) + (set-roll-to-grav-2! (_type_ float) quaternion) + (rotate-toward-orientation! (_type_ quaternion float float int int float) quaternion) + (set-quaternion! (_type_ quaternion) quaternion) + (set-heading-vec-clear-roll-pitch! (_type_ vector) quaternion) + (point-toward-point-clear-roll-pitch! (_type_ vector) quaternion) + (rot->dir-targ! (_type_) quaternion) + (y-angle (_type_) float) + (global-y-angle-to-point (_type_ vector) float) + (relative-y-angle-to-point (_type_ vector) float) + (roll-relative-to-gravity (_type_) float) + (set-and-limit-velocity (_type_ int vector float) trsqv) + (get-quaternion (_type_) quaternion) + ) + ) + +;; definition for method 3 of type trsqv +(defmethod inspect ((this trsqv)) + (when (not this) + (set! this this) + (goto cfg-4) + ) + (format #t "[~8x] ~A~%" this (-> this type)) + (format #t "~1Ttrans: ~`vector`P~%" (-> this trans)) + (format #t "~1Trot: ~`vector`P~%" (-> this rot)) + (format #t "~1Tscale: ~`vector`P~%" (-> this scale)) + (format #t "~1Tquat: #~%" (-> this rot)) + (format #t "~1Tpause-adjust-distance: (meters ~m)~%" (-> this pause-adjust-distance)) + (format #t "~1Tnav-radius: (meters ~m)~%" (-> this nav-radius)) + (format #t "~1Ttransv: ~`vector`P~%" (-> this transv)) + (format #t "~1Trotv: ~`vector`P~%" (-> this rotv)) + (format #t "~1Tscalev: ~`vector`P~%" (-> this scalev)) + (format #t "~1Tdir-targ: #~%" (-> this dir-targ)) + (format #t "~1Tangle-change-time: ~D~%" (-> this angle-change-time)) + (format #t "~1Told-y-angle-diff: ~f~%" (-> this old-y-angle-diff)) + (label cfg-4) + this + ) + +;; definition for method 23 of type trsqv +(defmethod global-y-angle-to-point ((this trsqv) (arg0 vector)) + "Get the angle in the xz plane from the position of this trsqv to the point arg0 +(ignores our current yaw)." + (vector-y-angle (vector-! (new 'stack-no-clear 'vector) arg0 (-> this trans))) + ) + +;; definition for method 24 of type trsqv +(defmethod relative-y-angle-to-point ((this trsqv) (arg0 vector)) + "Get the y angle between the current orientation and arg0 +(how much we'd have to yaw to point at arg0)." + (deg-diff (y-angle this) (vector-y-angle (vector-! (new 'stack-no-clear 'vector) arg0 (-> this trans)))) + ) + +;; failed to figure out what this is: +0 + + + + diff --git a/test/decompiler/reference/jak3/engine/math/trigonometry-h_REF.gc b/test/decompiler/reference/jak3/engine/math/trigonometry-h_REF.gc new file mode 100644 index 0000000000..8e4b1f21d4 --- /dev/null +++ b/test/decompiler/reference/jak3/engine/math/trigonometry-h_REF.gc @@ -0,0 +1,9 @@ +;;-*-Lisp-*- +(in-package goal) + +;; failed to figure out what this is: +0 + + + + diff --git a/test/decompiler/reference/jak3/engine/math/trigonometry_REF.gc b/test/decompiler/reference/jak3/engine/math/trigonometry_REF.gc new file mode 100644 index 0000000000..64b558f029 --- /dev/null +++ b/test/decompiler/reference/jak3/engine/math/trigonometry_REF.gc @@ -0,0 +1,664 @@ +;;-*-Lisp-*- +(in-package goal) + +;; definition for function radmod +(defun radmod ((arg0 float)) + "Wrap arg0 to be within (-pi, pi)." + (let ((f0-1 (+ 3.1415925 arg0))) + (if (< 0.0 f0-1) + (+ -3.1415925 (- f0-1 (* (the float (the int (/ f0-1 6.283185))) 6.283185))) + (+ 3.1415925 (- f0-1 (* (the float (the int (/ f0-1 6.283185))) 6.283185))) + ) + ) + ) + +;; definition for function deg- +(defun deg- ((arg0 float) (arg1 float)) + "Compute arg0-arg1, unwrapped, using rotation units. +Result should be in the range (-180, 180)" + (the float (sar (- (shl (the int arg0) 48) (shl (the int arg1) 48)) 48)) + ) + +;; definition for function deg-diff +(defun deg-diff ((arg0 float) (arg1 float)) + "Very similar to the function above, but computes arg1 - arg0 instead." + (the float (sar (- (shl (the int arg1) 48) (shl (the int arg0) 48)) 48)) + ) + +;; definition for function deg-seek +(defun deg-seek ((arg0 float) (arg1 float) (arg2 float)) + "Move in toward target by at most max-diff, using rotation units" + (let ((v1-1 (shl (the int arg0) 48)) + (a0-2 (shl (the int arg1) 48)) + ) + (let* ((a1-2 (shl (the int arg2) 48)) + (a2-1 (- a0-2 v1-1)) + (a3-0 (abs a2-1)) + ) + (set! a0-2 (cond + ((< a3-0 0) + (+ v1-1 a1-2) + ) + ((>= a1-2 a3-0) + (empty) + a0-2 + ) + ((>= a2-1 0) + (+ v1-1 a1-2) + ) + (else + (- v1-1 a1-2) + ) + ) + ) + ) + (the float (sar a0-2 48)) + ) + ) + +;; definition for function deg-seek-smooth +(defun deg-seek-smooth ((arg0 float) (arg1 float) (arg2 float) (arg3 float)) + "Step amount of the way from in to target, by at most max-diff, using rotation units" + (let ((f0-1 (* (deg- arg1 arg0) arg3))) + (if (< arg2 (fabs f0-1)) + (set! f0-1 (if (>= f0-1 0.0) + arg2 + (- arg2) + ) + ) + ) + (+ arg0 f0-1) + ) + ) + +;; definition for function deg-lerp-clamp +(defun deg-lerp-clamp ((arg0 float) (arg1 float) (arg2 float)) + "Map [0, 1] to min-val, max-val, handling wrapping and saturating, using rotation units." + (cond + ((>= 0.0 arg2) + arg0 + ) + ((>= arg2 1.0) + arg1 + ) + (else + (the float (sar (shl (the int (+ arg0 (* arg2 (deg-diff arg0 arg1)))) 48) 48)) + ) + ) + ) + +;; definition for symbol binary-table, type (array float) +(define binary-table (new 'static 'boxed-array :type float + 1.0 + 0.5 + 0.25 + 0.125 + 0.0625 + 0.03125 + 0.015625 + 0.0078125 + 0.00390625 + 0.001953125 + 0.0009765625 + 0.00048828125 + 0.00024414062 + 0.00012207031 + 0.000061035156 + 0.000030517578 + 0.000015258789 + 0.0000076293945 + 0.0000038146973 + 0.0000019073486 + 0.0000009536743 + 0.00000047683716 + 0.00000023841858 + 0.00000011920929 + 0.000000059604645 + 0.000000029802322 + 0.000000014901161 + 0.000000007450581 + 0.0000000037252903 + 0.0000000018626451 + 0.0000000009313226 + 0.0000000004656613 + ) + ) + +;; definition for symbol sincos-table, type (array float) +(define sincos-table (new 'static 'boxed-array :type float + 0.7853982 + 0.4636476 + 0.24497867 + 0.124354996 + 0.06241881 + 0.031239834 + 0.015623729 + 0.007812341 + 0.0039062302 + 0.0019531226 + 0.0009765622 + 0.0004882812 + 0.00024414062 + 0.00012207031 + 0.000061035156 + 0.000030517578 + 0.000015258789 + 0.0000076293945 + 0.0000038146973 + 0.0000019073486 + 0.0000009536743 + 0.00000047683716 + 0.00000023841858 + 0.00000011920929 + 0.000000059604645 + 0.000000029802322 + 0.000000014901161 + 0.000000007450581 + 0.0000000037252903 + 0.0000000018626451 + 0.0000000009313226 + 0.0000000004656613 + ) + ) + +;; definition for function sin +(defun sin ((arg0 float)) + "Compute the sine of an angle in rotation units. Unwraps it." + (let ((f2-0 (* 0.000095873795 (the float (sar (shl (the int arg0) 48) 48))))) + f2-0 + (let* ((f1-4 (* 0.999998 f2-0)) + (f0-3 (* f2-0 f2-0)) + (f2-1 (* f2-0 f0-3)) + (f1-5 (+ f1-4 (* -0.16666014 f2-1))) + (f2-2 (* f2-1 f0-3)) + (f1-6 (+ f1-5 (* 0.008326521 f2-2))) + (f2-3 (* f2-2 f0-3)) + (f1-7 (+ f1-6 (* -0.0001956241 f2-3))) + (f0-4 (* f2-3 f0-3)) + ) + (+ f1-7 (* 0.0000023042373 f0-4)) + ) + ) + ) + +;; definition for function sin-rad +;; ERROR: function was not converted to expressions. Cannot decompile. + +;; definition for symbol *sin-poly-vec*, type vector +(define *sin-poly-vec* + (new 'static 'vector :x -0.16666014 :y 0.008326521 :z -0.0001956241 :w 0.0000023042373) + ) + +;; definition for symbol *sin-poly-vec2*, type vector +(define *sin-poly-vec2* (new 'static 'vector :x 0.999998)) + +;; definition for function vector-sin-rad! +(defun vector-sin-rad! ((arg0 vector) (arg1 vector)) + "Taylor series approximation of sine on all 4 elements in a vector. +Inputs should be in radians, in -pi to pi. +Somehow their coefficients are a little bit off. +Like the first coefficient, which should obviously be 1, is not quite 1." + (rlet ((acc :class vf) + (vf1 :class vf) + (vf10 :class vf) + (vf2 :class vf) + (vf3 :class vf) + (vf4 :class vf) + (vf5 :class vf) + (vf6 :class vf) + (vf7 :class vf) + (vf8 :class vf) + (vf9 :class vf) + ) + (.lvf vf1 (&-> arg1 quad)) + (.mul.vf vf3 vf1 vf1) + (.lvf vf10 (&-> *sin-poly-vec2* quad)) + (.lvf vf9 (&-> *sin-poly-vec* quad)) + (.mul.vf vf4 vf3 vf1) + (.mul.vf vf5 vf3 vf3) + (.mul.x.vf acc vf1 vf10) + (.mul.vf vf6 vf4 vf3) + (.mul.vf vf7 vf5 vf4) + (.add.mul.x.vf acc vf4 vf9 acc) + (.mul.vf vf8 vf6 vf5) + (.add.mul.y.vf acc vf6 vf9 acc) + (.add.mul.z.vf acc vf7 vf9 acc) + (.add.mul.w.vf vf2 vf8 vf9 acc) + (.svf (&-> arg0 quad) vf2) + arg0 + ) + ) + +;; definition for function cos-rad +;; ERROR: function was not converted to expressions. Cannot decompile. + +;; definition for symbol *cos-poly-vec*, type vector +(define *cos-poly-vec* (new 'static 'vector :x -0.49998003 :y 0.041620404 :z -0.0013636408 :w 0.000020170546)) + +;; definition for function vector-cos-rad! +;; ERROR: Bad vector register dependency: vf2 +(defun vector-cos-rad! ((arg0 vector) (arg1 vector)) + "Compute the cosine of all 4 vector elements. +Radians, with no wrapping. Uses taylor series with 4 coefficients." + (rlet ((acc :class vf) + (vf0 :class vf) + (vf1 :class vf) + (vf2 :class vf) + (vf3 :class vf) + (vf4 :class vf) + (vf5 :class vf) + (vf6 :class vf) + (vf9 :class vf) + ) + (init-vf0-vector) + (.lvf vf1 (&-> arg1 quad)) + (.sub.vf vf2 vf2 vf2) + (.lvf vf9 (&-> *cos-poly-vec* quad)) + (.mul.vf vf3 vf1 vf1) + (.add.w.vf acc vf2 vf0) + (.mul.vf vf4 vf3 vf3) + (.add.mul.x.vf acc vf3 vf9 acc) + (.mul.vf vf5 vf4 vf3) + (.add.mul.y.vf acc vf4 vf9 acc) + (.mul.vf vf6 vf4 vf4) + (.add.mul.z.vf acc vf5 vf9 acc) + (.add.mul.w.vf vf2 vf6 vf9 acc) + (.svf (&-> arg0 quad) vf2) + arg0 + ) + ) + +;; definition for function vector-sincos-rad! +;; ERROR: Bad vector register dependency: vf14 +(defun vector-sincos-rad! ((arg0 vector) (arg1 vector) (arg2 vector)) + "Compute the sine and cosine of each element of src, storing it in dst-sin and dst-cos. +This is more efficient than separate calls to sin and cos. +Inputs should be radians in -pi to pi." + (rlet ((acc :class vf) + (vf0 :class vf) + (vf1 :class vf) + (vf10 :class vf) + (vf11 :class vf) + (vf12 :class vf) + (vf13 :class vf) + (vf14 :class vf) + (vf2 :class vf) + (vf3 :class vf) + (vf4 :class vf) + (vf5 :class vf) + (vf6 :class vf) + (vf7 :class vf) + (vf8 :class vf) + (vf9 :class vf) + ) + (init-vf0-vector) + (.lvf vf1 (&-> arg2 quad)) + (.sub.vf vf14 vf14 vf14) + (.lvf vf11 (&-> *sin-poly-vec2* quad)) + (.mul.vf vf2 vf1 vf1) + (.lvf vf10 (&-> *sin-poly-vec* quad)) + (.lvf vf13 (&-> *cos-poly-vec* quad)) + (.mul.x.vf acc vf1 vf11) + (.mul.vf vf3 vf2 vf1) + (.mul.vf vf4 vf2 vf2) + (.mul.vf vf5 vf3 vf2) + (.mul.vf vf6 vf3 vf3) + (.mul.vf vf7 vf4 vf3) + (.mul.vf vf8 vf4 vf4) + (.mul.vf vf9 vf5 vf4) + (.add.mul.x.vf acc vf3 vf10 acc) + (.add.mul.y.vf acc vf5 vf10 acc) + (.add.mul.z.vf acc vf7 vf10 acc) + (.add.mul.w.vf vf12 vf9 vf10 acc) + (.add.w.vf acc vf14 vf0) + (.add.mul.x.vf acc vf2 vf13 acc) + (.add.mul.y.vf acc vf4 vf13 acc) + (.add.mul.z.vf acc vf6 vf13 acc) + (.add.mul.w.vf vf14 vf8 vf13 acc) + (.svf (&-> arg0 quad) vf12) + (.svf (&-> arg1 quad) vf14) + 0 + ) + ) + +;; definition for function sincos-rad! +;; ERROR: function was not converted to expressions. Cannot decompile. + +;; definition for function sincos! +;; ERROR: function was not converted to expressions. Cannot decompile. + +;; definition for function vector-rad<-vector-deg! +;; WARN: Return type mismatch float vs none. +(defun vector-rad<-vector-deg! ((out vector) (in vector)) + "Convert a vector in rotation units to radians, and unwrap. +Input can be anything, output will be -2pi to pi." + (local-vars (v0-0 float) (v1-1 uint128) (v1-2 uint128) (v1-3 uint128)) + (rlet ((vf1 :class vf) + (vf2 :class vf) + ) + (let ((v1-0 #x38c90fda)) + (.lvf vf1 (&-> in quad)) + (.ftoi.vf vf1 vf1) + (.mov vf2 v1-0) + ) + (.mov v1-1 vf1) + (.pw.sll v1-2 v1-1 16) + (.pw.sra v1-3 v1-2 16) + (.mov vf1 v1-3) + (.itof.vf vf1 vf1) + (.mul.x.vf vf1 vf1 vf2) + (.svf (&-> out quad) vf1) + (.mov v0-0 vf1) + (none) + ) + ) + +;; definition for function vector-rad<-vector-deg/2! +;; WARN: Return type mismatch float vs int. +(defun vector-rad<-vector-deg/2! ((out vector) (in vector)) + "Divide the input by two, and then convert from rotation units to radians, unwrapping. +Not sure why this really needs to be separate the from previous function..." + (local-vars (v0-0 float) (v1-1 uint128) (v1-2 uint128) (v1-3 uint128)) + (rlet ((vf1 :class vf) + (vf2 :class vf) + ) + (let ((v1-0 #x38c90fda)) + (let ((a2-0 #x3f000000)) + (.lvf vf1 (&-> in quad)) + (.mov vf2 a2-0) + ) + (.mul.x.vf vf1 vf1 vf2) + (.ftoi.vf vf1 vf1) + (.mov vf2 v1-0) + ) + (.mov v1-1 vf1) + (.pw.sll v1-2 v1-1 16) + (.pw.sra v1-3 v1-2 16) + (.mov vf1 v1-3) + (.itof.vf vf1 vf1) + (.mul.x.vf vf1 vf1 vf2) + (.svf (&-> out quad) vf1) + (.mov v0-0 vf1) + (the-as int v0-0) + ) + ) + +;; definition for function vector-sincos! +(defun vector-sincos! ((arg0 vector) (arg1 vector) (arg2 vector)) + "Compute sine and cosine of each element in a vector, in rotation units" + (let ((s4-0 (new 'stack-no-clear 'vector))) + (vector-rad<-vector-deg! s4-0 arg2) + (vector-sincos-rad! arg0 arg1 s4-0) + ) + ) + +;; definition for function tan-rad +(defun tan-rad ((arg0 float)) + "This function appears to be named wrong and actually operates on rotation units." + (/ (sin arg0) (cos arg0)) + ) + +;; definition for function cos +(defun cos ((arg0 float)) + "Cosine of rotation units." + (sin (+ 16384.0 arg0)) + ) + +;; definition for function tan +(defun tan ((arg0 float)) + "Correctly named tangent of rotation units." + (/ (sin arg0) (cos arg0)) + ) + +;; definition for function atan0 +;; ERROR: function was not converted to expressions. Cannot decompile. + +;; definition for function atan-series-rad +;; ERROR: function was not converted to expressions. Cannot decompile. + +;; definition for function atan-rad +(defun atan-rad ((arg0 float)) + "Inverse tangent in radians." + (atan-series-rad (/ (+ -1.0 arg0) (+ 1.0 arg0))) + ) + +;; definition for function sign-bit +(defun sign-bit ((arg0 int)) + "Return 1 if bit 31 is set, otherwise 0." + (local-vars (v1-1 int)) + (let ((v1-0 arg0)) + (shift-arith-right-32 v1-1 v1-0 31) + ) + (logand v1-1 1) + ) + +;; definition for function sign-float +;; ERROR: function was not converted to expressions. Cannot decompile. + +;; definition for function sign +(defun sign ((arg0 float)) + "Similar to above, but returns 0 if input is 0. +But is more complicated." + (cond + ((< 0.0 arg0) + 1.0 + ) + ((< arg0 0.0) + -1.0 + ) + (else + 0.0 + ) + ) + ) + +;; definition for function atan2-rad +(defun atan2-rad ((arg0 float) (arg1 float)) + "Atan for radians." + (cond + ((= arg1 0.0) + (* 1.5707963 (sign arg0)) + ) + ((and (< arg0 0.0) (< arg1 0.0)) + (let ((f30-1 -3.1415925) + (f0-6 (/ arg0 arg1)) + ) + (+ f30-1 (atan-series-rad (/ (+ -1.0 f0-6) (+ 1.0 f0-6)))) + ) + ) + ((< arg0 0.0) + (let ((f0-14 (- (/ arg0 arg1)))) + (- (atan-series-rad (/ (+ -1.0 f0-14) (+ 1.0 f0-14)))) + ) + ) + ((< arg1 0.0) + (let ((f30-2 3.1415925) + (f0-22 (- (/ arg0 arg1))) + ) + (- f30-2 (atan-series-rad (/ (+ -1.0 f0-22) (+ 1.0 f0-22)))) + ) + ) + (else + (let ((f0-28 (/ arg0 arg1))) + (atan-series-rad (/ (+ -1.0 f0-28) (+ 1.0 f0-28))) + ) + ) + ) + ) + +;; definition for function atan +(defun atan ((arg0 float) (arg1 float)) + "Atan for rotation units. Signs behave like atan.." + (cond + ((and (= arg1 0.0) (= arg0 0.0)) + 0.0 + ) + ((and (< arg1 0.0) (< arg0 0.0)) + (+ -32768.0 (atan0 (- arg0) (- arg1))) + ) + ((< arg0 0.0) + (- (atan0 (- arg0) arg1)) + ) + ((< arg1 0.0) + (- 32768.0 (atan0 arg0 (- arg1))) + ) + (else + (atan0 arg0 arg1) + ) + ) + ) + +;; definition for function asin +(defun asin ((arg0 float)) + "Inverse sine, rotation units." + (let ((gp-0 #f)) + 0.0 + (when (< arg0 0.0) + (set! arg0 (- arg0)) + (set! gp-0 #t) + ) + (let ((f0-5 (cond + ((< 1.0 arg0) + 16383.996 + ) + (else + (let* ((f0-6 1.0) + (f1-2 arg0) + (f0-8 (sqrtf (- f0-6 (* f1-2 f1-2)))) + ) + (atan0 arg0 f0-8) + ) + ) + ) + ) + ) + (if gp-0 + (- f0-5) + f0-5 + ) + ) + ) + ) + +;; definition for function acos +(defun acos ((arg0 float)) + "Inverse cosine. Returns rotation units." + (- 16384.0 (asin arg0)) + ) + +;; definition for function acos-rad +(defun acos-rad ((arg0 float)) + "Inverse cosine, radians." + (cond + ((>= arg0 0.0) + (let* ((f0-1 1.0) + (f1-1 arg0) + (f0-3 (sqrtf (- f0-1 (* f1-1 f1-1)))) + (f0-5 (/ (- f0-3 arg0) (+ f0-3 arg0))) + ) + (atan-series-rad f0-5) + ) + ) + (else + (let* ((f0-6 1.0) + (f1-6 arg0) + (f0-8 (sqrtf (- f0-6 (* f1-6 f1-6)))) + (f0-10 (/ (+ f0-8 arg0) (- f0-8 arg0))) + ) + (- 3.1415925 (atan-series-rad f0-10)) + ) + ) + ) + ) + +;; definition for function sinerp +(defun sinerp ((arg0 float) (arg1 float) (arg2 float)) + "Map amount to min,max using sine. Kinda weird, usually people use cosine." + (lerp arg0 arg1 (sin (* 16384.0 arg2))) + ) + +;; definition for function sinerp-clamp +(defun sinerp-clamp ((arg0 float) (arg1 float) (arg2 float)) + "Like sinerp, but clamp to min,max." + (cond + ((>= 0.0 arg2) + arg0 + ) + ((>= arg2 1.0) + arg1 + ) + (else + (sinerp arg0 arg1 arg2) + ) + ) + ) + +;; definition for function coserp +(defun coserp ((arg0 float) (arg1 float) (arg2 float)) + "Weird lerp with cosine (over 90 degrees?)." + (lerp arg0 arg1 (- 1.0 (cos (* 16384.0 arg2)))) + ) + +;; definition for function coserp-clamp +(defun coserp-clamp ((arg0 float) (arg1 float) (arg2 float)) + "Weird 90 degree lerp with cosine, clamped to min,max." + (cond + ((>= 0.0 arg2) + arg0 + ) + ((>= arg2 1.0) + arg1 + ) + (else + (coserp arg0 arg1 arg2) + ) + ) + ) + +;; definition for function coserp180 +(defun coserp180 ((arg0 float) (arg1 float) (arg2 float)) + "Classic lerp with cosine." + (lerp arg0 arg1 (* 0.5 (- 1.0 (cos (* 32768.0 arg2))))) + ) + +;; definition for function coserp180-clamp +(defun coserp180-clamp ((arg0 float) (arg1 float) (arg2 float)) + "Classic coserp with saturation." + (cond + ((>= 0.0 arg2) + arg0 + ) + ((>= arg2 1.0) + arg1 + ) + (else + (coserp180 arg0 arg1 arg2) + ) + ) + ) + +;; definition for function ease-in-out +(defun ease-in-out ((arg0 int) (arg1 int)) + "Weird coserp like mapping from 0 to 1 as progress goes from 0 to total." + (local-vars (v1-0 int)) + (cond + ((>= arg1 arg0) + 1.0 + ) + ((<= arg1 0) + 0.0 + ) + ((begin (set! v1-0 (/ arg0 2)) (< v1-0 arg1)) + (let ((a0-1 (- arg1 arg0))) + (+ 0.5 (* 0.5 (sin (- 16384.0 (/ (* 16384.0 (the float a0-1)) (the float v1-0)))))) + ) + ) + (else + (- 0.5 (* 0.5 (cos (/ (* 16384.0 (the float arg1)) (the float v1-0))))) + ) + ) + ) + + + + diff --git a/test/decompiler/reference/jak3/engine/math/vector-h_REF.gc b/test/decompiler/reference/jak3/engine/math/vector-h_REF.gc new file mode 100644 index 0000000000..525dee434c --- /dev/null +++ b/test/decompiler/reference/jak3/engine/math/vector-h_REF.gc @@ -0,0 +1,1039 @@ +;;-*-Lisp-*- +(in-package goal) + +;; definition of type bit-array +(deftype bit-array (basic) + ((length int32) + (allocated-length int32) + (_pad uint8) + (bytes uint8 :dynamic :overlay-at _pad) + ) + (:methods + (new (symbol type int) _type_) + (get-bit (_type_ int) symbol) + (clear-bit (_type_ int) int) + (set-bit (_type_ int) int) + (clear-all! (_type_) _type_) + ) + ) + +;; definition for method 3 of type bit-array +(defmethod inspect ((this bit-array)) + (when (not this) + (set! this this) + (goto cfg-4) + ) + (format #t "[~8x] ~A~%" this (-> this type)) + (format #t "~1Tlength: ~D~%" (-> this length)) + (format #t "~1Tallocated-length: ~D~%" (-> this allocated-length)) + (label cfg-4) + this + ) + +;; definition for method 0 of type bit-array +(defmethod new bit-array ((allocation symbol) (type-to-make type) (arg0 int)) + "Allocate a new bit-array with room arg0 bits." + (let ((v0-0 (object-new allocation type-to-make (+ (/ (logand -8 (+ arg0 7)) 8) -1 (-> type-to-make size))))) + (set! (-> v0-0 length) arg0) + (set! (-> v0-0 allocated-length) arg0) + v0-0 + ) + ) + +;; definition for method 4 of type bit-array +(defmethod length ((this bit-array)) + (-> this length) + ) + +;; definition for method 5 of type bit-array +;; WARN: Return type mismatch uint vs int. +(defmethod asize-of ((this bit-array)) + (the-as int (+ (-> this type size) (/ (logand -8 (+ (-> this allocated-length) 7)) 8))) + ) + +;; definition for method 9 of type bit-array +(defmethod get-bit ((this bit-array) (arg0 int)) + "Get the nth bit as a boolean." + (let ((v1-2 (-> this bytes (/ arg0 8)))) + (logtest? v1-2 (ash 1 (logand arg0 7))) + ) + ) + +;; definition for method 10 of type bit-array +(defmethod clear-bit ((this bit-array) (arg0 int)) + "Set the nth bit to 0." + (logclear! (-> this bytes (/ arg0 8)) (ash 1 (logand arg0 7))) + 0 + ) + +;; definition for method 11 of type bit-array +(defmethod set-bit ((this bit-array) (arg0 int)) + "Set the nth bit to 1." + (logior! (-> this bytes (/ arg0 8)) (ash 1 (logand arg0 7))) + 0 + ) + +;; definition for method 12 of type bit-array +(defmethod clear-all! ((this bit-array)) + "Set all bits to 0." + (countdown (v1-2 (/ (logand -8 (+ (-> this allocated-length) 7)) 8)) + (nop!) + (nop!) + (set! (-> this bytes v1-2) (the-as uint 0)) + ) + this + ) + +;; definition of type vector16ub +(deftype vector16ub (structure) + ((data uint8 16) + (quad uint128 :overlay-at (-> data 0)) + ) + ) + +;; definition for method 3 of type vector16ub +;; INFO: Used lq/sq +(defmethod inspect ((this vector16ub)) + (when (not this) + (set! this this) + (goto cfg-4) + ) + (format #t "[~8x] ~A~%" this 'vector16ub) + (format #t "~1Tdata[16] @ #x~X~%" (-> this data)) + (format #t "~1Tquad: ~D~%" (-> this quad)) + (label cfg-4) + this + ) + +;; definition of type vector4ub +(deftype vector4ub (structure) + ((data uint8 4) + (x uint8 :overlay-at (-> data 0)) + (y uint8 :overlay-at (-> data 1)) + (z uint8 :overlay-at (-> data 2)) + (w uint8 :overlay-at (-> data 3)) + (clr uint32 :overlay-at (-> data 0)) + ) + :pack-me + ) + +;; definition for method 3 of type vector4ub +(defmethod inspect ((this vector4ub)) + (when (not this) + (set! this this) + (goto cfg-4) + ) + (format #t "[~8x] ~A~%" this 'vector4ub) + (format #t "~1Tdata[4] @ #x~X~%" (-> this data)) + (format #t "~1Tx: ~D~%" (-> this x)) + (format #t "~1Ty: ~D~%" (-> this y)) + (format #t "~1Tz: ~D~%" (-> this z)) + (format #t "~1Tw: ~D~%" (-> this w)) + (format #t "~1Tclr: ~D~%" (-> this clr)) + (label cfg-4) + this + ) + +;; definition of type vector4b +(deftype vector4b (structure) + ((data int8 4) + (x int8 :overlay-at (-> data 0)) + (y int8 :overlay-at (-> data 1)) + (z int8 :overlay-at (-> data 2)) + (w int8 :overlay-at (-> data 3)) + (clr int32 :overlay-at (-> data 0)) + ) + :pack-me + ) + +;; definition for method 3 of type vector4b +(defmethod inspect ((this vector4b)) + (when (not this) + (set! this this) + (goto cfg-4) + ) + (format #t "[~8x] ~A~%" this 'vector4b) + (format #t "~1Tdata[4] @ #x~X~%" (-> this data)) + (format #t "~1Tx: ~D~%" (-> this x)) + (format #t "~1Ty: ~D~%" (-> this y)) + (format #t "~1Tz: ~D~%" (-> this z)) + (format #t "~1Tw: ~D~%" (-> this w)) + (format #t "~1Tclr: ~D~%" (-> this clr)) + (label cfg-4) + this + ) + +;; definition of type vector2ub +(deftype vector2ub (structure) + ((data uint8 2) + (x uint8 :overlay-at (-> data 0)) + (y uint8 :overlay-at (-> data 1)) + (clr uint16 :overlay-at (-> data 0)) + ) + :pack-me + ) + +;; definition for method 3 of type vector2ub +(defmethod inspect ((this vector2ub)) + (when (not this) + (set! this this) + (goto cfg-4) + ) + (format #t "[~8x] ~A~%" this 'vector2ub) + (format #t "~1Tdata[2] @ #x~X~%" (-> this data)) + (format #t "~1Tx: ~D~%" (-> this x)) + (format #t "~1Ty: ~D~%" (-> this y)) + (format #t "~1Tclr: ~D~%" (-> this clr)) + (label cfg-4) + this + ) + +;; definition of type vector2b +(deftype vector2b (structure) + ((data int8 2) + (x int8 :overlay-at (-> data 0)) + (y int8 :overlay-at (-> data 1)) + (clr int16 :overlay-at (-> data 0)) + ) + ) + +;; definition for method 3 of type vector2b +(defmethod inspect ((this vector2b)) + (when (not this) + (set! this this) + (goto cfg-4) + ) + (format #t "[~8x] ~A~%" this 'vector2b) + (format #t "~1Tdata[2] @ #x~X~%" (-> this data)) + (format #t "~1Tx: ~D~%" (-> this x)) + (format #t "~1Ty: ~D~%" (-> this y)) + (format #t "~1Tclr: ~D~%" (-> this clr)) + (label cfg-4) + this + ) + +;; definition of type vector2h +(deftype vector2h (structure) + ((data int16 2) + (x int16 :overlay-at (-> data 0)) + (y int16 :overlay-at (-> data 1)) + ) + :pack-me + ) + +;; definition for method 3 of type vector2h +(defmethod inspect ((this vector2h)) + (when (not this) + (set! this this) + (goto cfg-4) + ) + (format #t "[~8x] ~A~%" this 'vector2h) + (format #t "~1Tdata[2] @ #x~X~%" (-> this data)) + (format #t "~1Tx: ~D~%" (-> this x)) + (format #t "~1Ty: ~D~%" (-> this y)) + (label cfg-4) + this + ) + +;; definition of type vector2uh +(deftype vector2uh (structure) + ((data uint16 2) + (x uint16 :overlay-at (-> data 0)) + (y uint16 :overlay-at (-> data 1)) + (val uint32 :overlay-at (-> data 0)) + ) + :pack-me + ) + +;; definition for method 3 of type vector2uh +(defmethod inspect ((this vector2uh)) + (when (not this) + (set! this this) + (goto cfg-4) + ) + (format #t "[~8x] ~A~%" this 'vector2uh) + (format #t "~1Tdata[2] @ #x~X~%" (-> this data)) + (format #t "~1Tx: ~D~%" (-> this x)) + (format #t "~1Ty: ~D~%" (-> this y)) + (format #t "~1Tval: ~D~%" (-> this val)) + (label cfg-4) + this + ) + +;; definition of type vector3h +(deftype vector3h (structure) + ((data int16 3) + (x int16 :overlay-at (-> data 0)) + (y int16 :overlay-at (-> data 1)) + (z int16 :overlay-at (-> data 2)) + ) + ) + +;; definition for method 3 of type vector3h +(defmethod inspect ((this vector3h)) + (when (not this) + (set! this this) + (goto cfg-4) + ) + (format #t "[~8x] ~A~%" this 'vector3h) + (format #t "~1Tdata[3] @ #x~X~%" (-> this data)) + (format #t "~1Tx: ~D~%" (-> this x)) + (format #t "~1Ty: ~D~%" (-> this y)) + (format #t "~1Tz: ~D~%" (-> this z)) + (label cfg-4) + this + ) + +;; definition of type vector3uh +(deftype vector3uh (structure) + ((data uint16 3) + (x uint16 :overlay-at (-> data 0)) + (y uint16 :overlay-at (-> data 1)) + (z uint16 :overlay-at (-> data 2)) + ) + ) + +;; definition for method 3 of type vector3uh +(defmethod inspect ((this vector3uh)) + (when (not this) + (set! this this) + (goto cfg-4) + ) + (format #t "[~8x] ~A~%" this 'vector3uh) + (format #t "~1Tdata[3] @ #x~X~%" (-> this data)) + (format #t "~1Tx: ~D~%" (-> this x)) + (format #t "~1Ty: ~D~%" (-> this y)) + (format #t "~1Tz: ~D~%" (-> this z)) + (label cfg-4) + this + ) + +;; definition of type vector2w +(deftype vector2w (structure) + ((data int32 2) + (x int32 :overlay-at (-> data 0)) + (y int32 :overlay-at (-> data 1)) + ) + ) + +;; definition for method 3 of type vector2w +(defmethod inspect ((this vector2w)) + (when (not this) + (set! this this) + (goto cfg-4) + ) + (format #t "[~8x] ~A~%" this 'vector2w) + (format #t "~1Tdata[2] @ #x~X~%" (-> this data)) + (format #t "~1Tx: ~D~%" (-> this x)) + (format #t "~1Ty: ~D~%" (-> this y)) + (label cfg-4) + this + ) + +;; definition of type vector3w +(deftype vector3w (structure) + ((data int32 3) + (x int32 :overlay-at (-> data 0)) + (y int32 :overlay-at (-> data 1)) + (z int32 :overlay-at (-> data 2)) + ) + ) + +;; definition for method 3 of type vector3w +(defmethod inspect ((this vector3w)) + (when (not this) + (set! this this) + (goto cfg-4) + ) + (format #t "[~8x] ~A~%" this 'vector3w) + (format #t "~1Tdata[3] @ #x~X~%" (-> this data)) + (format #t "~1Tx: ~D~%" (-> this x)) + (format #t "~1Ty: ~D~%" (-> this y)) + (format #t "~1Tz: ~D~%" (-> this z)) + (label cfg-4) + this + ) + +;; definition of type vector4w +(deftype vector4w (structure) + ((data int32 4) + (x int32 :overlay-at (-> data 0)) + (y int32 :overlay-at (-> data 1)) + (z int32 :overlay-at (-> data 2)) + (w int32 :overlay-at (-> data 3)) + (dword uint64 2 :overlay-at (-> data 0)) + (quad uint128 :overlay-at (-> data 0)) + ) + ) + +;; definition for method 3 of type vector4w +;; INFO: Used lq/sq +(defmethod inspect ((this vector4w)) + (when (not this) + (set! this this) + (goto cfg-4) + ) + (format #t "[~8x] ~A~%" this 'vector4w) + (format #t "~1Tdata[4] @ #x~X~%" (&-> this x)) + (format #t "~1Tx: ~D~%" (-> this x)) + (format #t "~1Ty: ~D~%" (-> this y)) + (format #t "~1Tz: ~D~%" (-> this z)) + (format #t "~1Tw: ~D~%" (-> this w)) + (format #t "~1Tdword[2] @ #x~X~%" (&-> this x)) + (format #t "~1Tquad: ~D~%" (-> this quad)) + (label cfg-4) + this + ) + +;; definition of type vector2 +(deftype vector2 (structure) + ((data float 2) + (x float :overlay-at (-> data 0)) + (y float :overlay-at (-> data 1)) + ) + :allow-misaligned + ) + +;; definition for method 3 of type vector2 +(defmethod inspect ((this vector2)) + (when (not this) + (set! this this) + (goto cfg-4) + ) + (format #t "[~8x] ~A~%" this 'vector2) + (format #t "~1Tdata[2] @ #x~X~%" (-> this data)) + (format #t "~1Tx: ~f~%" (-> this x)) + (format #t "~1Ty: ~f~%" (-> this y)) + (label cfg-4) + this + ) + +;; definition of type vector3 +(deftype vector3 (structure) + ((data float 3) + (x float :overlay-at (-> data 0)) + (y float :overlay-at (-> data 1)) + (z float :overlay-at (-> data 2)) + ) + ) + +;; definition for method 3 of type vector3 +(defmethod inspect ((this vector3)) + (when (not this) + (set! this this) + (goto cfg-4) + ) + (format #t "[~8x] ~A~%" this 'vector3) + (format #t "~1Tdata[3] @ #x~X~%" (-> this data)) + (format #t "~1Tx: ~f~%" (-> this x)) + (format #t "~1Ty: ~f~%" (-> this y)) + (format #t "~1Tz: ~f~%" (-> this z)) + (label cfg-4) + this + ) + +;; definition of type vector4 +(deftype vector4 (structure) + ((data float 4) + (x float :overlay-at (-> data 0)) + (y float :overlay-at (-> data 1)) + (z float :overlay-at (-> data 2)) + (w float :overlay-at (-> data 3)) + (dword uint64 2 :overlay-at (-> data 0)) + (quad uint128 :overlay-at (-> data 0)) + ) + ) + +;; definition for method 3 of type vector4 +;; INFO: Used lq/sq +(defmethod inspect ((this vector4)) + (when (not this) + (set! this this) + (goto cfg-4) + ) + (format #t "[~8x] ~A~%" this 'vector4) + (format #t "~1Tdata[4] @ #x~X~%" (&-> this x)) + (format #t "~1Tx: ~f~%" (-> this x)) + (format #t "~1Ty: ~f~%" (-> this y)) + (format #t "~1Tz: ~f~%" (-> this z)) + (format #t "~1Tw: ~f~%" (-> this w)) + (format #t "~1Tdword[2] @ #x~X~%" (&-> this x)) + (format #t "~1Tquad: ~D~%" (-> this quad)) + (label cfg-4) + this + ) + +;; definition for method 2 of type vector4w +(defmethod print ((this vector4w)) + (format #t "#" (-> this x) (-> this y) (-> this z) (-> this w) this) + this + ) + +;; definition of type vector4w-2 +(deftype vector4w-2 (structure) + ((data int32 8) + (quad uint128 2 :overlay-at (-> data 0)) + (vector vector4w 2 :inline :overlay-at (-> data 0)) + ) + ) + +;; definition for method 3 of type vector4w-2 +(defmethod inspect ((this vector4w-2)) + (when (not this) + (set! this this) + (goto cfg-4) + ) + (format #t "[~8x] ~A~%" this 'vector4w-2) + (format #t "~1Tdata[8] @ #x~X~%" (-> this vector)) + (format #t "~1Tquad[2] @ #x~X~%" (-> this vector)) + (format #t "~1Tvector[2] @ #x~X~%" (-> this vector)) + (label cfg-4) + this + ) + +;; definition of type vector4w-3 +(deftype vector4w-3 (structure) + ((data int32 12) + (quad uint128 3 :overlay-at (-> data 0)) + (vector vector4w 3 :inline :overlay-at (-> data 0)) + ) + ) + +;; definition for method 3 of type vector4w-3 +(defmethod inspect ((this vector4w-3)) + (when (not this) + (set! this this) + (goto cfg-4) + ) + (format #t "[~8x] ~A~%" this 'vector4w-3) + (format #t "~1Tdata[12] @ #x~X~%" (-> this vector)) + (format #t "~1Tquad[3] @ #x~X~%" (-> this vector)) + (format #t "~1Tvector[3] @ #x~X~%" (-> this vector)) + (label cfg-4) + this + ) + +;; definition of type vector4w-4 +(deftype vector4w-4 (structure) + ((data int32 16) + (quad uint128 4 :overlay-at (-> data 0)) + (vector vector4w 4 :inline :overlay-at (-> data 0)) + ) + ) + +;; definition for method 3 of type vector4w-4 +(defmethod inspect ((this vector4w-4)) + (when (not this) + (set! this this) + (goto cfg-4) + ) + (format #t "[~8x] ~A~%" this 'vector4w-4) + (format #t "~1Tdata[16] @ #x~X~%" (-> this vector)) + (format #t "~1Tquad[4] @ #x~X~%" (-> this vector)) + (format #t "~1Tvector[4] @ #x~X~%" (-> this vector)) + (label cfg-4) + this + ) + +;; definition of type vector4h +(deftype vector4h (structure) + ((data int16 4) + (x int16 :overlay-at (-> data 0)) + (y int16 :overlay-at (-> data 1)) + (z int16 :overlay-at (-> data 2)) + (w int16 :overlay-at (-> data 3)) + (long uint64 :overlay-at (-> data 0)) + ) + :pack-me + ) + +;; definition for method 3 of type vector4h +(defmethod inspect ((this vector4h)) + (when (not this) + (set! this this) + (goto cfg-4) + ) + (format #t "[~8x] ~A~%" this 'vector4h) + (format #t "~1Tdata[4] @ #x~X~%" (-> this data)) + (format #t "~1Tx: ~D~%" (-> this x)) + (format #t "~1Ty: ~D~%" (-> this y)) + (format #t "~1Tz: ~D~%" (-> this z)) + (format #t "~1Tw: ~D~%" (-> this w)) + (format #t "~1Tlong: ~D~%" (-> this long)) + (label cfg-4) + this + ) + +;; definition of type vector8h +(deftype vector8h (structure) + ((data int16 8) + (quad uint128 :overlay-at (-> data 0)) + ) + ) + +;; definition for method 3 of type vector8h +;; INFO: Used lq/sq +(defmethod inspect ((this vector8h)) + (when (not this) + (set! this this) + (goto cfg-4) + ) + (format #t "[~8x] ~A~%" this 'vector8h) + (format #t "~1Tdata[8] @ #x~X~%" (-> this data)) + (format #t "~1Tquad: ~D~%" (-> this quad)) + (label cfg-4) + this + ) + +;; definition of type vector16b +(deftype vector16b (structure) + ((data int8 16) + (quad uint128 :overlay-at (-> data 0)) + ) + ) + +;; definition for method 3 of type vector16b +;; INFO: Used lq/sq +(defmethod inspect ((this vector16b)) + (when (not this) + (set! this this) + (goto cfg-4) + ) + (format #t "[~8x] ~A~%" this 'vector16b) + (format #t "~1Tdata[16] @ #x~X~%" (-> this data)) + (format #t "~1Tquad: ~D~%" (-> this quad)) + (label cfg-4) + this + ) + +;; definition for method 3 of type vector +(defmethod inspect ((this vector)) + (format #t "[~8x] vector~%" this) + (format #t "~T[~F] [~F] [~F] [~F]~%" (-> this x) (-> this y) (-> this z) (-> this w)) + (format #t "~T(static-vectorm ~M ~M ~M)~%" (-> this x) (-> this y) (-> this z)) + this + ) + +;; definition for method 2 of type vector +(defmethod print ((this vector)) + (format #t "#" (-> this x) (-> this y) (-> this z) (-> this w) this) + this + ) + +;; definition for symbol *null-vector*, type vector +(define *null-vector* (new 'static 'vector :w 1.0)) + +;; definition for symbol *identity-vector*, type vector +(define *identity-vector* (new 'static 'vector :x 1.0 :y 1.0 :z 1.0 :w 1.0)) + +;; definition for symbol *x-vector*, type vector +(define *x-vector* (new 'static 'vector :x 1.0 :w 1.0)) + +;; definition for symbol *y-vector*, type vector +(define *y-vector* (new 'static 'vector :y 1.0 :w 1.0)) + +;; definition for symbol *z-vector*, type vector +(define *z-vector* (new 'static 'vector :z 1.0 :w 1.0)) + +;; definition for symbol *up-vector*, type vector +(define *up-vector* (new 'static 'vector :y 1.0 :w 1.0)) + +;; definition of type vector4s-3 +(deftype vector4s-3 (structure) + ((data float 12) + (quad uint128 3 :overlay-at (-> data 0)) + (vector vector 3 :inline :overlay-at (-> data 0)) + ) + ) + +;; definition for method 3 of type vector4s-3 +(defmethod inspect ((this vector4s-3)) + (when (not this) + (set! this this) + (goto cfg-4) + ) + (format #t "[~8x] ~A~%" this 'vector4s-3) + (format #t "~1Tdata[12] @ #x~X~%" (-> this data)) + (format #t "~1Tquad[3] @ #x~X~%" (-> this data)) + (format #t "~1Tvector[3] @ #x~X~%" (-> this data)) + (label cfg-4) + this + ) + +;; definition of type vector-array +(deftype vector-array (inline-array-class) + ((data vector :inline :dynamic) + ) + ) + +;; definition for method 3 of type vector-array +(defmethod inspect ((this vector-array)) + (when (not this) + (set! this this) + (goto cfg-4) + ) + (format #t "[~8x] ~A~%" this (-> this type)) + (format #t "~1Tlength: ~D~%" (-> this length)) + (format #t "~1Tallocated-length: ~D~%" (-> this allocated-length)) + (format #t "~1Tdata[0] @ #x~X~%" (-> this data)) + (label cfg-4) + this + ) + +;; failed to figure out what this is: +(set! (-> vector-array heap-base) (the-as uint 16)) + +;; definition of type rgbaf +(deftype rgbaf (vector) + ((r float :overlay-at (-> data 0)) + (g float :overlay-at (-> data 1)) + (b float :overlay-at (-> data 2)) + (a float :overlay-at (-> data 3)) + ) + ) + +;; definition for method 3 of type rgbaf +;; INFO: Used lq/sq +(defmethod inspect ((this rgbaf)) + (when (not this) + (set! this this) + (goto cfg-4) + ) + (format #t "[~8x] ~A~%" this 'rgbaf) + (format #t "~1Tdata[4] @ #x~X~%" (&-> this x)) + (format #t "~1Tx: ~f~%" (-> this x)) + (format #t "~1Ty: ~f~%" (-> this y)) + (format #t "~1Tz: ~f~%" (-> this z)) + (format #t "~1Tw: ~f~%" (-> this w)) + (format #t "~1Tquad: ~D~%" (-> this quad)) + (format #t "~1Tr: ~f~%" (-> this x)) + (format #t "~1Tg: ~f~%" (-> this y)) + (format #t "~1Tb: ~f~%" (-> this z)) + (format #t "~1Ta: ~f~%" (-> this w)) + (label cfg-4) + this + ) + +;; definition of type plane +(deftype plane (vector) + ((a float :overlay-at (-> data 0)) + (b float :overlay-at (-> data 1)) + (c float :overlay-at (-> data 2)) + (d float :overlay-at (-> data 3)) + ) + ) + +;; definition for method 3 of type plane +;; INFO: Used lq/sq +(defmethod inspect ((this plane)) + (when (not this) + (set! this this) + (goto cfg-4) + ) + (format #t "[~8x] ~A~%" this 'plane) + (format #t "~1Tdata[4] @ #x~X~%" (&-> this x)) + (format #t "~1Tx: ~f~%" (-> this x)) + (format #t "~1Ty: ~f~%" (-> this y)) + (format #t "~1Tz: ~f~%" (-> this z)) + (format #t "~1Tw: ~f~%" (-> this w)) + (format #t "~1Tquad: ~D~%" (-> this quad)) + (format #t "~1Ta: ~f~%" (-> this x)) + (format #t "~1Tb: ~f~%" (-> this y)) + (format #t "~1Tc: ~f~%" (-> this z)) + (format #t "~1Td: ~f~%" (-> this w)) + (label cfg-4) + this + ) + +;; definition of type sphere +(deftype sphere (vector) + ((r float :overlay-at (-> data 3)) + ) + ) + +;; definition for method 3 of type sphere +;; INFO: Used lq/sq +(defmethod inspect ((this sphere)) + (when (not this) + (set! this this) + (goto cfg-4) + ) + (format #t "[~8x] ~A~%" this 'sphere) + (format #t "~1Tdata[4] @ #x~X~%" (&-> this x)) + (format #t "~1Tx: ~f~%" (-> this x)) + (format #t "~1Ty: ~f~%" (-> this y)) + (format #t "~1Tz: ~f~%" (-> this z)) + (format #t "~1Tw: ~f~%" (-> this r)) + (format #t "~1Tquad: ~D~%" (-> this quad)) + (format #t "~1Tr: ~f~%" (-> this r)) + (label cfg-4) + this + ) + +;; definition of type isphere +(deftype isphere (vec4s) + () + ) + +;; definition of type box8s +(deftype box8s (structure) + ((data float 8) + (quad uint128 2 :overlay-at (-> data 0)) + (vector vector 2 :overlay-at (-> data 0)) + (min vector :inline :overlay-at (-> data 0)) + (max vector :inline :overlay-at (-> data 4)) + ) + ) + +;; definition for method 3 of type box8s +(defmethod inspect ((this box8s)) + (when (not this) + (set! this this) + (goto cfg-4) + ) + (format #t "[~8x] ~A~%" this 'box8s) + (format #t "~1Tdata[8] @ #x~X~%" (-> this data)) + (format #t "~1Tquad[2] @ #x~X~%" (-> this data)) + (format #t "~1Tvector[2] @ #x~X~%" (-> this data)) + (format #t "~1Tmin: #~%" (-> this data)) + (format #t "~1Tmax: #~%" (-> this max)) + (label cfg-4) + this + ) + +;; definition of type box8s-array +(deftype box8s-array (inline-array-class) + ((data box8s :inline :dynamic) + ) + ) + +;; definition for method 3 of type box8s-array +(defmethod inspect ((this box8s-array)) + (when (not this) + (set! this this) + (goto cfg-4) + ) + (format #t "[~8x] ~A~%" this (-> this type)) + (format #t "~1Tlength: ~D~%" (-> this length)) + (format #t "~1Tallocated-length: ~D~%" (-> this allocated-length)) + (format #t "~1Tdata[0] @ #x~X~%" (-> this data)) + (label cfg-4) + this + ) + +;; failed to figure out what this is: +(set! (-> box8s-array heap-base) (the-as uint 32)) + +;; definition of type vertical-planes +(deftype vertical-planes (structure) + ((data uint128 4) + ) + ) + +;; definition for method 3 of type vertical-planes +(defmethod inspect ((this vertical-planes)) + (when (not this) + (set! this this) + (goto cfg-4) + ) + (format #t "[~8x] ~A~%" this 'vertical-planes) + (format #t "~1Tdata[4] @ #x~X~%" (-> this data)) + (label cfg-4) + this + ) + +;; definition of type vertical-planes-array +(deftype vertical-planes-array (basic) + ((length uint32) + (data vertical-planes :inline :dynamic) + ) + ) + +;; definition for method 3 of type vertical-planes-array +(defmethod inspect ((this vertical-planes-array)) + (when (not this) + (set! this this) + (goto cfg-4) + ) + (format #t "[~8x] ~A~%" this (-> this type)) + (format #t "~1Tlength: ~D~%" (-> this length)) + (format #t "~1Tdata[0] @ #x~X~%" (-> this data)) + (label cfg-4) + this + ) + +;; definition of type qword +(deftype qword (structure) + ((data uint32 4) + (byte uint8 16 :overlay-at (-> data 0)) + (hword uint16 8 :overlay-at (-> data 0)) + (word uint32 4 :overlay-at (-> data 0)) + (dword uint64 2 :overlay-at (-> data 0)) + (quad uint128 :overlay-at (-> data 0)) + (vector vector :inline :overlay-at (-> data 0)) + (vector4w vector4w :inline :overlay-at (-> data 0)) + ) + ) + +;; definition for method 3 of type qword +;; INFO: Used lq/sq +(defmethod inspect ((this qword)) + (when (not this) + (set! this this) + (goto cfg-4) + ) + (format #t "[~8x] ~A~%" this 'qword) + (format #t "~1Tdata[4] @ #x~X~%" (-> this data)) + (format #t "~1Tbyte[16] @ #x~X~%" (-> this data)) + (format #t "~1Thword[8] @ #x~X~%" (-> this data)) + (format #t "~1Tword[4] @ #x~X~%" (-> this data)) + (format #t "~1Tdword[2] @ #x~X~%" (-> this data)) + (format #t "~1Tquad: ~D~%" (-> this quad)) + (format #t "~1Tvector: #~%" (-> this data)) + (format #t "~1Tvector4w: #~%" (-> this data)) + (label cfg-4) + this + ) + +;; definition of type vector3s +(deftype vector3s (structure) + ((data float 3) + (x float :overlay-at (-> data 0)) + (y float :overlay-at (-> data 1)) + (z float :overlay-at (-> data 2)) + ) + :pack-me + ) + +;; definition for method 3 of type vector3s +(defmethod inspect ((this vector3s)) + (when (not this) + (set! this this) + (goto cfg-4) + ) + (format #t "[~8x] ~A~%" this 'vector3s) + (format #t "~1Tdata[3] @ #x~X~%" (-> this data)) + (format #t "~1Tx: ~f~%" (-> this x)) + (format #t "~1Ty: ~f~%" (-> this y)) + (format #t "~1Tz: ~f~%" (-> this z)) + (label cfg-4) + this + ) + +;; definition for function vector-dot +(defun vector-dot ((arg0 vector) (arg1 vector)) + "Take the dot product of two vectors. +Only does the x, y, z compoments. +Originally handwritten assembly to space out loads and use FPU accumulator" + (vector-dot arg0 arg1) + ) + +;; definition for function vector-dot-vu +(defun vector-dot-vu ((arg0 vector) (arg1 vector)) + "Take the dot product (xyz only). Using VU0." + (local-vars (v0-0 float)) + (rlet ((vf1 :class vf) + (vf2 :class vf) + ) + (.lvf vf1 (&-> arg0 quad)) + (.lvf vf2 (&-> arg1 quad)) + (.mul.vf vf1 vf1 vf2) + (.add.y.vf vf1 vf1 vf1 :mask #b1) + (.add.z.vf vf1 vf1 vf1 :mask #b1) + (.mov v0-0 vf1) + v0-0 + ) + ) + +;; definition for function vector4-dot +(defun vector4-dot ((arg0 vector) (arg1 vector)) + "Take the dot product of two vectors. +Does the x, y, z, and w compoments" + (vector4-dot arg0 arg1) + ) + +;; definition for function vector4-dot-vu +(defun vector4-dot-vu ((arg0 vector) (arg1 vector)) + "Take the dot product (xyzw). Using VU0." + (local-vars (v0-0 float)) + (rlet ((acc :class vf) + (vf0 :class vf) + (vf1 :class vf) + (vf2 :class vf) + (vf3 :class vf) + ) + (init-vf0-vector) + (.lvf vf1 (&-> arg0 quad)) + (.lvf vf2 (&-> arg1 quad)) + (.mul.vf vf1 vf1 vf2) + (.add.w.vf vf3 vf0 vf0 :mask #b1) + (.mul.x.vf acc vf3 vf1 :mask #b1) + (.add.mul.y.vf acc vf3 vf1 acc :mask #b1) + (.add.mul.z.vf acc vf3 vf1 acc :mask #b1) + (.add.mul.w.vf vf1 vf3 vf1 acc :mask #b1) + (.mov v0-0 vf1) + v0-0 + ) + ) + +;; definition for function vector+! +(defun vector+! ((arg0 vector) (arg1 vector) (arg2 vector)) + "Set dst = a + b. The w component of dst is set to 0." + (vector+! arg0 arg1 arg2) + ) + +;; definition for function vector-! +(defun vector-! ((arg0 vector) (arg1 vector) (arg2 vector)) + "Set dst = a - b. The w componenent of dst is set to 0." + (vector-! arg0 arg1 arg2) + ) + +;; definition for function vector-zero! +;; INFO: Used lq/sq +(defun vector-zero! ((arg0 vector)) + "Set xyzw to 0." + (set! (-> arg0 quad) (the-as uint128 0)) + arg0 + ) + +;; definition for function vector-reset! +(defun vector-reset! ((arg0 vector)) + "Set vector to <0,0,0,1>." + (rlet ((vf0 :class vf)) + (init-vf0-vector) + (.svf (&-> arg0 quad) vf0) + arg0 + ) + ) + +;; definition for function vector-copy! +;; INFO: Used lq/sq +(defun vector-copy! ((arg0 vector) (arg1 vector)) + "Copy arg1 to arg0." + (set! (-> arg0 quad) (-> arg1 quad)) + arg0 + ) + +;; definition for function vector-length< +(defun vector-length< ((arg0 vector) (arg1 float)) + (let ((f0-0 (vector-length-squared arg0)) + (f1-0 arg1) + ) + (< f0-0 (* f1-0 f1-0)) + ) + ) + +;; definition for function vector-length> +(defun vector-length> ((arg0 vector) (arg1 float)) + (< (* arg1 arg1) (vector-length-squared arg0)) + ) + +;; definition for symbol *zero-vector*, type vector +(define *zero-vector* (new 'static 'vector)) + +;; failed to figure out what this is: +0 + + + + diff --git a/test/decompiler/reference/jak3/engine/physics/gravity-h_REF.gc b/test/decompiler/reference/jak3/engine/physics/gravity-h_REF.gc new file mode 100644 index 0000000000..8e4b1f21d4 --- /dev/null +++ b/test/decompiler/reference/jak3/engine/physics/gravity-h_REF.gc @@ -0,0 +1,9 @@ +;;-*-Lisp-*- +(in-package goal) + +;; failed to figure out what this is: +0 + + + + diff --git a/test/offline/config/jak3/config.jsonc b/test/offline/config/jak3/config.jsonc index 1b27d02994..586d8f430d 100644 --- a/test/offline/config/jak3/config.jsonc +++ b/test/offline/config/jak3/config.jsonc @@ -1,11 +1,25 @@ { "dgos": [ + "CGO/KERNEL.CGO", "CGO/GAME.CGO" ], "skip_compile_files": [], - "skip_compile_functions": [], + "skip_compile_functions": [ + // math + "logf", + "log2f", + "cube-root", + "lerp-scale", + "rand-vu-init", + "rand-vu", + "rand-vu-nostep", + // matrix + "matrix-axis-sin-cos-vu!", + "matrix-axis-sin-cos!", + "matrix-3x3-normalize!" + ], "skip_compile_states": {} }