2018-09-23 20:41:56 +08:00
|
|
|
use na::{Real, Unit, Rotation2, Rotation3};
|
2018-09-21 01:54:12 +08:00
|
|
|
|
|
|
|
use traits::Number;
|
2018-09-23 20:41:56 +08:00
|
|
|
use aliases::{TVec3, TVec2, TMat3, TMat4};
|
2018-09-21 01:54:12 +08:00
|
|
|
|
2018-09-23 00:42:38 +08:00
|
|
|
/// A rotation 4 * 4 matrix created from an axis of 3 scalars and an angle expressed in radians.
|
2018-10-08 10:30:16 +08:00
|
|
|
///
|
|
|
|
/// # See also:
|
|
|
|
///
|
|
|
|
/// * [`scaling`](fn.scaling.html)
|
|
|
|
/// * [`translation`](fn.translation.html)
|
|
|
|
/// * [`rotation2d`](fn.rotation2d.html)
|
|
|
|
/// * [`scaling2d`](fn.scaling2d.html)
|
|
|
|
/// * [`translation2d`](fn.translation2d.html)
|
2018-09-23 20:41:56 +08:00
|
|
|
pub fn rotation<N: Real>(angle: N, v: &TVec3<N>) -> TMat4<N> {
|
2018-09-21 01:54:12 +08:00
|
|
|
Rotation3::from_axis_angle(&Unit::new_normalize(*v), angle).to_homogeneous()
|
|
|
|
}
|
|
|
|
|
2018-09-22 23:36:08 +08:00
|
|
|
/// A 4 * 4 scale matrix created from a vector of 3 components.
|
2018-10-08 10:30:16 +08:00
|
|
|
///
|
|
|
|
/// # See also:
|
|
|
|
///
|
|
|
|
/// * [`rotation`](fn.rotation.html)
|
|
|
|
/// * [`translation`](fn.translation.html)
|
|
|
|
/// * [`rotation2d`](fn.rotation2d.html)
|
|
|
|
/// * [`scaling2d`](fn.scaling2d.html)
|
|
|
|
/// * [`translation2d`](fn.translation2d.html)
|
2018-09-23 20:41:56 +08:00
|
|
|
pub fn scaling<N: Number>(v: &TVec3<N>) -> TMat4<N> {
|
|
|
|
TMat4::new_nonuniform_scaling(v)
|
2018-09-21 01:54:12 +08:00
|
|
|
}
|
|
|
|
|
2018-09-23 00:42:38 +08:00
|
|
|
/// A 4 * 4 translation matrix created from the scaling factor on each axis.
|
2018-10-08 10:30:16 +08:00
|
|
|
///
|
|
|
|
/// # See also:
|
|
|
|
///
|
|
|
|
/// * [`rotation`](fn.rotation.html)
|
|
|
|
/// * [`scaling`](fn.scaling.html)
|
|
|
|
/// * [`rotation2d`](fn.rotation2d.html)
|
|
|
|
/// * [`scaling2d`](fn.scaling2d.html)
|
|
|
|
/// * [`translation2d`](fn.translation2d.html)
|
2018-09-23 20:41:56 +08:00
|
|
|
pub fn translation<N: Number>(v: &TVec3<N>) -> TMat4<N> {
|
|
|
|
TMat4::new_translation(v)
|
2018-09-21 01:54:12 +08:00
|
|
|
}
|
2018-09-23 02:16:43 +08:00
|
|
|
|
|
|
|
|
|
|
|
/// A rotation 3 * 3 matrix created from an angle expressed in radians.
|
2018-10-08 10:30:16 +08:00
|
|
|
///
|
|
|
|
/// # See also:
|
|
|
|
///
|
|
|
|
/// * [`rotation`](fn.rotation.html)
|
|
|
|
/// * [`scaling`](fn.scaling.html)
|
|
|
|
/// * [`translation`](fn.translation.html)
|
|
|
|
/// * [`scaling2d`](fn.scaling2d.html)
|
|
|
|
/// * [`translation2d`](fn.translation2d.html)
|
2018-09-23 20:41:56 +08:00
|
|
|
pub fn rotation2d<N: Real>(angle: N) -> TMat3<N> {
|
2018-09-23 02:16:43 +08:00
|
|
|
Rotation2::new(angle).to_homogeneous()
|
|
|
|
}
|
|
|
|
|
|
|
|
/// A 3 * 3 scale matrix created from a vector of 2 components.
|
2018-10-08 10:30:16 +08:00
|
|
|
///
|
|
|
|
/// # See also:
|
|
|
|
///
|
|
|
|
/// * [`rotation`](fn.rotation.html)
|
|
|
|
/// * [`scaling`](fn.scaling.html)
|
|
|
|
/// * [`translation`](fn.translation.html)
|
|
|
|
/// * [`rotation2d`](fn.rotation2d.html)
|
|
|
|
/// * [`translation2d`](fn.translation2d.html)
|
2018-09-23 20:41:56 +08:00
|
|
|
pub fn scaling2d<N: Number>(v: &TVec2<N>) -> TMat3<N> {
|
|
|
|
TMat3::new_nonuniform_scaling(v)
|
2018-09-23 02:16:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// A 3 * 3 translation matrix created from the scaling factor on each axis.
|
2018-10-08 10:30:16 +08:00
|
|
|
///
|
|
|
|
/// # See also:
|
|
|
|
///
|
|
|
|
/// * [`rotation`](fn.rotation.html)
|
|
|
|
/// * [`scaling`](fn.scaling.html)
|
|
|
|
/// * [`translation`](fn.translation.html)
|
|
|
|
/// * [`rotation2d`](fn.rotation2d.html)
|
|
|
|
/// * [`scaling2d`](fn.scaling2d.html)
|
2018-09-23 20:41:56 +08:00
|
|
|
pub fn translation2d<N: Number>(v: &TVec2<N>) -> TMat3<N> {
|
|
|
|
TMat3::new_translation(v)
|
2018-09-23 02:16:43 +08:00
|
|
|
}
|