This is a lightweight matrix / vector library meant for usage with WebGL.
At the core this library only consists of the traits Matrix
and Vector
.
Available features:
Matrix4
: 4x4 matrix operations (includes Vector4)Matrix3
: 3x3 matrix operations (includes Vector3)Vector4
: 4-dimensional vector operationsVector3
: 3-dimensional vector operationsSliceOps
: Low level slice operations such as addition, subtraction, scaling etc.
All the types are simple arrays. You may also just use slices as operands.
use webgl_matrix::{Matrix, Vector, ProjectionMatrix, Mat4, Vec4, Mat3, Vec3};
fn main() {
// all the default operations available
let mut B = [1., 2., 3.,
4., 5., 6.,
7., 8., 9.];
let b = Vec3::ones();
// Matrix operations are in-place
B.inverse();
B.transpose();
// ..
// Some basic vector operations
let c = B.mul_vector_left(&b);
let mag = c.mag(); // magnitude
let d = c.scale(5.);
let e = c.add(&b);
// Or fancier transformations
B.translate(&[1., 2., 3.]);
let A = Mat4::identity();
// operate on slices
let b = [1., 2., 3., 4., 5., 6., 7.];
// with automatic homogenous coordinate expansion
let c = A.mul_vector(&b[0..=2]);
// or using all four coordinates
let d = A.mul_vector(&b[3..]);
// create projection matrices (left, right, bot, top, near, far)
let P = Mat4::create_perspective_from_viewport(0., 1., 0., 1., 0.1, 10.);
}