Struct glamour::Matrix4

source ·
#[repr(C)]
pub struct Matrix4<U: Scalar> { pub x_axis: Vector4<U>, pub y_axis: Vector4<U>, pub z_axis: Vector4<U>, pub w_axis: Vector4<U>, }
Expand description

4x4 column-major matrix.

Bitwise compatible with glam::Mat4 / glam::DMat4.

Alignment: Always 16-byte aligned.

Fields§

§x_axis: Vector4<U>§y_axis: Vector4<U>§z_axis: Vector4<U>§w_axis: Vector4<U>

Implementations§

source§

impl<T> Matrix4<T>
where T: FloatScalar,

source

pub const ZERO: Self = _

All zeroes.

source

pub const NAN: Self = _

All NaNs.

source

pub const IDENTITY: Self = _

Identity matrix

§Example
let matrix = Matrix4::<f32>::IDENTITY;
assert_eq!(matrix.row(0), vec4!(1.0, 0.0, 0.0, 0.0));
assert_eq!(matrix.row(1), vec4!(0.0, 1.0, 0.0, 0.0));
assert_eq!(matrix.row(2), vec4!(0.0, 0.0, 1.0, 0.0));
assert_eq!(matrix.row(3), vec4!(0.0, 0.0, 0.0, 1.0));
source§

impl<T: FloatScalar> Matrix4<T>

source

pub fn is_nan(&self) -> bool

Returns true if any elements are NaN.

source

pub fn is_finite(&self) -> bool

Returns true if all elements are finite.

source

pub fn transpose(&self) -> Self

Returns the transpose of self.

source

pub fn inverse(&self) -> Self

Returns the inverse of self.

source

pub fn determinant(&self) -> T::Scalar

Returns the determinant of self.

source

pub fn abs(&self) -> Self

Takes the absolute value of each element in self.

source

pub fn mul_scalar(&self, rhs: T::Scalar) -> Self

Multiplies the matrix by a scalar.

source

pub fn div_scalar(&self, rhs: T::Scalar) -> Self

Divides the matrix by a scalar.

source

pub fn mul_vec4(&self, vec: Vector4<T>) -> Vector4<T>

Transforms a 4D vector.

See (e.g.) glam::Mat4::mul_vec4().

source

pub fn transform_point3(&self, point: Point3<T>) -> Point3<T>

Transform 3D point.

This assumes that the matrix is a valid affine matrix, and does not perform perspective correction.

See glam::Mat4::transform_point3() or glam::DMat4::transform_point3() (depending on the scalar).

source

pub fn transform_vector3(&self, vector: Vector3<T>) -> Vector3<T>

Transform 3D vector.

See glam::Mat4::transform_vector3() or glam::DMat4::transform_vector3() (depending on the scalar).

source

pub fn project_point3(&self, vector: Point3<T>) -> Point3<T>

Project 3D point.

Transform the point, including perspective correction.

See glam::Mat4::project_point3() or glam::DMat4::project_point3() (depending on the scalar).

source

pub fn from_cols( x_axis: Vector4<T>, y_axis: Vector4<T>, z_axis: Vector4<T>, w_axis: Vector4<T>, ) -> Self

Creates a 4x4 matrix from four column vectors.

source

pub fn col(&self, index: usize) -> Vector4<T>

Returns the matrix column for the given index.

§Panics

Panics if index is greater than 3.

source

pub fn row(&self, index: usize) -> Vector4<T>

Returns the matrix row for the given index.

§Panics

Panics if index is greater than 3.

source

pub fn from_scale(vector: Vector3<T>) -> Self

Creates an affine transformation matrix containing the given 3D non-uniform scale.

See (e.g.) glam::Mat4::from_scale().

§Panics

Panics if all elements of scale are zero when glam_assert is enabled.

source

pub fn from_axis_angle(axis: Vector3<T>, angle: Angle<T::Scalar>) -> Self

Creates an affine transformation matrix containing a 3D rotation around a normalized rotation axis of angle.

See (e.g.) glam::Mat4::from_axis_angle().

§Panics

Panics if axis is not normalized when glam_assert is enabled.

source

pub fn from_translation(translation: Vector3<T>) -> Self

Creates an affine transformation matrix from the given 3D translation.

See (e.g.) glam::Mat4::from_translation().

