Skip to main content

Matrix4x4

Struct Matrix4x4 

Source
#[repr(C)]
pub struct Matrix4x4 { pub m: [f32; 16], }
Expand description

4x4 homogeneous transformation matrix stored in column-major order.

Matrix indices: [ 0 4 8 12 ] [ 1 5 9 13 ] [ 2 6 10 14 ] [ 3 7 11 15 ]

Fields§

§m: [f32; 16]

Implementations§

Source§

impl Matrix4x4

Source

pub const IDENTITY: Matrix4x4

Source

pub const fn identity() -> Matrix4x4

Source

pub const fn from_array(m: [f32; 16]) -> Matrix4x4

Source

pub const fn from_2d( a: f32, b: f32, c: f32, d: f32, e: f32, f: f32, ) -> Matrix4x4

Constructs a 4x4 matrix from 2D affine matrix components: matrix(a, b, c, d, e, f) where a, c, e are row 0, b, d, f are row 1.

Source

pub fn translation(tx: f32, ty: f32, tz: f32) -> Matrix4x4

Creates a 3D translation matrix.

Source

pub fn scaling(sx: f32, sy: f32, sz: f32) -> Matrix4x4

Creates a 3D scaling matrix.

Source

pub fn rotation_z(rad: f32) -> Matrix4x4

Creates a rotation matrix around the Z axis (standard 2D rotation).

Source

pub fn rotation_x(rad: f32) -> Matrix4x4

Creates a rotation matrix around the X axis.

Source

pub fn rotation_y(rad: f32) -> Matrix4x4

Creates a rotation matrix around the Y axis.

Source

pub fn rotation_axis(x: f32, y: f32, z: f32, rad: f32) -> Matrix4x4

Creates a rotation matrix around an arbitrary 3D axis [x, y, z].

Source

pub fn skew(ax_rad: f32, ay_rad: f32) -> Matrix4x4

Creates a 2D skew matrix given horizontal and vertical angles in radians.

Source

pub fn perspective(d: f32) -> Matrix4x4

Creates a perspective projection matrix where d is the distance to the projection plane.

Source

pub fn multiply(&self, rhs: &Matrix4x4) -> Matrix4x4

Multiplies self by rhs: Result = self * rhs.

Source

pub fn determinant(&self) -> f32

Computes the determinant of the 4x4 matrix using Laplace expansion.

Source

pub fn inverse(&self) -> Option<Matrix4x4>

Computes the analytical inverse of the 4x4 matrix.

Source

pub fn transform_point2d(&self, p: Point) -> Point

Transforms a 2D point using homogeneous coordinates with perspective divide.

Source

pub fn transform_point(&self, x: f32, y: f32) -> (f32, f32)

Transforms 2D coordinates (x, y) using homogeneous coordinates with perspective divide.

Source

pub fn transform_rect(&self, r: Rect) -> Rect

Transforms an axis-aligned rectangle, computing its new bounding box.

Source

pub fn transform_bounds( &self, x: f32, y: f32, width: f32, height: f32, ) -> (f32, f32, f32, f32)

Transforms an axis-aligned rectangle (x, y, width, height) returning the new bounding box (min_x, min_y, w, h).

Source

pub fn is_identity(&self) -> bool

Returns true if this matrix is approximately the identity matrix.

Source

pub fn is_2d(&self) -> bool

Returns true if this matrix represents a pure 2D affine transformation (no Z or perspective).

Trait Implementations§

Source§

impl Clone for Matrix4x4

Source§

fn clone(&self) -> Matrix4x4

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Matrix4x4

Source§

impl Debug for Matrix4x4

Source§

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

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

impl Default for Matrix4x4

Source§

fn default() -> Matrix4x4

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

impl PartialEq for Matrix4x4

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Matrix4x4

Auto Trait Implementations§

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.