Expand description
A struct representing a 4x4 matrix.
It’s values are stored in column-major order by default,
as expected by OpenGL and accepted by all other APIs.
To change this, use feature mat-row-major
Fields
values: [f32; 16]Implementations
sourceimpl Mat4
impl Mat4
sourcepub fn rotate(r: Quaternion) -> Self
pub fn rotate(r: Quaternion) -> Self
Creates a 3D rotation matrix.
sourcepub fn local_to_world(t: Vec3, r: Quaternion, s: Vec3) -> Self
pub fn local_to_world(t: Vec3, r: Quaternion, s: Vec3) -> Self
Creates a 3D local-to-world/object-to-world matrix.
When multiplying this matrix by a vector, it will be
- scaled by
s - rotated by
r - translated by
t
in this order.
sourcepub fn world_to_local(t: Vec3, r: Quaternion, s: Vec3) -> Self
pub fn world_to_local(t: Vec3, r: Quaternion, s: Vec3) -> Self
Creates a 3D world-to-local/world-to-object matrix.
This matrix does the opposite of local_to_world()
sourcepub fn orthographic_vulkan(
left: f32,
right: f32,
bottom: f32,
top: f32,
near: f32,
far: f32
) -> Self
pub fn orthographic_vulkan(
left: f32,
right: f32,
bottom: f32,
top: f32,
near: f32,
far: f32
) -> Self
Creates an orthographic projection matrix with z mapped to [0; 1], as expected by Vulkan.
sourcepub fn orthographic_opengl(
left: f32,
right: f32,
bottom: f32,
top: f32,
near: f32,
far: f32
) -> Self
pub fn orthographic_opengl(
left: f32,
right: f32,
bottom: f32,
top: f32,
near: f32,
far: f32
) -> Self
Creates an orthographic projection matrix with z mapped to [-1; 1], as expected by OpenGL.
sourcepub fn inverse_orthographic_vulkan(
left: f32,
right: f32,
bottom: f32,
top: f32,
near: f32,
far: f32
) -> Self
pub fn inverse_orthographic_vulkan(
left: f32,
right: f32,
bottom: f32,
top: f32,
near: f32,
far: f32
) -> Self
Creates an inverse orthographics projection matrix with z mapped to [0; 1], as expected by Vulkan.
The world position of a uv/depth pair can be reconstructed with the same code as shown
in inverse_perspective_vulkan()
sourcepub fn inverse_orthographic_opengl(
left: f32,
right: f32,
bottom: f32,
top: f32,
near: f32,
far: f32
) -> Self
pub fn inverse_orthographic_opengl(
left: f32,
right: f32,
bottom: f32,
top: f32,
near: f32,
far: f32
) -> Self
Creates an inverse orthographics projection matrix with z mapped to [-1; 1], as expected by OpenGL.
The world position of a uv/depth pair can be reconstructed with the same code as shown
in inverse_perspective_opengl()
sourcepub fn perspective_vulkan(
fov_rad: f32,
near: f32,
far: f32,
aspect: f32
) -> Self
pub fn perspective_vulkan(
fov_rad: f32,
near: f32,
far: f32,
aspect: f32
) -> Self
Creates a perspective projection matrix with z mapped to [0; 1], as expected by Vulkan.
sourcepub fn perspective_opengl(
fov_rad: f32,
near: f32,
far: f32,
aspect: f32
) -> Self
pub fn perspective_opengl(
fov_rad: f32,
near: f32,
far: f32,
aspect: f32
) -> Self
Creates a perspective projection matrix with z mapped to [-1; 1], as expected by OpenGL.
sourcepub fn inverse_perspective_vulkan(
fov_rad: f32,
near: f32,
far: f32,
aspect: f32
) -> Self
pub fn inverse_perspective_vulkan(
fov_rad: f32,
near: f32,
far: f32,
aspect: f32
) -> Self
Creates an inverse perspective matrix with z mapped to [0; 1], as expected by Vulkan.
This matrix can be used to reconstruct the world position from a uv/depth pair in a shader. This pseudo code can be used:
vec4 clipPos = vec4(uv.xy, depth, 1.0);
vec4 worldPos = invProjection * clipPos;
worldPos /= worldPos.w;sourcepub fn inverse_perspective_opengl(
fov_rad: f32,
near: f32,
far: f32,
aspect: f32
) -> Self
pub fn inverse_perspective_opengl(
fov_rad: f32,
near: f32,
far: f32,
aspect: f32
) -> Self
Creates an inverse perspective matrix with z mapped to [-1; 1], as expected by OpenGL.
This matrix can be used to reconstruct the world position from a uv/depth pair in a shader. This pseudo code can be used:
vec4 clipPos = vec4(uv.xy, depth * 2.0 - 1.0, 1.0);
vec4 worldPos = invProjection * clipPos;
worldPos /= worldPos.w;sourcepub const fn get(&self, column: usize, row: usize) -> f32
pub const fn get(&self, column: usize, row: usize) -> f32
Returns a value indexed by column and row
sourcepub fn set(&mut self, column: usize, row: usize, val: f32)
pub fn set(&mut self, column: usize, row: usize, val: f32)
Sets the value indexed by column and row to val
sourcepub fn transposed(&self) -> Mat4
pub fn transposed(&self) -> Mat4
Returns a transposed copy of self.
sourcepub fn as_mut_slice(&mut self) -> &mut [f32]
pub fn as_mut_slice(&mut self) -> &mut [f32]
Returns the underlying values as a mutable slice
sourcepub fn as_ptr(&self) -> *const f32
pub fn as_ptr(&self) -> *const f32
Returns the underlying values as a pointer with no size information
sourcepub fn as_mut_ptr(&mut self) -> *mut f32
pub fn as_mut_ptr(&mut self) -> *mut f32
Returns the underlying values as a mutable pointer with no size information
Trait Implementations
impl Copy for Mat4
impl StructuralPartialEq for Mat4
Auto Trait Implementations
impl RefUnwindSafe for Mat4
impl Send for Mat4
impl Sync for Mat4
impl Unpin for Mat4
impl UnwindSafe for Mat4
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into)Uses borrowed data to replace owned data, usually by cloning. Read more