pub struct Mat4<T>(pub Vec4<T>, pub Vec4<T>, pub Vec4<T>, pub Vec4<T>);Tuple Fields§
§0: Vec4<T>§1: Vec4<T>§2: Vec4<T>§3: Vec4<T>Implementations§
Source§impl<T> Mat4<T>
impl<T> Mat4<T>
Sourcepub fn new(
col0: &Vec4<T>,
col1: &Vec4<T>,
col2: &Vec4<T>,
col3: &Vec4<T>,
) -> Self
pub fn new( col0: &Vec4<T>, col1: &Vec4<T>, col2: &Vec4<T>, col3: &Vec4<T>, ) -> Self
Creates a new Mat4 instance from four column vectors.
§Parameters
col0: The first column vector.col1: The second column vector.col2: The third column vector.col3: The fourth column vector.
§Returns
Returns a new Mat4 with the specified column vectors.
§Examples
let col0 = Vec4::new(1.0, 0.0, 0.0, 0.0);
let col1 = Vec4::new(0.0, 1.0, 0.0, 0.0);
let col2 = Vec4::new(0.0, 0.0, 1.0, 0.0);
let col3 = Vec4::new(0.0, 0.0, 0.0, 1.0);
let mat = Mat4::new(&col0, &col1, &col2, &col3);Sourcepub fn determinant(&self) -> T
pub fn determinant(&self) -> T
Source§impl<T> Mat4<T>
impl<T> Mat4<T>
Sourcepub fn rotate(&mut self, axis: Vec3<T>, angle: T)
pub fn rotate(&mut self, axis: Vec3<T>, angle: T)
Applies a rotation transformation to the matrix around an arbitrary axis.
§Parameters
axis: The axis of rotation as aVec3<T>. It should be normalized.angle: The angle of rotation in radians.
§Examples
use std::f32::consts::PI;
let mut mat = Mat4::identity();
let axis = Vec3::new(0.0, 1.0, 0.0);
let angle = PI / 4.0; // 45 degrees
mat.rotate(&axis, angle);Sourcepub fn rotate_xyz(&mut self, angles: Vec3<T>)
pub fn rotate_xyz(&mut self, angles: Vec3<T>)
Applies a rotation transformation to the matrix around the X, Y, and Z axes sequentially.
The rotations are applied in the order X -> Y -> Z, meaning that:
- First, the matrix is rotated around the X-axis by
angles.x. - Then, the resulting matrix is rotated around the Y-axis by
angles.y. - Finally, the resulting matrix is rotated around the Z-axis by
angles.z.
§Parameters
angles: AVec3<T>containing the rotation angles (in radians) for the X, Y, and Z axes respectively.
§Examples
use std::f32::consts::PI;
let mut mat = Mat4::identity();
let angles = Vec3::new(PI / 4.0, PI / 6.0, PI / 3.0);
mat.rotate_xyz(angles);Sourcepub fn rotate_zyx(&mut self, angles: Vec3<T>)
pub fn rotate_zyx(&mut self, angles: Vec3<T>)
Applies a rotation transformation to the matrix around the Z, Y, and X axes sequentially.
The rotations are applied in the order Z -> Y -> X, meaning that:
- First, the matrix is rotated around the Z-axis by
angles.z. - Then, the resulting matrix is rotated around the Y-axis by
angles.y. - Finally, the resulting matrix is rotated around the X-axis by
angles.x.
§Parameters
angles: AVec3<T>containing the rotation angles (in radians) for the Z, Y, and X axes respectively.
§Examples
use std::f32::consts::PI;
let mut mat = Mat4::identity();
let angles = Vec3::new(PI / 3.0, PI / 6.0, PI / 4.0);
mat.rotate_zyx(angles);Sourcepub fn frustum(
left: T,
right: T,
bottom: T,
top: T,
near_plane: T,
far_plane: T,
) -> Self
pub fn frustum( left: T, right: T, bottom: T, top: T, near_plane: T, far_plane: T, ) -> Self
Creates a frustum matrix for a perspective projection.
The frustum matrix transforms coordinates from the view frustum to normalized device coordinates.
§Parameters
left,right,bottom,top: Coordinates of the clipping planes of the view frustum.near_plane: The distance to the near clipping plane.far_plane: The distance to the far clipping plane.
§Returns
A Mat4<T> representing the frustum projection matrix.
§Examples
let frustum = Mat4::frustum(-1.0, 1.0, -1.0, 1.0, 0.1, 100.0);Sourcepub fn perspective(fov_y: T, aspect: T, near_plane: T, far_plane: T) -> Self
pub fn perspective(fov_y: T, aspect: T, near_plane: T, far_plane: T) -> Self
Creates a perspective projection matrix.
This matrix is used to transform coordinates from a perspective projection view to normalized device coordinates.
§Parameters
fov_y: Field of view in the Y direction (in radians).aspect: Aspect ratio of the viewport (width / height).near_plane: The distance to the near clipping plane.far_plane: The distance to the far clipping plane.
§Returns
A Mat4<T> representing the perspective projection matrix.
§Examples
let perspective = Mat4::perspective(std::f32::consts::PI / 4.0, 16.0 / 9.0, 0.1, 100.0);Sourcepub fn orthographic(
left: T,
right: T,
bottom: T,
top: T,
near_plane: T,
far_plane: T,
) -> Self
pub fn orthographic( left: T, right: T, bottom: T, top: T, near_plane: T, far_plane: T, ) -> Self
Creates an orthographic projection matrix.
This matrix maps 3D coordinates to a 2D view with no perspective distortion. It is useful for 2D games or certain types of 3D projections where depth perception is not needed.
§Parameters
left,right,bottom,top: Coordinates of the clipping planes of the orthographic view.near_plane: The distance to the near clipping plane.far_plane: The distance to the far clipping plane.
§Returns
A Mat4<T> representing the orthographic projection matrix.
§Examples
let ortho = Mat4::orthographic(-1.0, 1.0, -1.0, 1.0, 0.1, 100.0);Sourcepub fn look_at(eye: Vec3<T>, target: Vec3<T>, up: Vec3<T>) -> Self
pub fn look_at(eye: Vec3<T>, target: Vec3<T>, up: Vec3<T>) -> Self
Creates a view matrix that orients the camera to look at a specific target.
The view matrix transforms coordinates from world space to camera (or view) space.
§Parameters
eye: The position of the camera.target: The position the camera is looking at.up: The up direction of the camera.
§Returns
A Mat4<T> representing the view matrix.
§Examples
let eye = Vec3::new(0.0, 0.0, 5.0);
let target = Vec3::new(0.0, 0.0, 0.0);
let up = Vec3::new(0.0, 1.0, 0.0);
let view_matrix = Mat4::look_at(eye, target, up);