alloy::math::mat

Struct Matrix4

source
#[repr(C, align(64))]
pub struct Matrix4(/* private fields */);
Expand description

An owning representation of a 4x4 matrix.

Like Mat4, the Matrix4 object represents a matrix in 4D. Unlike the Mat4, this is an owning representation that stores the actual content of the vector.

Matrix4 does not implement Copy to prevent accidental copying of large amounts of data. If you need to copy the data, you can use the Clone trait.

Implementations§

source§

impl Matrix4

source

pub const ZERO: Self = _

The zero matrix.

source

pub const IDENTITY: Self = _

The identity matrix.

source

pub const fn new() -> Self

Constructs a new 4x4 matrix with the identity matrix.

source

pub const fn identity() -> Self

Constructs a new 4x4 matrix as an identity matrix.

source

pub const fn with_diagonal(diagonal: f32) -> Self

Constructs a new 4x4 matrix with the given value for the diagonal.

§Parameters
  • diagonal - The value to set on the diagonal.
source

pub const fn from_arrays(data: [[f32; 4]; 4]) -> Self

Constructs a new 4x4 matrix from the 4x4 array of f32.

§Parameters
  • data - The 4x4 array of f32 values.
source

pub const fn from_slice(data: &[f32]) -> Self

Constructs a new 4x4 matrix from a slice of 16 f32 values.

This function will panic if the slice does not have a length of at least 16.

§Parameters
  • data - The slice of 16 f32 values.
source

pub const fn from_array_slice(data: &[[f32; 4]]) -> Self

Constructs a new 4x4 matrix from a slice of 4-component arrays of f32.

This function will panic if the slice does not have a length of at least 4.

§Parameters
  • data - The slice of 4-component arrays of f32 values.
source

pub const unsafe fn from_ptr_unchecked(ptr: *const f32) -> Self

Constructs a new 4x4 matrix from a mutable slice of 16 f32 values.

§Parameters
  • data - The mutable pointer to a sequence of 16 f32 values.
§Safety

The caller must ensure that the pointer is valid and points to a sequence of 16 f32 reachable values.

source

pub const fn from_mat4(mat: &Mat4) -> Self

Constructs a new 4x4 matrix with the given Mat4.

§Parameters
  • mat - The Mat4 to copy the values from.
source

pub const fn from_rows(r0: &Vec4, r1: &Vec4, r2: &Vec4, r3: &Vec4) -> Self

Creates a new 4x4 matrix from 4 row vectors.

§Parameters
  • r0 - The first row of the matrix.
  • r1 - The second row of the matrix.
  • r2 - The third row of the matrix.
  • r3 - The fourth row of the matrix.
source

pub const fn from_cols(c0: &Vec4, c1: &Vec4, c2: &Vec4, c3: &Vec4) -> Self

Creates a new 4x4 matrix from 4 column vectors.

§Parameters
  • c0 - The first column of the matrix.
  • c1 - The second column of the matrix.
  • c2 - The third column of the matrix.
  • c3 - The fourth column of the matrix.
source§

impl Matrix4

source

pub const fn as_mat4(&self) -> &Mat4

Returns the row at the given index.

source

pub fn as_mut_mat4(&mut self) -> &mut Mat4

Returns the mutable Mat4 reference.

Methods from Deref<Target = Mat4>§

source

pub const COLS: usize = 4usize

source

pub const ROWS: usize = 4usize

source

pub fn as_slice(&self) -> &[f32]

Returns this Mat4 as a slice of f32.

source

pub fn as_mut_slice(&mut self) -> &mut [f32]

Returns this Mat4 as a mutable slice of f32.

source

pub fn as_ptr(&self) -> *const f32

Returns this vector as a ptr of f32.

source

pub fn as_mut_ptr(&mut self) -> *mut f32

Returns this vector as a mutable ptr of f32.

source

pub fn as_array_slice(&self) -> &[[f32; 4]]

