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

44 lines
1.3 KiB
Rust
Raw Normal View History

2019-03-25 18:21:41 +08:00
use na::{RealField, UnitComplex};
2018-09-21 04:12:26 +08:00
2019-03-23 21:29:07 +08:00
use crate::aliases::{TMat3, TVec2};
use crate::traits::Number;
2018-09-21 04:12:26 +08:00
/// Builds a 2D rotation matrix from an angle and right-multiply it to `m`.
2018-10-08 10:30:16 +08:00
///
/// # See also:
///
/// * [`rotation2d`](fn.rotation2d.html)
/// * [`scale2d`](fn.scale2d.html)
/// * [`scaling2d`](fn.scaling2d.html)
/// * [`translate2d`](fn.translate2d.html)
/// * [`translation2d`](fn.translation2d.html)
2019-03-25 18:21:41 +08:00
pub fn rotate2d<N: RealField>(m: &TMat3<N>, angle: N) -> TMat3<N> {
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-10-08 10:30:16 +08:00
///
/// # See also:
///
/// * [`rotate2d`](fn.rotate2d.html)
/// * [`rotation2d`](fn.rotation2d.html)
/// * [`scaling2d`](fn.scaling2d.html)
/// * [`translate2d`](fn.translate2d.html)
/// * [`translation2d`](fn.translation2d.html)
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)
}
/// Builds a translation matrix and right-multiply it to `m`.
2018-10-08 10:30:16 +08:00
///
/// # See also:
///
/// * [`rotate2d`](fn.rotate2d.html)
/// * [`rotation2d`](fn.rotation2d.html)
/// * [`scale2d`](fn.scale2d.html)
/// * [`scaling2d`](fn.scaling2d.html)
/// * [`translation2d`](fn.translation2d.html)
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-10-08 10:30:16 +08:00
}