#[repr(C)]pub struct Mat4 {
pub values: [f32; 16],
}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§
Source§impl 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