source

pub fn from_scale_rotation_translation( scale: Vector3<T>, axis: <T::Scalar as FloatScalar>::Quat, translation: Vector3<T>, ) -> Self

Creates an affine transformation matrix from the given 3D scale, rotation and translation.

See (e.g.) glam::Mat4::from_scale_rotation_translation().

§Panics

Will panic if rotation is not normalized when glam_assert is enabled.

source

pub fn look_at_lh(eye: Point3<T>, center: Point3<T>, up: Vector3<T>) -> Self

source

pub fn look_at_rh(eye: Point3<T>, center: Point3<T>, up: Vector3<T>) -> Self

source

pub fn look_to_lh(eye: Point3<T>, dir: Vector3<T>, up: Vector3<T>) -> Self

source

pub fn look_to_rh(eye: Point3<T>, dir: Vector3<T>, up: Vector3<T>) -> Self

source

pub fn perspective_rh_gl( fov_y_radians: Angle<T::Scalar>, aspect_ratio: T::Scalar, z_near: T::Scalar, z_far: T::Scalar, ) -> Self

source

pub fn perspective_lh( fov_y_radians: Angle<T::Scalar>, aspect_ratio: T::Scalar, z_near: T::Scalar, z_far: T::Scalar, ) -> Self

source

pub fn perspective_rh( fov_y_radians: Angle<T::Scalar>, aspect_ratio: T::Scalar, z_near: T::Scalar, z_far: T::Scalar, ) -> Self

source

pub fn perspective_infinite_lh( fov_y_radians: Angle<T::Scalar>, aspect_ratio: T::Scalar, z_near: T::Scalar, ) -> Self

source

pub fn perspective_infinite_reverse_lh( fov_y_radians: Angle<T::Scalar>, aspect_ratio: T::Scalar, z_near: T::Scalar, ) -> Self

source

pub fn perspective_infinite_rh( fov_y_radians: Angle<T::Scalar>, aspect_ratio: T::Scalar, z_near: T::Scalar, ) -> Self

source

pub fn perspective_infinite_reverse_rh( fov_y_radians: Angle<T::Scalar>, aspect_ratio: T::Scalar, z_near: T::Scalar, ) -> Self

source

pub fn orthographic_rh_gl( left: T::Scalar, right: T::Scalar, bottom: T::Scalar, top: T::Scalar, near: T::Scalar, far: T::Scalar, ) -> Self

source

pub fn orthographic_lh( left: T::Scalar, right: T::Scalar, bottom: T::Scalar, top: T::Scalar, near: T::Scalar, far: T::Scalar, ) -> Self

source

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

source

pub fn from_diagonal(diagonal: Vector4<T>) -> Self

Creates a 4x4 matrix with its diagonal set to diagonal and all other entries set to 0.

source

pub fn from_rotation_translation( rotation: <T::Scalar as FloatScalar>::Quat, translation: Vector3<T>, ) -> Self

Creates an affine transformation matrix from the given 3D translation.

See (e.g.) glam::Mat4::from_rotation_translation().

§Panics

Will panic if rotation is not normalized when glam_assert is enabled.

source

pub fn from_quat(quat: <T::Scalar as FloatScalar>::Quat) -> Self

Creates an affine transformation matrix from the given rotation quaternion.

See (e.g.) glam::Mat4::from_quat().

§Panics

Will panic if rotation is not normalized when glam_assert is enabled.

source

pub fn from_rotation_x(angle: Angle<T::Scalar>) -> Self

Creates a 3D rotation matrix from angle around the x axis.

source

pub fn from_rotation_y(angle: Angle<T::Scalar>) -> Self

Creates a 3D rotation matrix from angle around the y axis.

source

pub fn from_rotation_z(angle: Angle<T::Scalar>) -> Self

Creates a 3D rotation matrix from angle around the z axis.

source

pub fn from_mat3(mat3: Matrix3<T::Scalar>) -> Self

Create an affine transformation matrix from the given 3x3 linear transformation matrix.

See (e.g.) glam::Mat4::from_mat3().

source

pub fn mul_mat4(&self, other: &Self) -> Self

Multiplies two 4x4 matrices.

source

pub fn add_mat4(&self, other: &Self) -> Self

Adds two 4x4 matrices.

source

