#[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,
impl<T> Matrix4<T>where
T: FloatScalar,
Sourcepub const IDENTITY: Self
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>
impl<T: FloatScalar> Matrix4<T>
Sourcepub fn determinant(&self) -> T::Scalar
pub fn determinant(&self) -> T::Scalar
Returns the determinant of self.
Sourcepub fn mul_scalar(&self, rhs: T::Scalar) -> Self
pub fn mul_scalar(&self, rhs: T::Scalar) -> Self
Multiplies the matrix by a scalar.
Sourcepub fn div_scalar(&self, rhs: T::Scalar) -> Self
pub fn div_scalar(&self, rhs: T::Scalar) -> Self
Divides the matrix by a scalar.
Sourcepub fn mul_vec4(&self, vec: Vector4<T>) -> Vector4<T>
pub fn mul_vec4(&self, vec: Vector4<T>) -> Vector4<T>
Transforms a 4D vector.
See (e.g.) glam::Mat4::mul_vec4().
Sourcepub fn transform_point3(&self, point: Point3<T>) -> Point3<T>
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).
Sourcepub fn transform_vector3(&self, vector: Vector3<T>) -> Vector3<T>
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).
Sourcepub fn project_point3(&self, vector: Point3<T>) -> Point3<T>
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).
Sourcepub fn from_cols(
x_axis: Vector4<T>,
y_axis: Vector4<T>,
z_axis: Vector4<T>,
w_axis: Vector4<T>,
) -> Self
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.
Sourcepub fn from_scale(vector: Vector3<T>) -> Self
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.
Sourcepub fn from_axis_angle(axis: Vector3<T>, angle: Angle<T::Scalar>) -> Self
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.
Sourcepub fn from_translation(translation: Vector3<T>) -> Self
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().
Sourcepub fn from_scale_rotation_translation(
scale: Vector3<T>,
axis: <T::Scalar as FloatScalar>::Quat,
translation: Vector3<T>,
) -> Self
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.
Sourcepub fn look_at_lh(eye: Point3<T>, center: Point3<T>, up: Vector3<T>) -> Self
pub fn look_at_lh(eye: Point3<T>, center: Point3<T>, up: Vector3<T>) -> Self
See (e.g.) glam::Mat4::look_at_lh().
Sourcepub fn look_at_rh(eye: Point3<T>, center: Point3<T>, up: Vector3<T>) -> Self
pub fn look_at_rh(eye: Point3<T>, center: Point3<T>, up: Vector3<T>) -> Self
See (e.g.) glam::Mat4::look_at_rh().
Sourcepub fn look_to_lh(eye: Point3<T>, dir: Vector3<T>, up: Vector3<T>) -> Self
pub fn look_to_lh(eye: Point3<T>, dir: Vector3<T>, up: Vector3<T>) -> Self
See (e.g.) glam::Mat4::look_to_lh().
Sourcepub fn look_to_rh(eye: Point3<T>, dir: Vector3<T>, up: Vector3<T>) -> Self
pub fn look_to_rh(eye: Point3<T>, dir: Vector3<T>, up: Vector3<T>) -> Self
See (e.g.) glam::Mat4::look_to_rh().
Sourcepub fn perspective_rh_gl(
fov_y_radians: Angle<T::Scalar>,
aspect_ratio: T::Scalar,
z_near: T::Scalar,
z_far: T::Scalar,
) -> Self
pub fn perspective_rh_gl( fov_y_radians: Angle<T::Scalar>, aspect_ratio: T::Scalar, z_near: T::Scalar, z_far: T::Scalar, ) -> Self
See (e.g.) glam::Mat4::perspective_rh_gl().
Sourcepub fn perspective_lh(
fov_y_radians: Angle<T::Scalar>,
aspect_ratio: T::Scalar,
z_near: T::Scalar,
z_far: T::Scalar,
) -> Self
pub fn perspective_lh( fov_y_radians: Angle<T::Scalar>, aspect_ratio: T::Scalar, z_near: T::Scalar, z_far: T::Scalar, ) -> Self
See (e.g.) glam::Mat4::perspective_lh().
Sourcepub fn perspective_rh(
fov_y_radians: Angle<T::Scalar>,
aspect_ratio: T::Scalar,
z_near: T::Scalar,
z_far: T::Scalar,
) -> Self
pub fn perspective_rh( fov_y_radians: Angle<T::Scalar>, aspect_ratio: T::Scalar, z_near: T::Scalar, z_far: T::Scalar, ) -> Self
See (e.g.) glam::Mat4::perspective_rh().
Sourcepub fn perspective_infinite_lh(
fov_y_radians: Angle<T::Scalar>,
aspect_ratio: T::Scalar,
z_near: T::Scalar,
) -> Self
pub fn perspective_infinite_lh( fov_y_radians: Angle<T::Scalar>, aspect_ratio: T::Scalar, z_near: T::Scalar, ) -> Self
See (e.g.) glam::Mat4::perspective_infinite_lh().
Sourcepub fn perspective_infinite_reverse_lh(
fov_y_radians: Angle<T::Scalar>,
aspect_ratio: T::Scalar,
z_near: T::Scalar,
) -> Self
pub fn perspective_infinite_reverse_lh( fov_y_radians: Angle<T::Scalar>, aspect_ratio: T::Scalar, z_near: T::Scalar, ) -> Self
See (e.g.) glam::Mat4::perspective_infinite_reverse_lh().
Sourcepub fn perspective_infinite_rh(
fov_y_radians: Angle<T::Scalar>,
aspect_ratio: T::Scalar,
z_near: T::Scalar,
) -> Self
pub fn perspective_infinite_rh( fov_y_radians: Angle<T::Scalar>, aspect_ratio: T::Scalar, z_near: T::Scalar, ) -> Self
See (e.g.) glam::Mat4::perspective_infinite_rh().
Sourcepub fn perspective_infinite_reverse_rh(
fov_y_radians: Angle<T::Scalar>,
aspect_ratio: T::Scalar,
z_near: T::Scalar,
) -> Self
pub fn perspective_infinite_reverse_rh( fov_y_radians: Angle<T::Scalar>, aspect_ratio: T::Scalar, z_near: T::Scalar, ) -> Self
See (e.g.) glam::Mat4::perspective_infinite_reverse_rh().
Sourcepub fn orthographic_rh_gl(
left: T::Scalar,
right: T::Scalar,
bottom: T::Scalar,
top: T::Scalar,
near: T::Scalar,
far: T::Scalar,
) -> Self
pub fn orthographic_rh_gl( left: T::Scalar, right: T::Scalar, bottom: T::Scalar, top: T::Scalar, near: T::Scalar, far: T::Scalar, ) -> Self
See (e.g.) glam::Mat4::orthographic_rh_gl().
Sourcepub fn orthographic_lh(
left: T::Scalar,
right: T::Scalar,
bottom: T::Scalar,
top: T::Scalar,
near: T::Scalar,
far: T::Scalar,
) -> Self
pub fn orthographic_lh( left: T::Scalar, right: T::Scalar, bottom: T::Scalar, top: T::Scalar, near: T::Scalar, far: T::Scalar, ) -> Self
See (e.g.) glam::Mat4::orthographic_lh().
Sourcepub fn orthographic_rh(
left: T::Scalar,
right: T::Scalar,
bottom: T::Scalar,
top: T::Scalar,
near: T::Scalar,
far: T::Scalar,
) -> Self
pub fn orthographic_rh( left: T::Scalar, right: T::Scalar, bottom: T::Scalar, top: T::Scalar, near: T::Scalar, far: T::Scalar, ) -> Self
See (e.g.) glam::Mat4::orthographic_rh().
Sourcepub fn from_diagonal(diagonal: Vector4<T>) -> Self
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.
Sourcepub fn from_rotation_translation(
rotation: <T::Scalar as FloatScalar>::Quat,
translation: Vector3<T>,
) -> Self
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.
Sourcepub fn from_quat(quat: <T::Scalar as FloatScalar>::Quat) -> Self
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.
Sourcepub fn from_rotation_x(angle: Angle<T::Scalar>) -> Self
pub fn from_rotation_x(angle: Angle<T::Scalar>) -> Self
Creates a 3D rotation matrix from angle around the x axis.
Sourcepub fn from_rotation_y(angle: Angle<T::Scalar>) -> Self
pub fn from_rotation_y(angle: Angle<T::Scalar>) -> Self
Creates a 3D rotation matrix from angle around the y axis.
Sourcepub fn from_rotation_z(angle: Angle<T::Scalar>) -> Self
pub fn from_rotation_z(angle: Angle<T::Scalar>) -> Self
Creates a 3D rotation matrix from angle around the z axis.
Sourcepub fn from_mat3(mat3: Matrix3<T::Scalar>) -> Self
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().
Sourcepub fn to_cols_array(&self) -> [T::Scalar; 16]
pub fn to_cols_array(&self) -> [T::Scalar; 16]
Creates a [T; 16] array storing data in column major order.
Sourcepub fn to_cols_array_2d(&self) -> [[T::Scalar; 4]; 4]
pub fn to_cols_array_2d(&self) -> [[T::Scalar; 4]; 4]
Creates a [[T; 4]; 4] 2D array storing data in column major order.
Sourcepub fn from_cols_array(array: &[T::Scalar; 16]) -> Self
pub fn from_cols_array(array: &[T::Scalar; 16]) -> Self
Creates a 4x4 matrix from a [T; 16] array stored in column major order.
Sourcepub fn from_mat3_translation(
mat3: Matrix3<T::Scalar>,
translation: Vector3<T>,
) -> Self
pub fn from_mat3_translation( mat3: Matrix3<T::Scalar>, translation: Vector3<T>, ) -> Self
Creates an affine transformation matrics from a 3x3 matrix (expressing scale, shear and rotation) and a translation vector.
Sourcepub fn from_rows(
r0: Vector4<T>,
r1: Vector4<T>,
r2: Vector4<T>,
r3: Vector4<T>,
) -> Self
pub fn from_rows( r0: Vector4<T>, r1: Vector4<T>, r2: Vector4<T>, r3: Vector4<T>, ) -> Self
Create from rows (i.e., transposed).
Sourcepub fn is_invertible(&self) -> bool
pub fn is_invertible(&self) -> bool
Return true if the determinant is finite and nonzero.
Sourcepub fn try_inverse(&self) -> Option<Self>
pub fn try_inverse(&self) -> Option<Self>
Get the inverse if the matrix is invertible.
Sourcepub fn to_rows_array(&self) -> [T; 16]
pub fn to_rows_array(&self) -> [T; 16]
Get the columns of the transposed matrix as a scalar array.
Sourcepub fn to_rows_array_2d(&self) -> [[T; 4]; 4]
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>
impl<T> AbsDiffEq for Matrix4<T>
Source§fn default_epsilon() -> Self::Epsilon
fn default_epsilon() -> Self::Epsilon
Source§fn abs_diff_eq(&self, other: &Self, epsilon: Self::Epsilon) -> bool
fn abs_diff_eq(&self, other: &Self, epsilon: Self::Epsilon) -> bool
Source§fn abs_diff_ne(&self, other: &Self, epsilon: Self::Epsilon) -> bool
fn abs_diff_ne(&self, other: &Self, epsilon: Self::Epsilon) -> bool
AbsDiffEq::abs_diff_eq.Source§impl<T> Debug for Matrix4<T>where
T: FloatScalar,
impl<T> Debug for Matrix4<T>where
T: FloatScalar,
Source§impl<T> Default for Matrix4<T>where
T: FloatScalar,
impl<T> Default for Matrix4<T>where
T: FloatScalar,
Source§impl<T> Div<T> for Matrix4<T>where
T: FloatScalar,
impl<T> Div<T> for Matrix4<T>where
T: FloatScalar,
Source§impl<T> DivAssign<T> for Matrix4<T>where
T: FloatScalar,
impl<T> DivAssign<T> for Matrix4<T>where
T: FloatScalar,
Source§fn div_assign(&mut self, rhs: T)
fn div_assign(&mut self, rhs: T)
/= operation. Read moreSource§impl<T> Mul<T> for Matrix4<T>where
T: FloatScalar,
impl<T> Mul<T> for Matrix4<T>where
T: FloatScalar,
Source§impl<T> Mul for Matrix4<T>where
T: FloatScalar,
impl<T> Mul for Matrix4<T>where
T: FloatScalar,
Source§impl<T> MulAssign<T> for Matrix4<T>where
T: FloatScalar,
impl<T> MulAssign<T> for Matrix4<T>where
T: FloatScalar,
Source§fn mul_assign(&mut self, rhs: T)
fn mul_assign(&mut self, rhs: T)
*= operation. Read moreSource§impl<T: FloatScalar> RelativeEq for Matrix4<T>
impl<T: FloatScalar> RelativeEq for Matrix4<T>
Source§fn default_max_relative() -> Self::Epsilon
fn default_max_relative() -> Self::Epsilon
Source§fn relative_eq(
&self,
other: &Self,
epsilon: Self::Epsilon,
max_relative: Self::Epsilon,
) -> bool
fn relative_eq( &self, other: &Self, epsilon: Self::Epsilon, max_relative: Self::Epsilon, ) -> bool
Source§fn relative_ne(
&self,
other: &Self,
epsilon: Self::Epsilon,
max_relative: Self::Epsilon,
) -> bool
fn relative_ne( &self, other: &Self, epsilon: Self::Epsilon, max_relative: Self::Epsilon, ) -> bool
RelativeEq::relative_eq.Source§impl<T: FloatScalar> Transparent for Matrix4<T>
impl<T: FloatScalar> Transparent for Matrix4<T>
Source§type Wrapped = <T as FloatScalar>::Mat4
type Wrapped = <T as FloatScalar>::Mat4
Self.Source§impl<T> UlpsEq for Matrix4<T>
impl<T> UlpsEq for Matrix4<T>
impl<U: Copy + Scalar> Copy for Matrix4<U>
impl<U: Eq + Scalar> Eq for Matrix4<U>
impl<T: Scalar> Pod for Matrix4<T>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CheckedBitPattern for Twhere
T: AnyBitPattern,
impl<T> CheckedBitPattern for Twhere
T: AnyBitPattern,
Source§type Bits = T
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
fn is_valid_bit_pattern(_bits: &T) -> bool
bits
as &Self.