#[repr(C)]pub struct Matrix4x4 { /* private fields */ }
Expand description
A 4x4 matrix struct used for graphics programming with OpenGL.
Implementations§
source§impl Matrix4x4
impl Matrix4x4
sourcepub fn new(
m00: f32,
m01: f32,
m02: f32,
m03: f32,
m10: f32,
m11: f32,
m12: f32,
m13: f32,
m20: f32,
m21: f32,
m22: f32,
m23: f32,
m30: f32,
m31: f32,
m32: f32,
m33: f32
) -> Matrix4x4
pub fn new( m00: f32, m01: f32, m02: f32, m03: f32, m10: f32, m11: f32, m12: f32, m13: f32, m20: f32, m21: f32, m22: f32, m23: f32, m30: f32, m31: f32, m32: f32, m33: f32 ) -> Matrix4x4
sourcepub fn from_mat3(m: &Matrix3x3) -> Matrix4x4
pub fn from_mat3(m: &Matrix3x3) -> Matrix4x4
Creates a new 4x4 matrix from a 3x3 matrix.
Arguments
m
- The 3x3 matrix to convert to a 4x4 matrix.
Returns
A new 4x4 matrix with the same values as the input 3x3 matrix, with the fourth row and column set to zero.
Example
use cgl_rs::math::{Matrix3x3, Matrix4x4};
let m3 = Matrix3x3::new(
1.0, 2.0, 3.0,
4.0, 5.0, 6.0,
7.0, 8.0, 9.0
);
let m4 = Matrix4x4::from_mat3(&m3);
sourcepub fn rotate_about_axis(axis: &Vector3, angle: f32) -> Matrix4x4
pub fn rotate_about_axis(axis: &Vector3, angle: f32) -> Matrix4x4
Returns a new rotation matrix that rotates around the given axis by the specified angle.
Arguments
axis
- The axis to rotate around.angle
- The angle of rotation in radians.
Returns
A new rotation matrix that rotates around the given axis by the specified angle.
Example
use cgl_rs::math::{Matrix4x4, Vector3};
let axis = Vector3::new(1.0, 0.0, 0.0);
let m = Matrix4x4::rotate_about_axis(&axis, 0.5);
sourcepub fn perspective(fov: f32, aspect: f32, near: f32, far: f32) -> Matrix4x4
pub fn perspective(fov: f32, aspect: f32, near: f32, far: f32) -> Matrix4x4
Returns a new perspective projection matrix.
Arguments
fov
- The field of view angle in radians.aspect
- The aspect ratio of the projection.near
- The distance to the near clipping plane.far
- The distance to the far clipping plane.
Returns
A new perspective projection matrix.
Example
use cgl_rs::math::Matrix4x4;
let m = Matrix4x4::perspective(cgl_rs::math::constants::PI_2, 16.0/9.0, 0.1, 100.0);
sourcepub fn orthographic(
left: f32,
right: f32,
bottom: f32,
top: f32,
near: f32,
far: f32
) -> Matrix4x4
pub fn orthographic( left: f32, right: f32, bottom: f32, top: f32, near: f32, far: f32 ) -> Matrix4x4
Returns a new orthographic projection matrix.
Arguments
left
- The coordinate for the left vertical clipping plane.right
- The coordinate for the right vertical clipping plane.bottom
- The coordinate for the bottom horizontal clipping plane.top
- The coordinate for the top horizontal clipping plane.near
- The distance to the near clipping plane.far
- The distance to the far clipping plane.
Returns
A new orthographic projection matrix.
Example
use cgl_rs::math::Matrix4x4;
let m = Matrix4x4::orthographic(-1.0, 1.0, -1.0, 1.0, 0.1, 100.0);
sourcepub fn look_at(eye: Vector3, target: Vector3, up: Vector3) -> Matrix4x4
pub fn look_at(eye: Vector3, target: Vector3, up: Vector3) -> Matrix4x4
Returns a new view matrix that looks from the eye position towards the target position.
Arguments
eye
- The position of the camera.target
- The position to look at.up
- The up direction of the camera.
Returns
A new view matrix.
Example
use cgl_rs::math::{Matrix4x4, Vector3};
let mat = Matrix4x4::look_at(
Vector3::new(0.0, 0.0, 0.0),
Vector3::new(0.0, 0.0, -1.0),
Vector3::new(0.0, 1.0, 0.0)
);
sourcepub fn determinant(&self) -> f32
pub fn determinant(&self) -> f32
sourcepub fn mul_vec4(&self, other: &Vector4) -> Vector4
pub fn mul_vec4(&self, other: &Vector4) -> Vector4
Multiplies this matrix by a vector and returns the result.
Arguments
other
- The vector to multiply by.
Returns
The resulting vector of the multiplication.
Example
use cgl_rs::math::{Matrix4x4, Vector4};
let m = Matrix4x4::identity();
let v = Vector4::new(1.0, 2.0, 3.0, 1.0);
let result = m.mul_vec4(&v);
sourcepub fn gaussian_elimination(&self) -> Matrix4x4
pub fn gaussian_elimination(&self) -> Matrix4x4
sourcepub fn to_mat3(&self) -> Matrix3x3
pub fn to_mat3(&self) -> Matrix3x3
Converts this Matrix4x4 to a Matrix3x3 by discarding the last row and column.
Example
use cgl_rs::math::{Matrix3x3, Matrix4x4};
let m = Matrix4x4::identity();
let m3 = m.to_mat3();
sourcepub fn decompose_lu(&self) -> (Matrix4x4, Matrix4x4)
pub fn decompose_lu(&self) -> (Matrix4x4, Matrix4x4)
sourcepub fn lerp(&self, other: &Matrix4x4, t: f32) -> Matrix4x4
pub fn lerp(&self, other: &Matrix4x4, t: f32) -> Matrix4x4
Performs a linear interpolation between this matrix and another matrix.
Arguments
other
- The other matrix to interpolate with.t
- The interpolation factor. Should be between 0.0 and 1.0.
Returns
The interpolated matrix.
Example
use cgl_rs::math::Matrix4x4;
let m1 = Matrix4x4::identity();
let m2 = Matrix4x4::scale(1.0, 2.0, 3.0);
let m3 = m1.lerp(&m2, 0.5);