Struct citro3d::math::Matrix4

source ·
pub struct Matrix4(/* private fields */);
Expand description

A 4x4 row-major matrix of f32s.

§Layout details

Rows are actually stored as WZYX in memory. There are helper functions for accessing the rows in XYZW form. The Debug implementation prints the shows in WZYX form

It is also guaranteed to have the same layout as citro3d_sys::C3D_Mtx

Implementations§

source§

impl Matrix4

source

pub fn from_cells_wzyx(cells: [f32; 16]) -> Self

Construct a Matrix4 from the cells

§Note

This expects rows to be in WZYX order

source

pub fn from_rows(rows: [FVec4; 4]) -> Self

Construct a Matrix4 from its rows

source

pub fn from_raw(value: C3D_Mtx) -> Self

Create a new matrix from a raw citro3d_sys one

source

pub fn as_raw(&self) -> &C3D_Mtx

source

pub fn as_raw_mut(&mut self) -> &mut C3D_Mtx

source

pub fn into_raw(self) -> C3D_Mtx

source

pub fn rows_wzyx(self) -> [FVec4; 4]

Get the rows in raw (WZYX) form

source

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

Get the rows in XYZW form

source

pub fn zero() -> Self

Construct the zero matrix.

source

pub fn transpose(self) -> Matrix4

Transpose the matrix, swapping rows and columns.

source

pub fn translate(&mut self, x: f32, y: f32, z: f32)

Translate a transformation matrix by the given amounts in the X, Y, and Z directions.

source

pub fn scale(&mut self, x: f32, y: f32, z: f32)

Scale a transformation matrix by the given amounts in the X, Y, and Z directions.

source

pub fn rotate(&mut self, axis: FVec3, angle: f32)

Rotate a transformation matrix by the given angle around the given axis.

source

pub fn rotate_x(&mut self, angle: f32)

Rotate a transformation matrix by the given angle around the X axis.

source

pub fn rotate_y(&mut self, angle: f32)

Rotate a transformation matrix by the given angle around the Y axis.

source

pub fn rotate_z(&mut self, angle: f32)

Rotate a transformation matrix by the given angle around the Z axis.

source

pub fn inverse(self) -> Result<Self, Self>

Find the inverse of the matrix.

§Errors

If the matrix has no inverse, it will be returned unchanged as an [Err].

source

pub fn identity() -> Self

Construct the identity matrix.

source

pub fn diagonal(x: f32, y: f32, z: f32, w: f32) -> Self

Construct a 4x4 matrix with the given values on the diagonal.

source

pub fn looking_at( camera_position: FVec3, camera_target: FVec3, camera_up: FVec3, coordinates: CoordinateOrientation ) -> Self

Construct a 3D transformation matrix for a camera, given its position, target, and upward direction.

Trait Implementations§

source§

impl Add for Matrix4

§

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 Clone for Matrix4

source§

fn clone(&self) -> Matrix4

Returns a copy of the value. Read more
1.0.0§

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 From<&Matrix4> for Uniform

source§

fn from(value: &Matrix4) -> Self

Converts to this type from the input type.
source§

impl From<Mat4> for Matrix4

Available on crate feature glam only.
source§

fn from(mat: Mat4) -> Self

Converts to this type from the input type.
source§

impl From<Matrix4> for Mat4

Available on crate feature glam only.
source§

fn from(mat: Matrix4) -> Self

Converts to this type from the input type.
source§

impl From<Matrix4> for Uniform

source§

fn from(value: Matrix4) -> Self

Converts to this type from the input type.
source§

impl From<Projection<Orthographic>> for Matrix4

source§

fn from(projection: Projection<Orthographic>) -> Self

Converts to this type from the input type.
source§

impl From<Projection<Perspective>> for Matrix4

source§

fn from(projection: Projection<Perspective>) -> Self

Converts to this type from the input type.
source§

impl Mul<FVec<3>> for &Matrix4

§

type Output = FVec<4>

The resulting type after applying the * operator.
source§

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

Performs the * operation. Read more
source§

impl Mul<FVec<4>> for &Matrix4

§

type Output = FVec<4>

The resulting type after applying the * operator.
source§

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

Performs the * operation. Read more
source§

impl Mul<Matrix4> for &Matrix4

§

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 for Matrix4

§

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 PartialEq for Matrix4

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0§

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

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

impl Sub for Matrix4

§

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 Copy for Matrix4

Auto Trait Implementations§

§

impl RefUnwindSafe for Matrix4

§

impl Send for Matrix4

§

impl Sync for Matrix4

§

impl Unpin for Matrix4

§

impl UnwindSafe for Matrix4

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn into(self) -> U

Calls U::from(self).

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

§

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

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

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

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

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

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.