pub fn sub_mat4(&self, other: &Self) -> Self

Subtracts two 4x4 matrices.

source

pub fn to_cols_array(&self) -> [T::Scalar; 16]

Creates a [T; 16] array storing data in column major order.

source

pub fn to_cols_array_2d(&self) -> [[T::Scalar; 4]; 4]

Creates a [[T; 4]; 4] 2D array storing data in column major order.

source

pub fn from_cols_array(array: &[T::Scalar; 16]) -> Self

Creates a 4x4 matrix from a [T; 16] array stored in column major order.

source

pub fn from_rows( r0: Vector4<T>, r1: Vector4<T>, r2: Vector4<T>, r3: Vector4<T>, ) -> Self

Create from rows (i.e., transposed).

source

pub fn is_invertible(&self) -> bool

Return true if the determinant is finite and nonzero.

source

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

Get the inverse if the matrix is invertible.

source

pub fn to_rows_array(&self) -> [T; 16]

Get the columns of the transposed matrix as a scalar array.

source

pub fn to_rows_array_2d(&self) -> [[T; 4]; 4]

Get the columns of the transposed matrix.

Trait Implementations§

source§

impl<T> AbsDiffEq for Matrix4<T>
where T: FloatScalar, T::Epsilon: Clone,

source§

type Epsilon = <T as AbsDiffEq>::Epsilon

Used for specifying relative comparisons.
source§

fn default_epsilon() -> Self::Epsilon

The default tolerance to use when testing values that are close together. Read more
source§

fn abs_diff_eq(&self, other: &Self, epsilon: Self::Epsilon) -> bool

A test for equality that uses the absolute difference to compute the approximate equality of two numbers.
source§

fn abs_diff_ne(&self, other: &Self, epsilon: Self::Epsilon) -> bool

The inverse of AbsDiffEq::abs_diff_eq.
source§

impl<T: Scalar> AsMut<[[T; 4]; 4]> for Matrix4<T>

source§

fn as_mut(&mut self) -> &mut [[T; 4]; 4]

Converts this type into a mutable reference of the (usually inferred) input type.
source§

impl<T: Scalar> AsRef<[[T; 4]; 4]> for Matrix4<T>

source§

fn as_ref(&self) -> &[[T; 4]; 4]

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<U: Clone + Scalar> Clone for Matrix4<U>

source§

fn clone(&self) -> Matrix4<U>

Returns a copy 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<T> Debug for Matrix4<T>
where T: FloatScalar,

source§

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

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

impl<T> Default for Matrix4<T>
where T: FloatScalar,

source§

fn default() -> Self

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

impl<T> Div<T> for Matrix4<T>
where T: FloatScalar,

source§

type Output = Matrix4<T>

The resulting type after applying the / operator.
source§

fn div(self, rhs: T) -> Self::Output

Performs the / operation. Read more
source§

impl<T> DivAssign<T> for Matrix4<T>
where T: FloatScalar,

source§

fn div_assign(&mut self, rhs: T)

Performs the /= operation. Read more
source§

impl<T: Scalar> From<[[T; 4]; 4]> for Matrix4<T>

source§

fn from(value: [[T; 4]; 4]) -> Self

Converts to this type from the input type.
source§

impl<T: FloatScalar> From<[T; 16]> for Matrix4<T>

source§

fn from(value: [T; 16]) -> Matrix4<T>

Converts to this type from the input type.
source§

impl From<DMat4> for Matrix4<f64>

source§

fn from(mat: DMat4) -> Self

Converts to this type from the input type.
source§

impl From<Mat4> for Matrix4<f32>

source§

fn from(mat: Mat4) -> Self

Converts to this type from the input type.
source§

impl<T: FloatScalar> From<Matrix4<T>> for [T; 16]

source§

fn from(value: Matrix4<T>) -> [T; 16]

Converts to this type from the input type.
source§

impl From<Matrix4<f32>> for Mat4

source§

fn from(mat: Matrix4<f32>) -> Self

Converts to this type from the input type.
source§

impl From<Matrix4<f64>> for DMat4

source§

fn from(mat: Matrix4<f64>) -> Self

Converts to this type from the input type.
source§

impl<T> Mul<T> for Matrix4<T>
where T: FloatScalar,

source§

type Output = Matrix4<T>

