#[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
impl Matrix4
sourcepub const fn with_diagonal(diagonal: f32) -> Self
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.
sourcepub const fn from_arrays(data: [[f32; 4]; 4]) -> Self
pub const fn from_arrays(data: [[f32; 4]; 4]) -> Self
sourcepub const fn from_slice(data: &[f32]) -> Self
pub const fn from_slice(data: &[f32]) -> Self
sourcepub const fn from_array_slice(data: &[[f32; 4]]) -> Self
pub const fn from_array_slice(data: &[[f32; 4]]) -> Self
sourcepub const unsafe fn from_ptr_unchecked(ptr: *const f32) -> Self
pub const unsafe fn from_ptr_unchecked(ptr: *const f32) -> Self
Methods from Deref<Target = Mat4>§
pub const COLS: usize = 4usize
pub const ROWS: usize = 4usize
sourcepub fn as_mut_slice(&mut self) -> &mut [f32]
pub fn as_mut_slice(&mut self) -> &mut [f32]
sourcepub fn as_mut_ptr(&mut self) -> *mut f32
pub fn as_mut_ptr(&mut self) -> *mut f32
Returns this vector as a mutable ptr of f32.
sourcepub fn as_array_slice(&self) -> &[[f32; 4]]
pub fn as_array_slice(&self) -> &[[f32; 4]]
sourcepub fn as_mut_array_slice(&mut self) -> &mut [[f32; 4]]
pub fn as_mut_array_slice(&mut self) -> &mut [[f32; 4]]
sourcepub fn as_array_ref(&self) -> &[[f32; 4]; 4]
pub fn as_array_ref(&self) -> &[[f32; 4]; 4]
sourcepub fn as_mut_array_ref(&mut self) -> &mut [[f32; 4]; 4]
pub fn as_mut_array_ref(&mut self) -> &mut [[f32; 4]; 4]
sourcepub fn to_matrix4(&self) -> Matrix4
pub fn to_matrix4(&self) -> Matrix4
sourcepub fn row(&self, index: usize) -> &Vec4
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.
sourcepub unsafe fn row_unchecked(&self, index: usize) -> &Vec4
pub unsafe fn row_unchecked(&self, index: usize) -> &Vec4
sourcepub fn mut_row(&mut self, index: usize) -> &mut Vec4
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.
sourcepub unsafe fn mut_row_unchecked(&mut self, index: usize) -> &mut Vec4
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.
sourcepub fn col(&self, index: usize) -> &Col4
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.
sourcepub unsafe fn col_unchecked(&self, index: usize) -> &Col4
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.
sourcepub fn mut_col(&mut self, index: usize) -> &mut Col4
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.
sourcepub unsafe fn mut_col_unchecked(&mut self, index: usize) -> &mut Col4
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.
sourcepub fn get(&self, row: usize, col: usize) -> f32
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.
sourcepub unsafe fn get_unchecked(&self, row: usize, col: usize) -> f32
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.
sourcepub fn get_mut(&mut self, row: usize, col: usize) -> &mut f32
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.
sourcepub unsafe fn get_mut_unchecked(&mut self, row: usize, col: usize) -> &mut f32
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.
sourcepub fn scale(&mut self, scale: f32)
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.
sourcepub fn scale_vec(&mut self, scale: &Vec4)
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.
sourcepub fn transpose(&mut self)
pub fn transpose(&mut self)
Transposes all the elements of this matrix, swapping rows and columns.
sourcepub fn determinant(&self) -> f32
pub fn determinant(&self) -> f32
Returns the determinant of the matrix.
sourcepub fn transposed(&self) -> Matrix4
pub fn transposed(&self) -> Matrix4
Returns the transpose of the matrix.
sourcepub fn mul_mat4(&self, other: &Mat4) -> Matrix4
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.
sourcepub fn mul_col_vec4(&self, vec: &Vec4) -> Vector4
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.
sourcepub fn mul_row_vec4(&self, vec: &Vec4) -> Vector4
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 AddAssign<&Mat4> for Matrix4
impl AddAssign<&Mat4> for Matrix4
source§fn add_assign(&mut self, rhs: &Mat4)
fn add_assign(&mut self, rhs: &Mat4)
+= operation. Read moresource§impl AddAssign<&Matrix4> for Mat4
impl AddAssign<&Matrix4> for Mat4
source§fn add_assign(&mut self, rhs: &Matrix4)
fn add_assign(&mut self, rhs: &Matrix4)
+= operation. Read moresource§impl AddAssign<&Matrix4> for Matrix4
impl AddAssign<&Matrix4> for Matrix4
source§fn add_assign(&mut self, rhs: &Self)
fn add_assign(&mut self, rhs: &Self)
+= operation. Read moresource§impl AddAssign<Matrix4> for Mat4
impl AddAssign<Matrix4> for Mat4
source§fn add_assign(&mut self, rhs: Matrix4)
fn add_assign(&mut self, rhs: Matrix4)
+= operation. Read moresource§impl AddAssign for Matrix4
impl AddAssign for Matrix4
source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
+= operation. Read moresource§impl BorrowMut<Mat4> for Matrix4
impl BorrowMut<Mat4> for Matrix4
source§fn borrow_mut(&mut self) -> &mut Mat4
fn borrow_mut(&mut self) -> &mut Mat4
source§impl DivAssign<f32> for Matrix4
impl DivAssign<f32> for Matrix4
source§fn div_assign(&mut self, rhs: f32)
fn div_assign(&mut self, rhs: f32)
/= operation. Read moresource§impl MulAssign<&Mat4> for Matrix4
impl MulAssign<&Mat4> for Matrix4
source§fn mul_assign(&mut self, rhs: &Mat4)
fn mul_assign(&mut self, rhs: &Mat4)
*= operation. Read moresource§impl MulAssign<&Matrix4> for Mat4
impl MulAssign<&Matrix4> for Mat4
source§fn mul_assign(&mut self, rhs: &Matrix4)
fn mul_assign(&mut self, rhs: &Matrix4)
*= operation. Read moresource§impl MulAssign<&Matrix4> for Matrix4
impl MulAssign<&Matrix4> for Matrix4
source§fn mul_assign(&mut self, rhs: &Self)
fn mul_assign(&mut self, rhs: &Self)
*= operation. Read moresource§impl MulAssign<Matrix4> for Mat4
impl MulAssign<Matrix4> for Mat4
source§fn mul_assign(&mut self, rhs: Matrix4)
fn mul_assign(&mut self, rhs: Matrix4)
*= operation. Read moresource§impl MulAssign<f32> for Matrix4
impl MulAssign<f32> for Matrix4
source§fn mul_assign(&mut self, rhs: f32)
fn mul_assign(&mut self, rhs: f32)
*= operation. Read moresource§impl MulAssign for Matrix4
impl MulAssign for Matrix4
source§fn mul_assign(&mut self, rhs: Self)
fn mul_assign(&mut self, rhs: Self)
*= operation. Read moresource§impl PartialOrd for Matrix4
impl PartialOrd for Matrix4
source§impl SubAssign<&Mat4> for Matrix4
impl SubAssign<&Mat4> for Matrix4
source§fn sub_assign(&mut self, rhs: &Mat4)
fn sub_assign(&mut self, rhs: &Mat4)
-= operation. Read moresource§impl SubAssign<&Matrix4> for Mat4
impl SubAssign<&Matrix4> for Mat4
source§fn sub_assign(&mut self, rhs: &Matrix4)
fn sub_assign(&mut self, rhs: &Matrix4)
-= operation. Read moresource§impl SubAssign<&Matrix4> for Matrix4
impl SubAssign<&Matrix4> for Matrix4
source§fn sub_assign(&mut self, rhs: &Self)
fn sub_assign(&mut self, rhs: &Self)
-= operation. Read moresource§impl SubAssign<Matrix4> for Mat4
impl SubAssign<Matrix4> for Mat4
source§fn sub_assign(&mut self, rhs: Matrix4)
fn sub_assign(&mut self, rhs: Matrix4)
-= operation. Read moresource§impl SubAssign for Matrix4
impl SubAssign for Matrix4
source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
-= operation. Read moreimpl StructuralPartialEq for Matrix4
Auto Trait Implementations§
impl Freeze for Matrix4
impl RefUnwindSafe for Matrix4
impl Send for Matrix4
impl Sync for Matrix4
impl Unpin for Matrix4
impl UnwindSafe for Matrix4
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)