Skip to main content

Module transform

Module transform 

Source
Expand description

The engine’s transform convention, in one place: the column-major 4x4 layout every renderer uniform is written in, the multiply and the two inverses over it, the T * R(YXZ) * S composition joints and props both build their matrix through, and the quaternion conversions that let a rotation be interpolated along the shorter arc rather than component-wise through its Euler angles.

Constants§

IDENTITY
Column-major 4x4 identity.

Functions§

blend_matrices
Interpolate two affine matrices in TRS space by weight f, clamped to [0, 1]. Translation and scale blend linearly while rotation is quaternion-slerped along the shorter arc, matching what a clip does between keyframes, so a blended pose is continuous with a clip’s own sampling.
compose
Compose a column-major T * R * S affine matrix from a rotation 3x3, per-axis scale, and translation.
decompose
Decompose a column-major affine matrix into translation, a unit rotation quaternion, and per-axis scale: the inverse of compose for a positive-scale T * R * S matrix. Scale is recovered as the length of each rotation column; a zero-length column yields a zero scale axis and the rotation falls back to identity for that axis.
euler_yxz_from_quat
YXZ Euler angles in degrees recovered from a unit rotation quaternion: the inverse of rotation_mat3 composed with quat_to_mat3. glTF stores node rotations as quaternions; the glTF importer converts them to the Euler JointPose representation this engine’s joints use. The conversion is matrix-exact for non-degenerate rotations; at gimbal lock (pitch ±90°) it folds the rotation onto the yaw axis with zero roll.
mat4_affine_inverse
Inverse of an affine matrix whose bottom row is [0, 0, 0, 1]. The upper 3x3 is inverted via the adjugate; the translation is mapped through it. A near-singular upper 3x3 (degenerate scale) falls back to identity rather than producing NaNs.
mat4_inverse
Inverse of a general 4x4 matrix, by cofactor expansion. Returns IDENTITY when the determinant is singular or non-finite, so a degenerate input yields a usable matrix instead of spreading NaNs through the pass that asked. Unlike mat4_affine_inverse this handles a projection’s bottom row, which is what the screen-space passes need to invert a view-projection and rebuild world position from depth.
mat4_mul
Column-major 4x4 multiply: a * b.
trs_matrix
Column-major T * R(YXZ) * S model matrix. The single home of the engine’s transform convention: joints, props, and runtime transforms all build their matrix here so they compose consistently.

Type Aliases§

Mat3
Column-major 3x3 rotation matrix, m[col][row].
Mat4
Column-major 4x4 matrix, m[col][row]: the layout shared by every renderer uniform in this codebase.