#[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_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
.source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)