Types
Variables
Functions
eul->matrix(arg0: matrix, arg1: euler-angles) => matrixsource
Convert from euler angles to 4x4 matrix.
eul->quat(arg0: quaternion, arg1: euler-angles) => quaternionsource
Convert euler angles to quaternion, not very efficient.
matrix->eul(arg0: euler-angles, arg1: matrix, arg2: int) => euler-anglessource
Convert matrix to euler angles with given order flag.
Not clear how this works if the matrix has more than just a rotation.
quat->eul(arg0: euler-angles, arg1: quaternion, arg2: int) => euler-anglessource
Conver quaternion to euler angles with given order, not very efficient.
set-eul!(arg0: euler-angles, arg1: float, arg2: float, arg3: float, arg4: int) => euler-anglessource
Set euler angles and the flag bits.
Types
float-type: uint32source
rgba: uint32source
xyzw: uint128source
xyzwh: uint128source
Functions
fractional-part(arg0: float) => floatsource
Get the fractional part of a float.
lerp(arg0: float, arg1: float, arg2: float) => floatsource
Linearly interpolate between arg0 and arg1.
lerp-clamp(arg0: float, arg1: float, arg2: float) => floatsource
Linearly interpolate between arg0 and arg1. arg2 is clamped to [0, 1]
lerp-scale(arg0: float, arg1: float, arg2: float, arg3: float, arg4: float) => floatsource
Linearly remap arg2 in [arg3, arg4] to [arg0, arg1].
More efficient than the -old version.
lerp-scale-old(arg0: float, arg1: float, arg2: float, arg3: float, arg4: float) => floatsource
log-x-plus-1-order9(arg0: float) => floatsource
Fast approximation of ln(x + 1). Probably only accurate for x in [0, 1].
print-time(arg0: object, arg1: time-frame) => nonesource
Print a time-frame as minutes:seconds:milliseconds
rand-uint31-gen(gen: random-generator) => uintsource
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.
rand-vu-float-range(arg0: float, arg1: float) => floatsource
Get a random float in between arg0 and arg1
rand-vu-init(seed: float) => floatsource
Initialize the VU0 random generator
rand-vu-int-count(arg0: int) => intsource
Get an integer in the range [0, max).
rand-vu-int-count-excluding(arg0: int, arg1: int) => intsource
Get an integer in the range [0, arg0).
If bit n is set in arg1, exclude this value from being returned.
rand-vu-int-range(arg0: int, arg1: int) => intsource
Get an integer in the given range (inclusive)
rand-vu-int-range-exclude(arg0: int, arg1: int, arg2: int) => intsource
Get an integer in the range [0, arg0), excluding arg2.
Note that this doesn't use bits like rand-vu-int-count-excluding.
rand-vu-nostep() => floatsource
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
rand-vu-percent?(arg0: float) => symbolsource
Get a boolean that's true with the given probability (in 0, 1)
sawtooth-wave(arg0: float) => floatsource
Sample a sawtooth with period 1. In range (0, 1)
seek-ease(arg0: float, arg1: float, arg2: float, arg3: float, arg4: float) => floatsource
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.
When closer than arg4, just go all the way there.
seek-ease-in-out(arg0: float, arg1: float, arg2: float, arg3: float, arg4: float, arg5: float, arg6: float) => floatsource
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
smooth-interp(arg0: float, arg1: float, arg2: float, arg3: float, arg4: float) => floatsource
Remap arg2 from (arg3, arg4) to (arg0, arg1), using cubic interpolation.
Satisfies:
- f(arg3) = arg0
- f(arg4) = arg1
- f'(arg3) = f'(arg4) = 0
smooth-step(arg0: float) => floatsource
Interpolate between 0, 1 with a cubic polynomial.
These are picked so f(0) = 0, f(1) = 1, f'(0) = f'(1) = 0.
triangle-wave(arg0: float) => floatsource
Sample a triangle wave. Period is 4, in range (-1, 1) (so slope is 1 or -1).
Variables
*_vu-reg-R_*: intsource
const exp-strail: pointersource
Types
matrix: structuresource
Functions
matrix-copy!(arg0: matrix, arg1: matrix) => matrixsource
Copy arg1 to arg0
Expand description
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.
Functions
column-scale-matrix!(arg0: matrix, arg1: vector, arg2: matrix) => matrixsource
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.
matrix*!(arg0: matrix, arg1: matrix, arg2: matrix) => matrixsource
Set dst = src1 * src2. It is okay for any arguments to be the same data.
This is a moderately efficient implementation.
matrix+!(arg0: matrix, arg1: matrix, arg2: matrix) => matrixsource
Set dst = src1 + src2. It is okay for any arguments to be the same data.
This is not an efficient implementation.
matrix-!(arg0: matrix, arg1: matrix, arg2: matrix) => matrixsource
Set dst = src1 - src1. It is okay for any arugments to be the same data.
This is not an efficient implementation.
matrix-3x3-determinant(arg0: matrix) => floatsource
Compute the determinant of a 3x3 matrix
matrix-3x3-inverse!(arg0: matrix, arg1: matrix) => matrixsource
Compute the inverse of a 3x3 matrix. Not very efficient.
Requires src != dst.
matrix-3x3-inverse-transpose!(arg0: matrix, arg1: matrix) => matrixsource
Invert and transpose.
Requires dst != src.
matrix-3x3-normalize!(arg0: matrix, arg1: matrix) => matrixsource
Unused.
matrix-4x4-determinant(arg0: matrix) => floatsource
Take the determinant of a 4x4 matrix, but this is wrong.
matrix-4x4-inverse!(arg0: matrix, arg1: matrix) => matrixsource
Invert a 4x4 matrix. This assumes that the input is a homogeneous transform.
Src and dst can be the same.
matrix-4x4-inverse-transpose!(arg0: matrix, arg1: matrix) => matrixsource
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.
matrix->quat(arg0: matrix, arg1: quaternion) => quaternionsource
Convert matrix to quaternion, works for matrix with scale.
unlike matrix->quaternion.
matrix->scale(arg0: matrix, arg1: vector) => vectorsource
Get the scale of a matrix.
matrix->trans(arg0: matrix, arg1: vector) => vectorsource
Multiply xyz by 1/w.
matrix->transformq(arg0: transformq, arg1: matrix) => transformqsource
Create a transformq from a matrix. Allowing scale, etc.
matrix-axis-angle!(arg0: matrix, arg1: vector, arg2: float) => matrixsource
Create an axis-angle rotation matrix.
matrix-axis-sin-cos!(dst: matrix, axis: vector, s: float, c: float) => matrixsource
Create an axis-angle rotation matrix. But given the sin/cos of the angle.
matrix-axis-sin-cos-vu!(arg0: matrix, arg1: vector, arg2: float, arg3: float) => nonesource
Create an axis-angle rotation matrix. But given the sin/cos of the angle.
matrix-identity!(arg0: matrix) => matrixsource
Set dst to the identity matrix.
matrix-inv-scale!(arg0: matrix, arg1: vector) => matrixsource
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
matrix-inverse-of-rot-trans!(arg0: matrix, arg1: matrix) => matrixsource
Set dst = src^-1, assuming src is a homogeneous tranform with only rotation/translation.
NOTE: THIS FUNCTION REQUIRES dst != src
matrix-lerp!(arg0: matrix, arg1: matrix, arg2: matrix, arg3: float) => matrixsource
Lerp an entire matrix, coefficient-wise.
matrix-mirror!(arg0: matrix, arg1: vector, arg2: vector) => matrixsource
Make a matrix that mirrors. Arguments are unclear.
matrix-rotate-x!(arg0: matrix, arg1: float) => matrixsource
Set dst to a homogeneous transform matrix for a rotation around the x-axis (degrees)
matrix-rotate-xyz!(arg0: matrix, arg1: vector) => matrixsource
Rotate in x,y,z order
matrix-rotate-xyz-2!(arg0: matrix, arg1: vector) => matrixsource
matrix-rotate-y!(arg0: matrix, arg1: float) => matrixsource
Set dst to a homoegeneous transform matrix for a rotation around the y axis (degrees)
matrix-rotate-yx!(arg0: matrix, arg1: float, arg2: float) => matrixsource
Rotate by y then x.
matrix-rotate-yxy!(arg0: matrix, arg1: vector) => matrixsource
Rotate. I believe in yxy order? Compared to the other rotations, this one
is quite a bit more optimized and avoid repeated trig operations.
matrix-rotate-yxz!(arg0: matrix, arg1: vector) => matrixsource
Rotate in y,x,z order.
matrix-rotate-yzx!(arg0: matrix, arg1: vector) => matrixsource
Rotate in y,z,x order
matrix-rotate-z!(arg0: matrix, arg1: float) => matrixsource
Set dst to a homogeneous transform matrix for a rotation around the z-axis (degrees)
matrix-rotate-zxy!(arg0: matrix, arg1: vector) => matrixsource
Rotate in z,x,y order
matrix-rotate-zyx!(arg0: matrix, arg1: vector) => matrixsource
Rotate in z,y,x order.
matrix-scale!(arg0: matrix, arg1: vector) => matrixsource
Set dst to a homogenous transform with only a scale. The x,y,z components
of scale become the x,y,z scaling factors
matrix-translate!(arg0: matrix, arg1: vector) => matrixsource
Set dst to a homogeneous transform with only a translation of trans
matrix-translate+!(arg0: matrix, arg1: matrix, arg2: vector) => matrixsource
Add the given translation to the translation of homogenous transform mat src
and store in dst. It is okay for dst = src.
matrix-transpose!(dst: matrix, src: matrix) => matrixsource
Set dst = src^T. src and dst can be the same.
matrix-y-angle(arg0: matrix) => floatsource
If mat has its upper 3x3 as a rotation, gets the y axis rotation.
matrix3-determinant(arg0: matrix) => floatsource
Unused. Not sure if this has limitations compared to the above version.
matrix3-inverse-transpose!(arg0: matrix, arg1: matrix) => matrixsource
Unused. Not sure if this has limitations compared to other version.
matrix<-quat(arg0: matrix, arg1: quaternion) => matrixsource
Modify the rotation part of a transform.
matrix<-scale(arg0: matrix, arg1: vector) => matrixsource
Set the scale of a matrix by rescaling.
matrix<-trans(arg0: matrix, arg1: vector) => matrixsource
Set the translation.
matrixp*!(arg0: matrix, arg1: matrix, arg2: matrix) => matrixsource
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.
scale-matrix!(arg0: matrix, arg1: vector, arg2: matrix) => matrixsource
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.
vector-matrix*!(arg0: vector, arg1: vector, arg2: matrix) => vectorsource
Set dst = vec * mat. dst may be equal to src.
vector-rotate*!(arg0: vector, arg1: vector, arg2: matrix) => vectorsource
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.
vector3s-matrix*!(arg0: vector3s, arg1: vector3s, arg2: matrix) => vector3ssource
Set dst to be ([src 1.0] * mat).xyz. Doesn't touch the w of dst.
dst and vec can be the same memory
vector3s-rotate*!(arg0: vector3s, arg1: vector3s, arg2: matrix) => vector3ssource
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).
Variables
Types
quaternion: structuresource
Variables
Functions
matrix->quaternion(arg0: quaternion, arg1: matrix) => quaternionsource
Convert a rotation matrix to a quaternion.
matrix-with-scale->quaternion(arg0: quaternion, arg1: matrix) => quaternionsource
Convert a matrix with a rotation and scale into a quaternion (just the rotation)
quaternion*!(arg0: quaternion, arg1: quaternion, arg2: quaternion) => quaternionsource
Real quaternion multiplication
quaternion+!(arg0: quaternion, arg1: quaternion, arg2: quaternion) => quaternionsource
Add quaternions as vectors.
quaternion-!(arg0: quaternion, arg1: quaternion, arg2: quaternion) => quaternionsource
Subtract quaternions as vectors.
quaternion->matrix(arg0: matrix, arg1: quaternion) => matrixsource
Convert quaternion to matrix.
quaternion->matrix-2(arg0: matrix, arg1: quaternion) => matrixsource
Unused alternate quaternion->matrix function.
quaternion-axis-angle!(arg0: quaternion, arg1: float, arg2: float, arg3: float, arg4: float) => quaternionsource
Construct a quaternion from an axis and angle. The axis should be normalized.
quaternion-conjugate!(arg0: quaternion, arg1: quaternion) => quaternionsource
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.
quaternion-copy!(arg0: quaternion, arg1: quaternion) => quaternionsource
Set arg0 = arg1
quaternion-delta-y(arg0: quaternion, arg1: quaternion) => floatsource
Difference in yaw between two quaternions
quaternion-dot(arg0: quaternion, arg1: quaternion) => floatsource
Treat quaternions as vectors and take the dot product.
quaternion-exp!(arg0: quaternion, arg1: quaternion) => quaternionsource
Quaternion exponentiation. Unused
quaternion-float*!(arg0: quaternion, arg1: quaternion, arg2: float) => quaternionsource
Multiply each element
quaternion-float/!(arg0: quaternion, arg1: quaternion, arg2: float) => quaternionsource
Divide each element
quaternion-i!(arg0: quaternion) => quaternionsource
Create unit i quaternion
quaternion-identity!(arg0: quaternion) => quaternionsource
Set quaternion to 0,0,0,1 (identity)
quaternion-inverse!(arg0: quaternion, arg1: quaternion) => quaternionsource
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!
quaternion-j!(arg0: quaternion) => quaternionsource
Create unit j quaternion.
quaternion-k!(arg0: quaternion) => quaternionsource
Create unit k quaternion
quaternion-left-mult-matrix!(arg0: matrix, arg1: quaternion) => matrixsource
Place quaternion coefficients into a matrix. Unused.
quaternion-log!(arg0: quaternion, arg1: quaternion) => quaternionsource
Take the log of a quaternion. Unused.
quaternion-look-at!(arg0: quaternion, arg1: vector, arg2: vector) => quaternionsource
Look along arg1, with arg2 as up.
quaternion-negate!(arg0: quaternion, arg1: quaternion) => quaternionsource
Set arg0 = -arg1.
quaternion-norm(arg0: quaternion) => floatsource
Get the norm of a quaternion.
quaternion-norm2(arg0: quaternion) => floatsource
Get the squared norm of a quaternion
quaternion-normalize!(arg0: quaternion) => quaternionsource
Normalize a quaternion
quaternion-pseudo-seek(arg0: quaternion, arg1: quaternion, arg2: quaternion, arg3: float) => quaternionsource
Seek one quaternion toward another. Not using real slerp, so this is only good if the quaternions
are pretty similar.
quaternion-pseudo-slerp!(arg0: quaternion, arg1: quaternion, arg2: quaternion, arg3: float) => quaternionsource
This is a bad interpolation between quaternions. It lerps then normalizes.
It will behave extremely poorly for 180 rotations.
It is unused.
quaternion-right-mult-matrix!(arg0: matrix, arg1: quaternion) => matrixsource
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.
quaternion-rotate-local-x!(arg0: quaternion, arg1: quaternion, arg2: float) => quaternionsource
Rotate existing quaternion along x axis.
quaternion-rotate-local-y!(arg0: quaternion, arg1: quaternion, arg2: float) => quaternionsource
Rotate existing quaternion along y axis.
quaternion-rotate-local-z!(arg0: quaternion, arg1: quaternion, arg2: float) => quaternionsource
Rotate existing quaternion along z axis.
quaternion-rotate-x!(arg0: quaternion, arg1: quaternion, arg2: float) => quaternionsource
Rotate existing quaternion along x axis (right multiply)
quaternion-rotate-y!(arg0: quaternion, arg1: quaternion, arg2: float) => quaternionsource
Rotate existing quaternion along y axis (right multiply)
quaternion-rotate-y-to-vector!(arg0: quaternion, arg1: quaternion, arg2: quaternion, arg3: float) => quaternionsource
Rotate along y so z-axis points to match another. Use arg3 as the max rotation amount.
quaternion-rotate-z!(arg0: quaternion, arg1: quaternion, arg2: float) => quaternionsource
Rotate existing quaternion along z axis (right multiply)
quaternion-set!(arg0: quaternion, arg1: float, arg2: float, arg3: float, arg4: float) => quaternionsource
Set arg0 = [arg1, arg2, arg3, arg4]
quaternion-slerp!(arg0: quaternion, arg1: quaternion, arg2: quaternion, arg3: float) => quaternionsource
Real quaternion slerp. Spherical-linear interpolation is a nice way to interpolate
between quaternions.
quaternion-smooth-seek!(arg0: quaternion, arg1: quaternion, arg2: quaternion, arg3: float) => quaternionsource
Another hacky rotation interpolation.
quaternion-validate(arg0: quaternion) => nonesource
quaternion-vector-angle!(arg0: quaternion, arg1: vector, arg2: float) => quaternionsource
Construct a quaternion from an axis and angle. The axis should be normalized.
quaternion-vector-len(arg0: quaternion) => floatsource
Assuming quaternion is normalized, get the length of the xyz part.
quaternion-vector-y-angle(arg0: quaternion, arg1: vector) => floatsource
Not sure. Angle between quaternion and axis, projected in xz plane?
quaternion-x-angle(arg0: quaternion) => floatsource
Get the x rotation angle. Not very efficient
quaternion-xz-angle(arg0: quaternion) => floatsource
yet another function to compute the yaw of a quaternion. This is a particularly inefficient version.
quaternion-y-angle(arg0: quaternion) => floatsource
Get the y rotation angle. Not very efficient
quaternion-z-angle(arg0: quaternion) => floatsource
Get the z rotation angle. Not very efficient
quaternion-zero!(arg0: quaternion) => quaternionsource
Set quaternion to all 0's
quaternion-zxy!(arg0: quaternion, arg1: vector) => quaternionsource
Make a quaternion from a sequence of z, x, y axis rotations.
quaternion<-rotate-y-vector(arg0: quaternion, arg1: vector) => quaternionsource
Create a quaternion representing only the yaw of the given vector
vector-angle<-quaternion!(arg0: vector, arg1: quaternion) => vectorsource
Convert the quaternion arg1 to axis-angle form and store in arg0 (angle goes in w)
vector-rotate-x!(arg0: vector, arg1: vector, arg2: float) => vectorsource
Rotate vector along x axis.
vector-rotate-y!(arg0: vector, arg1: vector, arg2: float) => vectorsource
Rotate vector along y axis.
vector-rotate-z!(arg0: vector, arg1: vector, arg2: float) => vectorsource
Rotate vector along z axis.
vector-x-angle(arg0: vector) => floatsource
Get the pitch angle of a vector.
vector-x-quaternion!(arg0: vector, arg1: quaternion) => vectorsource
Get the first row of the rotation matrix for this quaternion
vector-y-angle(arg0: vector) => floatsource
Get the yaw angle of a vector.
vector-y-quaternion!(arg0: vector, arg1: quaternion) => vectorsource
Get the second row of the rotation matrix for this quaternion
vector-z-quaternion!(arg0: vector, arg1: quaternion) => vectorsource
Get the third row of the rotation matrix for this quaternion
Types
Functions
transform-matrix-calc!(arg0: transform, arg1: matrix) => matrixsource
Convert a transform to matrix. Not efficient, and the output is the second arg.