Returns this Mat4 as a slice of 4-component arrays of f32.

source

pub fn as_mut_array_slice(&mut self) -> &mut [[f32; 4]]

Returns this Mat4 as a mutable slice of 4-component arrays of f32.

source

pub fn as_array_ref(&self) -> &[[f32; 4]; 4]

Returns this Mat4 as a reference to a 4x4 array of f32.

source

pub fn as_mut_array_ref(&mut self) -> &mut [[f32; 4]; 4]

Returns this Mat4 as a mutable reference to a 4x4 array of f32.

source

pub fn to_matrix4(&self) -> Matrix4

Returns this Mat4 as a Matrix4.

This function is const, unlike the equivalent From or ToOwned implementations.

source

pub fn row(&self, index: usize) -> &Vec4

Returns the row at the given index.

This function will panic if the given index is out of bounds.

§Parameters
  • index - The index of the row to return.
source

pub unsafe fn row_unchecked(&self, index: usize) -> &Vec4

Returns the row at the given index without performing bounds checking.

§Safety

This function is unsafe because it does not check that the given index is less than 4. If this constraint is violated, memory safety errors can occur.

§Parameters
  • index - The index of the row to return.
source

pub fn mut_row(&mut self, index: usize) -> &mut Vec4

Returns a mutable reference to the row at the given index.

This function will panic if the given index is out of bounds.

§Parameters
  • index - The index of the row to return.
source

pub unsafe fn mut_row_unchecked(&mut self, index: usize) -> &mut Vec4

Returns a mutable reference to the row at the given index without performing bounds checking.

§Safety

This function is unsafe because it does not check that the given index is less than 4. If this constraint is violated, memory safety errors can occur.

§Parameters
  • index - The index of the row to return.
source

pub fn col(&self, index: usize) -> &Col4

Returns the column at the given index.

This function will panic if the given index is out of bounds.

§Parameters
  • index - The index of the column to return.
source

pub unsafe fn col_unchecked(&self, index: usize) -> &Col4

Returns the column at the given index without performing bounds checking.

Note: Unlike Mat4::row_unchecked, this function returns an owning Vector4 instead of a reference of Vec4.

§Safety

This function is unsafe because it does not check that the given index is less than 4. If this constraint is violated, memory safety errors can occur.

§Parameters
  • index - The index of the column to return.
source

pub fn mut_col(&mut self, index: usize) -> &mut Col4

Returns a mutable reference to the column at the given index.

This function will panic if the given index is out of bounds.

§Parameters
  • index - The index of the column to return.
source

pub unsafe fn mut_col_unchecked(&mut self, index: usize) -> &mut Col4

Returns a mutable reference to the column at the given index without performing bounds checking.

§Safety

This function is unsafe because it does not check that the given index is less than 4. If this constraint is violated, memory safety errors can occur.

§Parameters
  • index - The index of the column to return.
source

pub fn get(&self, row: usize, col: usize) -> f32

Returns the value at the given column and row.

This function will panic if the given index is out of bounds.

§Parameters
  • row - The index of the row to return.
  • col - The index of the column to return.
source

pub unsafe fn get_unchecked(&self, row: usize, col: usize) -> f32

Returns the value at the given column and row without performing bounds checking.

§Safety

This function is unsafe because it does not check that the given index is less than 4. If this constraint is violated, memory safety errors can occur.

§Parameters
  • row - The index of the row to return.
  • col - The index of the column to return.
source

pub fn get_mut(&mut self, row: usize, col: usize) -> &mut f32

Returns a mutable reference to the value at the given column and row.

This function will panic if the given index is out of bounds.

§Parameters
  • row - The index of the row to return.
  • col - The index of the column to return.
source

pub unsafe fn get_mut_unchecked(&mut self, row: usize, col: usize) -> &mut f32

Returns a mutable reference to the value at the given column and row without performing bounds checking.

§Safety

