#[repr(C)]pub struct Mat3 {
pub cols: [Vec3; 3],
}
Expand description
A 3x3 column-major matrix, typically used for 2D affine transformations (scale, rotation).
While it can represent any 3x3 matrix, its primary role in a 3D engine is often
as the upper-left rotation and scale part of a Mat4
.
Fields§
§cols: [Vec3; 3]
The columns of the matrix. cols[0]
is the first column, and so on.
Implementations§
Source§impl Mat3
impl Mat3
Sourcepub fn from_cols(c0: Vec3, c1: Vec3, c2: Vec3) -> Self
pub fn from_cols(c0: Vec3, c1: Vec3, c2: Vec3) -> Self
Creates a new matrix from three column vectors.
Sourcepub fn from_scale_vec2(scale: Vec2) -> Self
pub fn from_scale_vec2(scale: Vec2) -> Self
Creates a 2D scaling matrix.
The Z-axis scale is set to 1.0, making it a no-op in that dimension.
Sourcepub fn from_scale(scale: Vec3) -> Self
pub fn from_scale(scale: Vec3) -> Self
Creates a 3D scaling matrix.
Sourcepub fn from_rotation_x(angle_radians: f32) -> Self
pub fn from_rotation_x(angle_radians: f32) -> Self
Creates a matrix for a rotation around the X-axis.
§Arguments
angle_radians
: The angle of rotation in radians.
Sourcepub fn from_rotation_y(angle_radians: f32) -> Self
pub fn from_rotation_y(angle_radians: f32) -> Self
Creates a matrix for a right-handed rotation around the Y-axis.
§Arguments
angle_radians
: The angle of rotation in radians.
Sourcepub fn from_rotation_z(angle_radians: f32) -> Self
pub fn from_rotation_z(angle_radians: f32) -> Self
Creates a matrix for a rotation around the Z-axis.
§Arguments
angle_radians
: The angle of rotation in radians.
Sourcepub fn from_axis_angle(axis: Vec3, angle_radians: f32) -> Self
pub fn from_axis_angle(axis: Vec3, angle_radians: f32) -> Self
Creates a rotation matrix from a normalized axis and an angle.
§Arguments
axis
: The axis of rotation. Must be a unit vector.angle_radians
: The angle of rotation in radians.
Sourcepub fn from_quat(q: Quaternion) -> Self
pub fn from_quat(q: Quaternion) -> Self
Creates a rotation matrix from a quaternion. The quaternion is normalized before conversion to ensure a valid rotation matrix.
Sourcepub fn from_mat4(m4: &Mat4) -> Self
pub fn from_mat4(m4: &Mat4) -> Self
Creates a Mat3
from the upper-left 3x3 corner of a Mat4
.
This effectively extracts the rotation and scale components, discarding translation.
Sourcepub fn determinant(&self) -> f32
pub fn determinant(&self) -> f32
Computes the determinant of the matrix.
The determinant is a scalar value indicating the volume scaling factor of the linear transformation. A determinant of 0 means the matrix is not invertible.
Sourcepub fn transpose(&self) -> Self
pub fn transpose(&self) -> Self
Returns the transpose of the matrix, where rows and columns are swapped.