2018-09-23 20:41:56 +08:00
|
|
|
use na::{Real, UnitComplex};
|
2018-09-21 04:12:26 +08:00
|
|
|
|
|
|
|
use traits::Number;
|
2018-09-23 20:41:56 +08:00
|
|
|
use aliases::{TMat3, TVec2};
|
2018-09-21 04:12:26 +08:00
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Builds a 2D rotation matrix from an angle and right-multiply it to `m`.
|
2018-09-23 20:41:56 +08:00
|
|
|
pub fn rotate2d<N: Real>(m: &TMat3<N>, angle: N) -> TMat3<N> {
|
2018-09-21 04:12:26 +08:00
|
|
|
m * UnitComplex::new(angle).to_homogeneous()
|
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Builds a 2D scaling matrix and right-multiply it to `m`.
|
2018-09-23 20:41:56 +08:00
|
|
|
pub fn scale2d<N: Number>(m: &TMat3<N>, v: &TVec2<N>) -> TMat3<N> {
|
2018-09-21 04:12:26 +08:00
|
|
|
m.prepend_nonuniform_scaling(v)
|
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Builds a translation matrix and right-multiply it to `m`.
|
2018-09-23 20:41:56 +08:00
|
|
|
pub fn translate2d<N: Number>(m: &TMat3<N>, v: &TVec2<N>) -> TMat3<N> {
|
2018-09-21 04:12:26 +08:00
|
|
|
m.prepend_translation(v)
|
2018-09-23 02:16:43 +08:00
|
|
|
}
|