This function is unsafe because it does not check that the given index is less than 4. If this constraint is violated, memory safety errors can occur.

§Parameters
  • row - The index of the row to return.
  • col - The index of the column to return.
source

pub fn scale(&mut self, scale: f32)

Scales each component of the matrix by the given scalar.

§Parameters
  • scale - The scalar to multiply each component by.
source

pub fn scale_vec(&mut self, scale: &Vec4)

Scales each row of the matrix by the given vector. This is equivalent to multiplying the matrix by a diagonal matrix with the given vector on the diagonal.

§Parameters
  • scale - The vector to multiply each row by.
source

pub fn transpose(&mut self)

Transposes all the elements of this matrix, swapping rows and columns.

source

pub fn invert(&mut self)

Inverts this matrix.

source

pub fn determinant(&self) -> f32

Returns the determinant of the matrix.

source

pub fn trace(&self) -> f32

Returns the trace of the matrix.

source

pub fn transposed(&self) -> Matrix4

Returns the transpose of the matrix.

source

pub fn inverted(&self) -> Matrix4

Returns the inverse of the matrix.

source

pub fn mul_mat4(&self, other: &Mat4) -> Matrix4

Combines this matrix with another matrix by performing matrix multiplication.

§Parameters
  • other - The matrix to combine with.
source

pub fn mul_col_vec4(&self, vec: &Vec4) -> Vector4

Combines this matrix with a column vector, returning the resultant vector.

This implements matrix-vector of:

| a b c d |   | x |   | ax + by + cz + dw |
| e f g h | * | y | = | ex + fy + gz + hw |
| i j k l |   | z |   | ix + jy + kz + lw |
| m n o p |   | w |   | mx + ny + oz + pw |
§Parameters
  • vec - The vector to combine with.
source

pub fn mul_row_vec4(&self, vec: &Vec4) -> Vector4

Combines this matrix with a row vector, returning the resultant vector.

This implements vector-matrix multiplication of:

| x y z w |   | a b c d |   | ax + ey + iz + mw |
            * | e f g h | = | bx + fy + jz + nw |
              | i j k l |   | cx + gy + kz + ow |
              | m n o p |   | dx + hy + lz + pw |

Trait Implementations§

source§

impl Add<&Mat4> for &Matrix4

source§

type Output = Matrix4

The resulting type after applying the + operator.
source§

fn add(self, rhs: &Mat4) -> Self::Output

Performs the + operation. Read more
source§

impl Add<&Mat4> for Matrix4

source§

type Output = Matrix4

The resulting type after applying the + operator.
source§

fn add(self, rhs: &Mat4) -> Self::Output

Performs the + operation. Read more
source§

impl Add<&Matrix4> for &Mat4

source§

type Output = Matrix4

The resulting type after applying the + operator.
source§

fn add(self, rhs: &Matrix4) -> Self::Output

Performs the + operation. Read more
source§

impl Add<&Matrix4> for Matrix4

source§

type Output = Matrix4

The resulting type after applying the + operator.
source§

fn add(self, rhs: &Matrix4) -> Self::Output

Performs the + operation. Read more
source§

impl Add<Matrix4> for &Mat4

source§

type Output = Matrix4

The resulting type after applying the + operator.
source§

fn add(self, rhs: Matrix4) -> Self::Output

Performs the + operation. Read more
source§

impl Add<Matrix4> for &Matrix4

source§

type Output = Matrix4

The resulting type after applying the + operator.
source§

fn add(self, rhs: Matrix4) -> Self::Output

Performs the + operation. Read more
source§

impl Add for &Matrix4

source§

type Output = Matrix4

The resulting type after applying the + operator.
source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
source§

impl Add for Matrix4

source§

type Output = Matrix4

The resulting type after applying the + operator.
source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
source§

impl AddAssign<&Mat4> for Matrix4

source§

fn add_assign(&mut self, rhs: &Mat4)

