Constructs a 4x4 identity matrix.
use gamemath::{Mat4, Vec4};
let m = Mat4::identity();
assert_eq!(m[0], Vec4::new(1.0, 0.0, 0.0, 0.0));
assert_eq!(m[1], Vec4::new(0.0, 1.0, 0.0, 0.0));
assert_eq!(m[2], Vec4::new(0.0, 0.0, 1.0, 0.0));
assert_eq!(m[3], Vec4::new(0.0, 0.0, 0.0, 1.0));
Constructs a 4x4 frustum matrix from a top, left, right, bottom, near and far value.
use gamemath::{Mat4, Vec4};
let m = Mat4::frustum(-10.0, -10.0, 10.0, 10.0, 0.1, 100.0);
assert_eq!(m[0], Vec4::new(0.01, 0.0, 0.0, 0.0));
assert_eq!(m[1], Vec4::new(0.0, -0.01, 0.0, 0.0));
assert_eq!(m[2], Vec4::new(0.0, 0.0, -1.002002, -1.0));
assert_eq!(m[3], Vec4::new(0.0, 0.0, -0.2002002, 0.0));
Constructs a 4x4 perspective-projection matrix from a fov, aspect, near and far value.
use gamemath::{Mat4, Vec4};
let m = Mat4::perspective(55.0, 1920.0 / 1080.0, 0.01, 100.0);
assert_eq!(m[0], Vec4::new(1.0805525, 0.0, 0.0, 0.0));
assert_eq!(m[1], Vec4::new(0.0, 1.9209821, 0.0, 0.0));
assert_eq!(m[2], Vec4::new(0.0, 0.0, -1.0002, -1.0));
assert_eq!(m[3], Vec4::new(0.0, 0.0, -0.020002, 0.0));
Constructs a 4x4 view-matrix from a eye, target and up Vec3<f32>
.
The resulting view-matrix will be "positioned" at the coordinates of the eye vector, loking
in the direction of the coordinates of the target vecctor and with its up direction in the
direction of the up vector.
use gamemath::{Mat4, Vec3, Vec4};
let m = Mat4::look_at(Vec3::new(0.0, 0.0, 1.0),
Vec3::new(0.0, 0.0, 0.0),
Vec3::new(0.0, -1.0, 0.0));
assert_eq!(m[0], Vec4::new(-1.0, 0.0, 0.0, 0.0));
assert_eq!(m[1], Vec4::new(0.0, -1.0, 0.0, 0.0));
assert_eq!(m[2], Vec4::new(0.0, 0.0, 1.0, 0.0));
assert_eq!(m[3], Vec4::new(0.0, 0.0, 1.0, 1.0));
Constructs a 4x4 perspective-orthogonal matrix from a top, left, right, bottom, near and far value.
use gamemath::{Mat4, Vec4};
let m = Mat4::orthogonal(-1.0, -1.0, 1.0, 1.0, 0.01, 100.0);
assert_eq!(m[0], Vec4::new(1.0, 0.0, 0.0, 0.0));
assert_eq!(m[1], Vec4::new(0.0, -1.0, 0.0, 0.0));
assert_eq!(m[2], Vec4::new(0.0, 0.0, -0.020002, 0.0));
assert_eq!(m[3], Vec4::new(0.0, 0.0, -1.0002, 1.0));
Extracts and returns a Vec3<f32>
pointing left, away from the position of a view-matrix.
Pretty much only makes sense for a view-matrix.
use gamemath::{Mat4, Vec3};
let m = Mat4::look_at(Vec3::new(0.0, 0.0, 1.0),
Vec3::new(0.0, 0.0, 0.0),
Vec3::new(0.0, -1.0, 0.0));
assert_eq!(m.get_left_vector(), Vec3::new(-1.0, 0.0, 0.0));
Extracts and returns a Vec3<f32>
pointing right, away from the position of a view-matrix.
Pretty much only makes sense for a view-matrix.
use gamemath::{Mat4, Vec3};
let m = Mat4::look_at(Vec3::new(0.0, 0.0, 1.0),
Vec3::new(0.0, 0.0, 0.0),
Vec3::new(0.0, -1.0, 0.0));
assert_eq!(m.get_right_vector(), Vec3::new(1.0, 0.0, 0.0));
Extracts and returns a Vec3<f32>
pointing up, away from the position of a view-matrix.
Pretty much only makes sense for a view-matrix.
use gamemath::{Mat4, Vec3};
let m = Mat4::look_at(Vec3::new(0.0, 0.0, 1.0),
Vec3::new(0.0, 0.0, 0.0),
Vec3::new(0.0, -1.0, 0.0));
assert_eq!(m.get_up_vector(), Vec3::new(0.0, -1.0, 0.0));
Extracts and returns a Vec3<f32>
pointing down, away from the position of a view-matrix.
Pretty much only makes sense for a view-matrix.
use gamemath::{Mat4, Vec3};
let m = Mat4::look_at(Vec3::new(0.0, 0.0, 1.0),
Vec3::new(0.0, 0.0, 0.0),
Vec3::new(0.0, -1.0, 0.0));
assert_eq!(m.get_down_vector(), Vec3::new(0.0, 1.0, 0.0));
Extracts and returns a Vec3<f32>
pointing backwards, away from the position of a view-matrix.
Pretty much only makes sense for a view-matrix.
use gamemath::{Mat4, Vec3};
let m = Mat4::look_at(Vec3::new(0.0, 0.0, 1.0),
Vec3::new(0.0, 0.0, 0.0),
Vec3::new(0.0, -1.0, 0.0));
assert_eq!(m.get_backward_vector(), Vec3::new(0.0, 0.0, 1.0));
Extracts and returns a Vec3<f32>
pointing forwards, away from the position of a view-matrix.
Pretty much only makes sense for a view-matrix.
use gamemath::{Mat4, Vec3};
let m = Mat4::look_at(Vec3::new(0.0, 0.0, 1.0),
Vec3::new(0.0, 0.0, 0.0),
Vec3::new(0.0, -1.0, 0.0));
assert_eq!(m.get_forward_vector(), Vec3::new(0.0, 0.0, -1.0));
Extracts and returns a transposed representation of the calling Mat4
object.
use gamemath::Mat4;
let m: Mat4 = (( 0.0, 1.0, 2.0, 3.0),
( 4.0, 5.0, 6.0, 7.0),
( 8.0, 9.0, 10.0, 11.0),
(12.0, 13.0, 14.0, 15.0)).into();
assert_eq!(m.transposed(), (( 0.0, 4.0, 8.0, 12.0),
( 1.0, 5.0, 9.0, 13.0),
( 2.0, 6.0, 10.0, 14.0),
( 3.0, 7.0, 11.0, 15.0)).into());
Performs a transpose operation on the calling Mat4
object.
use gamemath::Mat4;
let mut m: Mat4 = (( 0.0, 1.0, 2.0, 3.0),
( 4.0, 5.0, 6.0, 7.0),
( 8.0, 9.0, 10.0, 11.0),
(12.0, 13.0, 14.0, 15.0)).into();
m.transpose();
assert_eq!(m, (( 0.0, 4.0, 8.0, 12.0),
( 1.0, 5.0, 9.0, 13.0),
( 2.0, 6.0, 10.0, 14.0),
( 3.0, 7.0, 11.0, 15.0)).into());
calculates and returns the determinant value of the calling Mat4
object.
use gamemath::{Mat4, Vec3};
let m = Mat4::look_at(Vec3::new(0.0, 0.0, 1.0),
Vec3::new(0.0, 0.0, 0.0),
Vec3::new(0.0, -1.0, 0.0));
assert_eq!(m.determinant(), 1.0);
calculates and returns the adjoint matrix of the calling Mat4
object.
use gamemath::Mat4;
let m: Mat4 = (( 4.0, 15.0, 2.0, 13.0),
( 5.0, 10.0, 7.0, 12.0),
( 9.0, 6.0, 11.0, 8.0),
(16.0, 3.0, 14.0, 1.0)).into();
assert_eq!(m.adjointed(), ((-272.0, 816.0, -816.0, 272.0),
( 272.0, -816.0, 816.0, -272.0),
( 272.0, -816.0, 816.0, -272.0),
(-272.0, 816.0, -816.0, 272.0)).into());
calculates and returns the inverted matrix of the calling Mat4
object.
use gamemath::{Mat4, Vec3};
let m = Mat4::look_at(Vec3::new(0.0, 0.0, 1.0),
Vec3::new(0.0, 0.0, 0.0),
Vec3::new(0.0, -1.0, 0.0));
assert_eq!(m.inverted(), ((-1.0, 0.0, 0.0, 0.0),
( 0.0, -1.0, 0.0, 0.0),
( 0.0, 0.0, 1.0, 0.0),
( 0.0, 0.0, -1.0, 1.0)).into());
Performes the inversion operation on the calling Mat4
object.
use gamemath::{Mat4, Vec3};
let mut m = Mat4::look_at(Vec3::new(0.0, 0.0, 1.0),
Vec3::new(0.0, 0.0, 0.0),
Vec3::new(0.0, -1.0, 0.0));
m.invert();
assert_eq!(m, ((-1.0, 0.0, 0.0, 0.0),
( 0.0, -1.0, 0.0, 0.0),
( 0.0, 0.0, 1.0, 0.0),
( 0.0, 0.0, -1.0, 1.0)).into());
Constructs a 4x4 rotation matrix from a radians value and an axis Vec3<f32>
.
use gamemath::{Mat4, Vec3, Vec4};
let m = Mat4::rotation(1.0, Vec3::new(0.0, 0.0, 1.0));
assert_eq!(m[0], Vec4::new(0.5403023, -0.84147096, 0.0, 0.0));
assert_eq!(m[1], Vec4::new(0.84147096, 0.5403023, 0.0, 0.0));
assert_eq!(m[2], Vec4::new(0.0, 0.0, 1.0, 0.0));
assert_eq!(m[3], Vec4::new(0.0, 0.0, 0.0, 1.0));
Calculates and returns a Mat4
object representing the calling Mat4
object rotated
around a Vec3<f32>
axis, by a radians value.
use gamemath::{Mat4, Vec3, Vec4};
let m = Mat4::identity().rotated(1.0, Vec3::new(0.0, 0.0, 1.0));
assert_eq!(m, ((0.5403023, -0.84147096, 0.0, 0.0),
(0.84147096, 0.5403023, 0.0, 0.0),
(0.0, 0.0, 1.0, 0.0),
(0.0, 0.0, 0.0, 1.0)).into());
Rotates the calling Mat4
object around a Vec3<f32>
axis, by a radians value.
use gamemath::{Mat4, Vec3, Vec4};
let mut m = Mat4::identity();
m.rotate(1.0, Vec3::new(0.0, 0.0, 1.0));
assert_eq!(m, ((0.5403023, -0.84147096, 0.0, 0.0),
(0.84147096, 0.5403023, 0.0, 0.0),
(0.0, 0.0, 1.0, 0.0),
(0.0, 0.0, 0.0, 1.0)).into());
Calculates and returns a Mat4
object representing the calling Mat4
object scaled
by a Vec3<f32>
.
use gamemath::{Mat4, Vec3};
let m = Mat4::identity();
assert_eq!(m.scaled(Vec3::new(1.0, 2.0, 3.0)), ((1.0, 0.0, 0.0, 0.0),
(0.0, 2.0, 0.0, 0.0),
(0.0, 0.0, 3.0, 0.0),
(0.0, 0.0, 0.0, 1.0)).into());
Performs the scale operation on the calling Mat4
object, scaling it by a Vec3<f32>
.
use gamemath::{Mat4, Vec3};
let mut m = Mat4::identity();
m.scale(Vec3::new(1.0, 2.0, 3.0));
assert_eq!(m, ((1.0, 0.0, 0.0, 0.0),
(0.0, 2.0, 0.0, 0.0),
(0.0, 0.0, 3.0, 0.0),
(0.0, 0.0, 0.0, 1.0)).into());
Calculates and returns a Mat4
object representing the calling Mat4
object translated
by a Vec3<f32>
.
use gamemath::{Mat4, Vec3};
let m = Mat4::identity();
assert_eq!(m.translated(Vec3::new(1.0, 2.0, 3.0)), ((1.0, 0.0, 0.0, 0.0),
(0.0, 1.0, 0.0, 0.0),
(0.0, 0.0, 1.0, 0.0),
(1.0, 2.0, 3.0, 1.0)).into());
Performs the translate operation on the calling Mat4
object, translating it by a
Vec3<f32>
.
use gamemath::{Mat4, Vec3};
let mut m = Mat4::identity();
m.translate(Vec3::new(1.0, 2.0, 3.0));
assert_eq!(m, ((1.0, 0.0, 0.0, 0.0),
(0.0, 1.0, 0.0, 0.0),
(0.0, 0.0, 1.0, 0.0),
(1.0, 2.0, 3.0, 1.0)).into());