The resulting type after applying the * operator.
source§

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

Performs the * operation. Read more
source§

impl<T> Mul<Vector4<T>> for Matrix4<T::Scalar>
where T: FloatUnit,

source§

type Output = Vector4<T>

The resulting type after applying the * operator.
source§

fn mul(self, rhs: Vector4<T>) -> Self::Output

Performs the * operation. Read more
source§

impl<T> Mul for Matrix4<T>
where T: FloatScalar,

source§

type Output = Matrix4<T>

The resulting type after applying the * operator.
source§

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

Performs the * operation. Read more
source§

impl<T> MulAssign<T> for Matrix4<T>
where T: FloatScalar,

source§

fn mul_assign(&mut self, rhs: T)

Performs the *= operation. Read more
source§

impl<U: PartialEq + Scalar> PartialEq for Matrix4<U>

source§

fn eq(&self, other: &Matrix4<U>) -> 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<T: FloatScalar> RelativeEq for Matrix4<T>

source§

fn default_max_relative() -> Self::Epsilon

The default relative tolerance for testing values that are far-apart. Read more
source§

fn relative_eq( &self, other: &Self, epsilon: Self::Epsilon, max_relative: Self::Epsilon, ) -> bool

A test for equality that uses a relative comparison if the values are far apart.
source§

fn relative_ne( &self, other: &Self, epsilon: Self::Epsilon, max_relative: Self::Epsilon, ) -> bool

The inverse of RelativeEq::relative_eq.
source§

impl<T: FloatScalar> Transparent for Matrix4<T>

source§

type Wrapped = <T as FloatScalar>::Mat4

The inner type that shares a compatible representation with Self.
source§

fn wrap(x: Self::Wrapped) -> Self

Wrap the inner type by copy. Read more
source§

fn peel(x: Self) -> Self::Wrapped

Unwrap the inner type by copy. Read more
source§

fn peel_ref(x: &Self) -> &Self::Wrapped

Convert a reference to the inner type. Read more
source§

fn peel_mut(x: &mut Self) -> &mut Self::Wrapped

Convert a mutable reference to the inner type. Read more
source§

impl<T> UlpsEq for Matrix4<T>
where T: FloatScalar, T::Epsilon: Clone,

source§

fn default_max_ulps() -> u32

The default ULPs to tolerate when testing values that are far-apart. Read more
source§

fn ulps_eq(&self, other: &Self, epsilon: Self::Epsilon, max_ulps: u32) -> bool

A test for equality that uses units in the last place (ULP) if the values are far apart.
source§

fn ulps_ne(&self, other: &Self, epsilon: Self::Epsilon, max_ulps: u32) -> bool

The inverse of UlpsEq::ulps_eq.
source§

impl<T: Scalar> Zeroable for Matrix4<T>

source§

fn zeroed() -> Self

source§

impl<U: Copy + Scalar> Copy for Matrix4<U>

source§

impl<U: Eq + Scalar> Eq for Matrix4<U>

source§

impl<T: Scalar> Pod for Matrix4<T>

source§

impl<U: Scalar> StructuralPartialEq for Matrix4<U>

Auto Trait Implementations§

§

impl<U> Freeze for Matrix4<U>
where U: Freeze,

§

impl<U> RefUnwindSafe for Matrix4<U>
where U: RefUnwindSafe,

§

impl<U> Send for Matrix4<U>

§

impl<U> Sync for Matrix4<U>

§

impl<U> Unpin for Matrix4<U>
where U: Unpin,

§

impl<U> UnwindSafe for Matrix4<U>
where U: UnwindSafe,

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> CheckedBitPattern for T
where T: AnyBitPattern,

source§

type Bits = T

Self must have the same layout as the specified Bits except for the possible invalid bit patterns being checked during is_valid_bit_pattern.
source§

fn is_valid_bit_pattern(_bits: &T) -> bool

If this function returns true, then it must be valid to reinterpret bits as &Self.
source§

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

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> AnyBitPattern for T
where T: Pod,

source§

impl<T> NoUninit for T
where T: Pod,

source§

impl<T> PodValue for T
where T: Copy + Debug + Default + PartialEq + Pod + Send + Sync + Serializable + 'static,

source§

impl<T> Serializable for T

source§

impl<T> WasmComponentType for T