#[repr(C)]pub struct Matrix4<T: Scalar> {
pub col: [Vector4<T>; 4],
}Expand description
A 4x4 matrix stored in column-major order.
The standard matrix for 3D transformations using homogeneous coordinates.
§Layout
[m₀₀ m₀₁ m₀₂ m₀₃]
[m₁₀ m₁₁ m₁₂ m₁₃]
[m₂₀ m₂₁ m₂₂ m₂₃]
[m₃₀ m₃₁ m₃₂ m₃₃]Fields§
§col: [Vector4<T>; 4]Column vectors of the matrix
Implementations§
Source§impl<T: Scalar> Matrix4<T>
impl<T: Scalar> Matrix4<T>
Sourcepub fn new(
m0: T,
m1: T,
m2: T,
m3: T,
m4: T,
m5: T,
m6: T,
m7: T,
m8: T,
m9: T,
m10: T,
m11: T,
m12: T,
m13: T,
m14: T,
m15: T,
) -> Self
pub fn new( m0: T, m1: T, m2: T, m3: T, m4: T, m5: T, m6: T, m7: T, m8: T, m9: T, m10: T, m11: T, m12: T, m13: T, m14: T, m15: T, ) -> Self
Creates a new 4x4 matrix from column-major elements.
Sourcepub fn determinant(&self) -> T
pub fn determinant(&self) -> T
Computes the determinant of the matrix.
Uses Laplace expansion along the first column. A non-zero determinant indicates the matrix is invertible.
Sourcepub fn is_affine(&self, epsilon: T) -> bool
pub fn is_affine(&self, epsilon: T) -> bool
Returns true if the matrix is affine (last row equals [0, 0, 0, 1]).
Sourcepub fn inverse(&self) -> Self
pub fn inverse(&self) -> Self
Computes the inverse of the matrix.
Uses the adjugate matrix method:
M⁻¹ = (1/det(M)) * adj(M)§Note
Returns NaN or Inf if the matrix is singular (determinant = 0).
Sourcepub fn inverse_affine(&self) -> Self
pub fn inverse_affine(&self) -> Self
Computes the inverse of an affine matrix (rotation/scale + translation).
Assumes the last row is [0, 0, 0, 1].
Sourcepub fn mul_matrix_matrix(l: &Self, r: &Self) -> Self
pub fn mul_matrix_matrix(l: &Self, r: &Self) -> Self
Multiplies two 4x4 matrices.
Matrix multiplication follows the rule:
C[i,j] = Σₖ A[i,k] * B[k,j]Sourcepub fn mul_matrix_vector(l: &Self, r: &Vector4<T>) -> Vector4<T>
pub fn mul_matrix_vector(l: &Self, r: &Vector4<T>) -> Vector4<T>
Multiplies a 4x4 matrix by a 4D vector.
v' = M * vSourcepub fn mul_vector_matrix(l: &Vector4<T>, r: &Self) -> Vector4<T>
pub fn mul_vector_matrix(l: &Vector4<T>, r: &Self) -> Vector4<T>
Multiplies a 4D vector by a 4x4 matrix (row vector).
v' = vᵀ * MSourcepub fn add_matrix_matrix(l: &Self, r: &Self) -> Self
pub fn add_matrix_matrix(l: &Self, r: &Self) -> Self
Adds two matrices element-wise.
C[i,j] = A[i,j] + B[i,j]Sourcepub fn sub_matrix_matrix(l: &Self, r: &Self) -> Self
pub fn sub_matrix_matrix(l: &Self, r: &Self) -> Self
Subtracts two matrices element-wise.
C[i,j] = A[i,j] - B[i,j]