Performs the += operation. Read more
source§

impl AddAssign<&Matrix4> for Mat4

source§

fn add_assign(&mut self, rhs: &Matrix4)

Performs the += operation. Read more
source§

impl AddAssign<&Matrix4> for Matrix4

source§

fn add_assign(&mut self, rhs: &Self)

Performs the += operation. Read more
source§

impl AddAssign<Matrix4> for Mat4

source§

fn add_assign(&mut self, rhs: Matrix4)

Performs the += operation. Read more
source§

impl AddAssign for Matrix4

source§

fn add_assign(&mut self, rhs: Self)

Performs the += operation. Read more
source§

impl AsMut<Mat4> for Matrix4

source§

fn as_mut(&mut self) -> &mut Mat4

Converts this type into a mutable reference of the (usually inferred) input type.
source§

impl AsRef<Mat4> for Matrix4

source§

fn as_ref(&self) -> &Mat4

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl Borrow<Mat4> for Matrix4

source§

fn borrow(&self) -> &Mat4

Immutably borrows from an owned value. Read more
source§

impl BorrowMut<Mat4> for Matrix4

source§

fn borrow_mut(&mut self) -> &mut Mat4

Mutably borrows from an owned value. Read more
source§

impl Clone for Matrix4

source§

fn clone(&self) -> Matrix4

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Matrix4

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Matrix4

source§

fn default() -> Matrix4

Returns the “default value” for a type. Read more
source§

impl Deref for Matrix4

source§

type Target = Mat4

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl DerefMut for Matrix4

source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
source§

impl Display for Matrix4

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Div<&Matrix4> for f32

source§

type Output = Matrix4

The resulting type after applying the / operator.
source§

fn div(self, rhs: &Matrix4) -> Self::Output

Performs the / operation. Read more
source§

impl Div<f32> for &Matrix4

source§

type Output = Matrix4

The resulting type after applying the / operator.
source§

fn div(self, rhs: f32) -> Self::Output

Performs the / operation. Read more
source§

impl DivAssign<f32> for Matrix4

source§

fn div_assign(&mut self, rhs: f32)

Performs the /= operation. Read more
source§

impl Mul<&Mat4> for &Matrix4

source§

type Output = Matrix4

The resulting type after applying the * operator.
source§

fn mul(self, rhs: &Mat4) -> Self::Output

Performs the * operation. Read more
source§

impl Mul<&Mat4> for Matrix4

source§

type Output = Matrix4

The resulting type after applying the * operator.
source§

fn mul(self, rhs: &Mat4) -> Self::Output

Performs the * operation. Read more
source§

impl Mul<&Matrix4> for &Mat4

source§

type Output = Matrix4

The resulting type after applying the * operator.
source§

fn mul(self, rhs: &Matrix4) -> Self::Output

Performs the * operation. Read more
source§

impl Mul<&Matrix4> for Matrix4

source§

type Output = Matrix4

The resulting type after applying the * operator.
source§

fn mul(self, rhs: &Matrix4) -> Self::Output

Performs the * operation. Read more
source§

impl Mul<Matrix4> for &Mat4

source§

type Output = Matrix4

The resulting type after applying the * operator.
source§

fn mul(self, rhs: Matrix4) -> Self::Output

Performs the * operation. Read more
source§

impl Mul<Matrix4> for &Matrix4

source§

type Output = Matrix4

The resulting type after applying the * operator.
source§

fn mul(self, rhs: Matrix4) -> Self::Output

Performs the * operation. Read more
source§

impl Mul<f32> for Matrix4

source§

type Output = Matrix4

The resulting type after applying the * operator.
source§

fn mul(self, rhs: f32) -> Self::Output

Performs the * operation. Read more
source§

impl Mul for &Matrix4

source§

type Output = Matrix4

The resulting type after applying the * operator.
source§

fn mul(self, rhs: Self) -> Self::Output

Performs the * operation. Read more
source§

