pub struct Mat4(/* private fields */);Expand description
A 4x4 non-owning view of a matrix.
§Guarantees
This type has the strict requirement that it can only reference a
4x4-component slice of f32 values. It is guaranteed to never refer to
more or less than 2 entries.
This type is always in row-column order, meaning that the first index is the row, and the second index is the column.
§Relation to Matrix4
This type is a non-owning view of a 4x4 matrix, and is used to provide a way to reference a 4x4 matrix without taking ownership of the data.
Implementations§
source§impl Mat4
impl Mat4
sourcepub const unsafe fn from_array_slice_unchecked(data: &[[f32; 4]]) -> &Mat4
pub const unsafe fn from_array_slice_unchecked(data: &[[f32; 4]]) -> &Mat4
Creates a new 4x4 matrix view from a slice of 16 f32 values without
performing bounds checking.
§Safety
This function is unsafe because it does not check that the given slice has a length of 16. If this constraint is violated, memory safety errors can occur.
§Parameters
data- A slice of 16f32values.
sourcepub unsafe fn from_mut_array_slice_unchecked(data: &mut [[f32; 4]]) -> &mut Mat4
pub unsafe fn from_mut_array_slice_unchecked(data: &mut [[f32; 4]]) -> &mut Mat4
Creates a new 4x4 matrix view from a mutable slice of 16 f32 values
without performing bounds checking.
§Safety
This function is unsafe because it does not check that the given slice has a length of 16. If this constraint is violated, memory safety errors can occur.
§Parameters
data- A slice of 16f32values.
sourcepub const fn from_slice(data: &[f32]) -> Option<&Mat4>
pub const fn from_slice(data: &[f32]) -> Option<&Mat4>
sourcepub fn from_mut_slice(data: &mut [f32]) -> Option<&mut Mat4>
pub fn from_mut_slice(data: &mut [f32]) -> Option<&mut Mat4>
sourcepub const unsafe fn from_slice_unchecked(data: &[f32]) -> &Mat4
pub const unsafe fn from_slice_unchecked(data: &[f32]) -> &Mat4
sourcepub unsafe fn from_mut_slice_unchecked(data: &mut [f32]) -> &mut Mat4
pub unsafe fn from_mut_slice_unchecked(data: &mut [f32]) -> &mut Mat4
sourcepub const unsafe fn from_ptr_unchecked<'a>(ptr: *const f32) -> &'a Mat4
pub const unsafe fn from_ptr_unchecked<'a>(ptr: *const f32) -> &'a Mat4
sourcepub unsafe fn from_mut_ptr_unchecked<'a>(ptr: *mut f32) -> &'a mut Vec4
pub unsafe fn from_mut_ptr_unchecked<'a>(ptr: *mut f32) -> &'a mut Vec4
source§impl Mat4
impl Mat4
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 const fn as_array_slice(&self) -> &[[f32; 4]]
pub const 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 const fn as_array_ref(&self) -> &[[f32; 4]; 4]
pub const 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]
source§impl Mat4
impl Mat4
sourcepub const fn row(&self, index: usize) -> &Vec4
pub const 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 const unsafe fn row_unchecked(&self, index: usize) -> &Vec4
pub const 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 const fn col(&self, index: usize) -> &Col4
pub const 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 const unsafe fn col_unchecked(&self, index: usize) -> &Col4
pub const 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 const fn get(&self, row: usize, col: usize) -> f32
pub const 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 const unsafe fn get_unchecked(&self, row: usize, col: usize) -> f32
pub const 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.
source§impl Mat4
impl Mat4
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.
source§impl Mat4
impl Mat4
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 Mat4
impl AddAssign<&Mat4> for Mat4
source§fn add_assign(&mut self, rhs: &Mat4)
fn add_assign(&mut self, rhs: &Mat4)
+= operation. Read moresource§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 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 AsRef<Mat4> for Projection
impl AsRef<Mat4> for Projection
source§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 Mat4
impl DivAssign<f32> for Mat4
source§fn div_assign(&mut self, rhs: f32)
fn div_assign(&mut self, rhs: f32)
/= operation. Read moresource§impl MulAssign<&Mat4> for Mat4
impl MulAssign<&Mat4> for Mat4
source§fn mul_assign(&mut self, rhs: &Mat4)
fn mul_assign(&mut self, rhs: &Mat4)
*= 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 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 Mat4
impl MulAssign<f32> for Mat4
source§fn mul_assign(&mut self, rhs: f32)
fn mul_assign(&mut self, rhs: f32)
*= operation. Read moresource§impl PartialOrd for Mat4
impl PartialOrd for Mat4
source§impl SubAssign<&Mat4> for Mat4
impl SubAssign<&Mat4> for Mat4
source§fn sub_assign(&mut self, rhs: &Mat4)
fn sub_assign(&mut self, rhs: &Mat4)
-= operation. Read moresource§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 Mat4
impl SubAssign<Matrix4> for Mat4
source§fn sub_assign(&mut self, rhs: Matrix4)
fn sub_assign(&mut self, rhs: Matrix4)
-= operation. Read more