nalgebra/nalgebra-glm/src/gtx/transform2d.rs

20 lines
648 B
Rust
Raw Normal View History

2018-09-23 00:11:51 +08:00
use na::{Real, U2, U3, UnitComplex};
2018-09-21 04:12:26 +08:00
use traits::Number;
use aliases::{Mat, Vec};
/// Builds a 2D rotation matrix from an angle and right-multiply it to `m`.
2018-09-22 23:36:08 +08:00
pub fn rotate2d<N: Real>(m: &Mat<N, U3, U3>, angle: N) -> Mat<N, U3, U3> {
2018-09-21 04:12:26 +08:00
m * UnitComplex::new(angle).to_homogeneous()
}
/// Builds a 2D scaling matrix and right-multiply it to `m`.
2018-09-22 23:36:08 +08:00
pub fn scale2d<N: Number>(m: &Mat<N, U3, U3>, v: &Vec<N, U2>) -> Mat<N, U3, U3> {
2018-09-21 04:12:26 +08:00
m.prepend_nonuniform_scaling(v)
}
/// Builds a translation matrix and right-multiply it to `m`.
2018-09-22 23:36:08 +08:00
pub fn translate2d<N: Number>(m: &Mat<N, U3, U3>, v: &Vec<N, U2>) -> Mat<N, U3, U3> {
2018-09-21 04:12:26 +08:00
m.prepend_translation(v)
}