webgl_matrix/
lib.rs

1//! This is a lightweight matrix / vector library meant for usage with WebGL.
2//!
3//! At the core this library only consists of the traits `Matrix` and `Vector`. All implementations are optional features and can be added as needed.
4//!
5//! Available features:
6//! * `Matrix4`: 4x4 matrix operations (includes *Vector4*)
7//! * `Matrix3`: 3x3 matrix operations (includes *Vector3*)
8//! * `Vector4`: 4-dimensional vector operations
9//! * `Vector3`: 3-dimensional vector operations
10//! * `SliceOps`: Low level slice operations such as addition, subtraction, scaling etc.
11//!
12//! ## Examples
13//!
14//! All the types are simple arrays. You may also just use slices as operands.
15//!
16//! ```rust
17//! use webgl_matrix::{Matrix, Vector, ProjectionMatrix, Mat4, Vec4, Mat3, Vec3};
18//!
19//! fn main() {
20//!     // all the default operations available
21//!     let mut B = [1., 2., 3.,
22//!                  4., 5., 6.,
23//!                  7., 8., 9.];
24//!     let b = Vec3::ones();
25//!     // Matrix operations are in-place
26//!     B.inverse();
27//!     B.transpose();
28//!     // ..
29//!
30//!     // Some basic vector operations
31//!     let c = B.mul_vector_left(&b);
32//!     let mag = c.mag(); // magnitude
33//!     let d = c.scale(5.);
34//!     let e = c.add(&b);
35//!
36//!     // Or fancier transformations
37//!     B.translate(&[1., 2., 3.]);
38//!
39//!     let A = Mat4::identity();
40//!     // operate on slices
41//!     let b = [1., 2., 3., 4., 5., 6., 7.];
42//!
43//!     // with automatic homogenous coordinate expansion
44//!     let c = A.mul_vector(&b[0..=2]);
45//!     // or using all four coordinates
46//!     let d = A.mul_vector(&b[3..]);
47//!
48//!     // create projection matrices (left, right, bot, top, near, far)
49//!     let P = Mat4::create_perspective_from_viewport(0., 1., 0., 1., 0.1, 10.);
50//! }
51//! ```
52
53mod matrix;
54#[macro_use]
55mod vector;
56
57#[cfg(feature = "Vector3")]
58mod vec3;
59#[cfg(feature = "Vector3")]
60pub use vec3::Vec3;
61
62#[cfg(feature = "Matrix3")]
63mod mat3;
64#[cfg(feature = "Matrix3")]
65pub use mat3::Mat3;
66
67#[cfg(feature = "Vector4")]
68mod vec4;
69#[cfg(feature = "Vector4")]
70pub use vec4::Vec4;
71
72#[cfg(feature = "Matrix4")]
73mod mat4;
74#[cfg(feature = "Matrix4")]
75pub use mat4::{Mat4, ProjectionMatrix};
76
77#[cfg(any(feature = "Matrix4", feature = "Matrix3"))]
78pub use vector::MulVectorMatrix;
79
80#[cfg(feature = "SliceOps")]
81pub mod slice_ops;
82
83pub mod utils;
84pub use crate::matrix::Matrix;
85pub use crate::vector::Vector;
86
87pub mod prelude;