storm/math/
mod.rs

1mod aabb;
2mod interpolation;
3mod num;
4mod orthographic;
5mod perspective;
6
7use cgmath::Vector2;
8
9pub use self::aabb::AABB2D;
10pub use self::interpolation::Interpolation;
11pub use self::num::{Float, UnsignedInteger};
12pub use self::orthographic::{ortho_from_bounds, OrthographicCamera};
13pub use self::perspective::PerspectiveCamera;
14
15/// Represents 2 * pi.
16pub const TAO: f32 = 6.283_185_307_179_586_476f32;
17/// Represents pi.
18pub const PI: f32 = 3.141_592_653_589_793_238f32;
19/// Represents pi / 2.
20pub const PI_2: f32 = 1.570_796_326_794_896_619f32;
21/// Represents -pi / 2.
22pub const PI_NEG_2: f32 = -1.570_796_326_794_896_619f32;
23/// Simple const identity matrix.
24pub const IDENTITY_MATRIX: cgmath::Matrix4<f32> = cgmath::Matrix4::new(
25    1.0, 0.0, 0.0, 0.0, //
26    0.0, 1.0, 0.0, 0.0, //
27    0.0, 0.0, 1.0, 0.0, //
28    0.0, 0.0, 0.0, 1.0, //
29);
30
31/// Fast Vector2<f32> normalization.
32pub fn fast_normalize2(vector: Vector2<f32>) -> Vector2<f32> {
33    vector * (vector.x * vector.x + vector.y * vector.y).inv_sqrt()
34}
35
36/// Linearly interpolates between a and b by t.
37pub fn lerp(a: f32, b: f32, t: f32) -> f32 {
38    a + t * (b - a)
39}