Skip to main content

Mat4

Struct Mat4 

Source
pub struct Mat4 { /* private fields */ }
Expand description

Column-major 4x4 transformation and perspective projection matrix.

Implementations§

Source§

impl Mat4

Matrix constructors, projection, and point projection for Mat4.

Source

pub const fn identity() -> Self

Identity 4x4 matrix.

§Returns
  • Self - Identity matrix.
Source

pub fn perspective(fov_rad: f32, aspect: f32, near: f32, far: f32) -> Self

Builds a right-handed perspective projection matrix.

§Arguments
  • f32 - Vertical FOV in radians.
  • f32 - Viewport aspect ratio width / height.
  • f32 - Near plane distance.
  • f32 - Far plane distance.
§Returns
  • Self - Perspective projection matrix.
Source

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

Builds a right-handed look-at view matrix.

§Arguments
  • Vec3 - Camera eye position.
  • Vec3 - Target look-at position.
  • Vec3 - World up direction.
§Returns
  • Self - View transformation matrix.
Source

pub fn from_trs(position: Vec3, yaw_rad: f32, scale: Vec3) -> Self

Builds a TRS model matrix (translate * rotate_y * scale).

§Arguments
  • Vec3 - World translation.
  • f32 - Y-axis yaw rotation in radians.
  • Vec3 - Non-uniform scale.
§Returns
  • Self - Composed model transform matrix.
Source

pub fn from_trs_euler( position: Vec3, yaw_rad: f32, pitch_rad: f32, roll_rad: f32, scale: Vec3, ) -> Self

Builds a full 3D Euler TRS model matrix (translate * rotate_y(yaw) * rotate_x(pitch) * rotate_z(roll) * scale).

§Arguments
  • Vec3 - World translation.
  • f32 - Y-axis yaw rotation in radians.
  • f32 - X-axis pitch rotation in radians.
  • f32 - Z-axis roll rotation in radians.
  • Vec3 - Non-uniform scale.
§Returns
  • Self - Composed 3D model transform matrix.
Source

pub fn mul_point4(&self, p: Vec3) -> [f32; 4]

Transforms a 3D point returning homogeneous clip coordinates (x, y, z, w).

§Arguments
  • &Self - Transformation matrix.
  • Vec3 - Input 3D position.
§Returns
  • [f32; 4] - Homogeneous clip-space coordinates.
Source

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

Transforms a 3D point by the upper 3x4 affine portion of self.

§Arguments
  • &Self - Affine transformation matrix.
  • Vec3 - Input 3D position.
§Returns
  • Vec3 - Transformed 3D position.
Source

pub fn mul_vec3(&self, v: Vec3) -> Vec3

Transforms a 3D direction vector by the upper-left 3x3 linear portion of self (no translation).

§Arguments
  • &Self - Transformation matrix.
  • Vec3 - Input 3D vector.
§Returns
  • Vec3 - Linearly transformed 3D vector.
Source

pub fn transform_aabb(&self, local: Aabb3D) -> Aabb3D

Transforms a local Aabb3D into an enclosing world-space Aabb3D via Arvo’s 18-multiply method (zero corner loop, zero trigonometry).

§Arguments
  • &Self - Affine model transformation matrix.
  • Aabb3D - Local-space bounding box.
§Returns
  • Aabb3D - Tight world-space enclosing AABB.
Source

pub fn inverse_trs_euler( position: Vec3, yaw_rad: f32, pitch_rad: f32, roll_rad: f32, scale: Vec3, ) -> Self

Computes the exact analytical inverse of a TRS Euler matrix (S^-1 * R^T * T^-1) for object-space raytracing.

§Arguments
  • Vec3 - World translation.
  • f32 - Y-axis yaw rotation in radians.
  • f32 - X-axis pitch rotation in radians.
  • f32 - Z-axis roll rotation in radians.
  • Vec3 - Non-uniform scale.
§Returns
  • Self - Exact inverse model matrix mapping world space back to local object space.
Source

pub fn normal_basis_from_euler_scale( yaw_rad: f32, pitch_rad: f32, roll_rad: f32, scale: Vec3, ) -> [Vec3; 3]

Computes the inverse-transpose 3x3 normal transformation basis [col_x, col_y, col_z] (R * S^-1) once per object.

§Arguments
  • f32 - Y-axis yaw rotation in radians.
  • f32 - X-axis pitch rotation in radians.
  • f32 - Z-axis roll rotation in radians.
  • Vec3 - Non-uniform scale.
§Returns
  • [Vec3; 3] - Three column vectors transforming local normals into world space.
Source

pub fn transform_normal_with_basis(n: Vec3, basis: [Vec3; 3]) -> Vec3

Transforms a local surface normal using a precomputed 3x3 normal_basis without trigonometry.

§Arguments
  • Vec3 - Local-space normal vector.
  • [Vec3; 3] - Precomputed inverse-transpose 3x3 normal basis [col_x, col_y, col_z].
§Returns
  • Vec3 - Normalized world-space surface normal.
Source§

impl Mat4

Source

pub fn get_m(&self) -> [f32; 16]

Source

pub fn get_mut_m(&mut self) -> &mut [f32; 16]

Source

pub fn set_m(&mut self, val: [f32; 16]) -> &mut Self

Trait Implementations§

Source§

impl Clone for Mat4

Source§

fn clone(&self) -> Self

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 Mat4

Source§

impl Debug for Mat4

Source§

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

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

impl Mul for Mat4

Matrix multiplication self * rhs for Mat4.

Source§

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

Multiplies self * rhs.

§Arguments
  • Self - Left matrix.
  • Self - Right matrix.
§Returns
  • Self - Product matrix.
Source§

type Output = Mat4

The resulting type after applying the * operator.
Source§

impl PartialEq for Mat4

Source§

fn eq(&self, other: &Self) -> 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 Mat4

Auto Trait Implementations§

§

impl Forget for Mat4

§

impl Freeze for Mat4

§

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

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.