Struct anima_engine::math::Matrix
[−]
[src]
pub struct Matrix { pub array: [f32; 16], }
A simple matrix struct
tailored specifically for graphics.
Examples
let m = Matrix::ident().scale(Vector::new_unf(2.0)).trans(Vector::one()); assert_eq!(m.array[0], 2.0); assert_eq!(m.array[12], 1.0); let inv = m.inv(); assert_eq!(m * inv, Matrix::ident()); assert_eq!(inv * m, Matrix::ident());
Fields
array |
|
Methods
impl Matrix
fn new(array: [f32; 16]) -> Matrix
Creates a matrix using a length 16 array. (columns incremented first)
Examples
let m = Matrix::new([1.0; 16]); assert_eq!(m, Matrix { array: [1.0; 16] });
fn ident() -> Matrix
Creates an identity (1.0 on primary diagonal) matrix.
Examples
let m = Matrix::new([2.0; 16]); assert_eq!(m * Matrix::ident(), Matrix { array: [2.0; 16] });
fn trans(&self, vector: Vector) -> Matrix
Translates a matrix according to the scale represented by a vector.
The translation is applied to the left. (t * m
)
Examples
let v = Vector::new_unf(1.0); let m = Matrix::ident().trans(Vector::new(1.0, 0.0, 1.0)); assert_eq!(m * v, Vector { x: 2.0, y: 1.0, z: 2.0 });
fn scale(&self, vector: Vector) -> Matrix
Scales a matrix according to the scale represented by a vector.
The scaling is applied to the left. (s * m
)
Examples
let v = Vector::new_unf(2.0); let m = Matrix::ident().scale(Vector::new(2.0, 3.0, 4.0)); assert_eq!(m * v, Vector { x: 4.0, y: 6.0, z: 8.0 });
fn rot(self, quaternion: Quaternion) -> Matrix
Rotates a matrix according to the rotation represented by a quaternion.
The rotation is applied to the left. (r * m
)
Examples
let q = Quaternion::new(0.0, 1.0, 0.0, 0.0); let v = Vector::new(1.0, 0.0, 0.0); assert_eq!(Matrix::ident().rot(q) * v, Vector { x: -1.0, y: 0.0, z: 0.0 });
fn rot_around(&self, quaternion: Quaternion, point: Vector) -> Matrix
Rotates a matrix according to the rotation represented by the quaternion around a point.
The rotation is applied to the left. (r * m
)
Examples
let q = Quaternion::new(0.0, 1.0, 0.0, 0.0); let v = Vector::new(1.0, 0.0, 0.0); let p = Vector::new(2.0, 0.0, 0.0); assert_eq!(Matrix::ident().rot_around(q, p) * v, Vector { x: 3.0, y: 0.0, z: 0.0 });