impl Mul for Matrix4

source§

type Output = Matrix4

The resulting type after applying the * operator.
source§

fn mul(self, rhs: Self) -> Self::Output

Performs the * operation. Read more
source§

impl MulAssign<&Mat4> for Matrix4

source§

fn mul_assign(&mut self, rhs: &Mat4)

Performs the *= operation. Read more
source§

impl MulAssign<&Matrix4> for Mat4

source§

fn mul_assign(&mut self, rhs: &Matrix4)

Performs the *= operation. Read more
source§

impl MulAssign<&Matrix4> for Matrix4

source§

fn mul_assign(&mut self, rhs: &Self)

Performs the *= operation. Read more
source§

impl MulAssign<Matrix4> for Mat4

source§

fn mul_assign(&mut self, rhs: Matrix4)

Performs the *= operation. Read more
source§

impl MulAssign<f32> for Matrix4

source§

fn mul_assign(&mut self, rhs: f32)

Performs the *= operation. Read more
source§

impl MulAssign for Matrix4

source§

fn mul_assign(&mut self, rhs: Self)

Performs the *= operation. Read more
source§

impl PartialEq for Matrix4

source§

fn eq(&self, other: &Matrix4) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for Matrix4

source§

fn partial_cmp(&self, other: &Matrix4) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Sub<&Mat4> for &Matrix4

source§

type Output = Matrix4

The resulting type after applying the - operator.
source§

fn sub(self, rhs: &Mat4) -> Self::Output

Performs the - operation. Read more
source§

impl Sub<&Mat4> for Matrix4

source§

type Output = Matrix4

The resulting type after applying the - operator.
source§

fn sub(self, rhs: &Mat4) -> Self::Output

Performs the - operation. Read more
source§

impl Sub<&Matrix4> for &Mat4

source§

type Output = Matrix4

The resulting type after applying the - operator.
source§

fn sub(self, rhs: &Matrix4) -> Self::Output

Performs the - operation. Read more
source§

impl Sub<&Matrix4> for Matrix4

source§

type Output = Matrix4

The resulting type after applying the - operator.
source§

fn sub(self, rhs: &Matrix4) -> Self::Output

Performs the - operation. Read more
source§

impl Sub<Matrix4> for &Mat4

source§

type Output = Matrix4

The resulting type after applying the - operator.
source§

fn sub(self, rhs: Matrix4) -> Self::Output

Performs the - operation. Read more
source§

impl Sub<Matrix4> for &Matrix4

source§

type Output = Matrix4

The resulting type after applying the - operator.
source§

fn sub(self, rhs: Matrix4) -> Self::Output

Performs the - operation. Read more
source§

impl Sub for &Matrix4

source§

type Output = Matrix4

The resulting type after applying the - operator.
source§

fn sub(self, rhs: Self) -> Self::Output

Performs the - operation. Read more
source§

impl Sub for Matrix4

source§

type Output = Matrix4

The resulting type after applying the - operator.
source§

fn sub(self, rhs: Self) -> Self::Output

Performs the - operation. Read more
source§

impl SubAssign<&Mat4> for Matrix4

source§

fn sub_assign(&mut self, rhs: &Mat4)

Performs the -= operation. Read more
source§

impl SubAssign<&Matrix4> for Mat4

source§

fn sub_assign(&mut self, rhs: &Matrix4)

Performs the -= operation. Read more
source§

impl SubAssign<&Matrix4> for Matrix4

source§

fn sub_assign(&mut self, rhs: &Self)

Performs the -= operation. Read more
source§

impl SubAssign<Matrix4> for Mat4

source§

fn sub_assign(&mut self, rhs: Matrix4)

Performs the -= operation. Read more
source§

impl SubAssign for Matrix4

source§

fn sub_assign(&mut self, rhs: Self)

Performs the -= operation. Read more
source§

impl StructuralPartialEq for Matrix4

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.