Skip to main content

Mat4

Struct Mat4 

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

4x4 column-major matrix.

Fields§

§cols: [[f32; 4]; 4]

Column 0 (x-axis)

Implementations§

Source§

impl Mat4

Source

pub const IDENTITY: Self

The identity matrix.

Source

pub const ZERO: Self

All zeros.

Source

pub fn col(&self, i: usize) -> [f32; 4]

Returns column i as a 4-element array.

Source

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

Column-major element access: col i, row j.

Source

pub fn from_translation(t: Vec3) -> Self

Creates a translation matrix from a 3D offset.

Source

pub fn from_scale(s: Vec3) -> Self

Creates a non-uniform scale matrix.

Source

pub fn from_rotation(q: Quat) -> Self

Creates a rotation matrix from a unit quaternion.

Source

pub fn from_scale_rotation_translation(s: Vec3, r: Quat, t: Vec3) -> Self

Creates a combined scale-rotation-translation matrix.

Source

pub fn orthographic_lh( left: f32, right: f32, bottom: f32, top: f32, z_near: f32, z_far: f32, ) -> Self

Orthographic projection (left-handed, depth 0..1).

Source

pub fn perspective_lh( fov_y_radians: f32, aspect: f32, z_near: f32, z_far: f32, ) -> Self

Perspective projection (left-handed, depth 0..1).

Source

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

Left-handed look-at view matrix.

Source

pub fn inverse(self) -> Self

Computes the matrix inverse via cofactor expansion.

Source

pub fn transpose(self) -> Self

Returns the transpose of this matrix.

Source

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

Convert to column-major 2D array (for GPU upload).

Source

pub fn from_cols_array_2d(cols: &[[f32; 4]; 4]) -> Self

Create from a column-major 2D array.

Source

pub fn transform_point3(&self, p: Vec3) -> Vec3

Transform a point (w=1, applies translation).

Trait Implementations§

Source§

impl Clone for Mat4

Source§

fn clone(&self) -> Mat4

Returns a duplicate 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 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<'de> Deserialize<'de> for Mat4

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. 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 for Mat4

Source§

type Output = Mat4

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: 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 · 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 Serialize for Mat4

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
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 UnsafeUnpin for Mat4

§

impl UnwindSafe for Mat4

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, dest: *mut u8)

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

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,