Mat4

Struct Mat4 

Source
#[repr(C)]
pub struct Mat4 { pub cols: [Vec4; 4], }
Expand description

A 4x4 column-major matrix.

The matrix is stored in column-major order for GPU compatibility. Columns are accessed as m.cols[column_index].

Fields§

§cols: [Vec4; 4]

Matrix columns.

Implementations§

Source§

impl Mat4

Source

pub const ZERO: Self

Zero matrix.

Source

pub const IDENTITY: Self

Identity matrix.

Source

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

Creates a matrix from column vectors.

Source

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

Creates a matrix from row-major array (converts to column-major).

Source

pub fn from_cols_array(arr: [Float; 16]) -> Self

Creates a matrix from a flat column-major array.

Source

pub fn to_cols_array(self) -> [Float; 16]

Converts to a flat column-major array.

Source

pub fn from_diagonal(diag: Vec4) -> Self

Creates a diagonal matrix.

Source

pub fn from_scale(scale: Vec3) -> Self

Creates a scaling matrix.

Source

pub fn from_translation(translation: Vec3) -> Self

Creates a translation matrix.

Source

pub fn from_rotation_x(angle: Float) -> Self

Creates a rotation matrix around the X axis.

Source

pub fn from_rotation_y(angle: Float) -> Self

Creates a rotation matrix around the Y axis.

Source

pub fn from_rotation_z(angle: Float) -> Self

Creates a rotation matrix around the Z axis.

Source

pub fn from_axis_angle(axis: Vec3, angle: Float) -> Self

Creates a rotation matrix around an arbitrary axis.

Source

pub fn look_at_rh(eye: Vec3, target: Vec3, up: Vec3) -> Self

Creates a look-at view matrix (right-handed).

Source

pub fn look_at_lh(eye: Vec3, target: Vec3, up: Vec3) -> Self

Creates a look-at view matrix (left-handed).

Source

pub fn perspective_rh( fov_y: Float, aspect: Float, near: Float, far: Float, ) -> Self

Creates a perspective projection matrix (right-handed, Vulkan clip space).

  • fov_y: Vertical field of view in radians
  • aspect: Aspect ratio (width / height)
  • near: Near clipping plane
  • far: Far clipping plane
Source

pub fn orthographic_rh( left: Float, right: Float, bottom: Float, top: Float, near: Float, far: Float, ) -> Self

Creates an orthographic projection matrix (right-handed).

Source

pub fn transpose(self) -> Self

Returns the transpose of this matrix.

Source

pub fn determinant(self) -> Float

Computes the determinant.

Source

pub fn try_inverse(self) -> Option<Self>

Returns the inverse of this matrix, or None if not invertible.

Source

pub fn inverse(self) -> Self

Returns the inverse of this matrix.

§Panics

Panics if the matrix is not invertible.

Source

pub fn transform_vec4(self, v: Vec4) -> Vec4

Transforms a Vec4 by this matrix.

Source

pub fn transform_point(self, p: Vec3) -> Vec3

Transforms a point (Vec3 with w=1).

Source

pub fn transform_vector(self, v: Vec3) -> Vec3

Transforms a direction vector (Vec3 with w=0).

Source

pub fn approx_eq(self, other: Self) -> bool

Checks if this matrix is approximately equal to another.

Trait Implementations§

Source§

impl Clone for Mat4

Source§

fn clone(&self) -> Mat4

Returns a duplicate 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 Mat4

Source§

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

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

impl Default for Mat4

Source§

fn default() -> Self

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

impl Mul<Vec4> for Mat4

Source§

type Output = Vec4

The resulting type after applying the * operator.
Source§

fn mul(self, v: Vec4) -> Vec4

Performs the * operation. Read more
Source§

impl Mul<f32> for Mat4

Source§

type Output = Mat4

The resulting type after applying the * operator.
Source§

fn mul(self, s: Float) -> Self

Performs the * operation. Read more
Source§

impl Mul for Mat4

Source§

type Output = Mat4

The resulting type after applying the * operator.
Source§

fn mul(self, other: Self) -> Self

Performs the * operation. Read more
Source§

impl PartialEq for Mat4

Source§

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

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

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

Source§

impl StructuralPartialEq for Mat4

Auto Trait Implementations§

§

impl Freeze for Mat4

§

impl RefUnwindSafe for Mat4

§

impl Send for Mat4

§

impl Sync for Mat4

§

impl Unpin for Mat4

§

impl UnwindSafe for Mat4

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> CloneToUninit for T
where T: Clone,

§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

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.