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

83 lines
2.0 KiB
Rust
Raw Normal View History

2021-08-08 18:59:40 +08:00
use na::{Rotation2, Rotation3, Unit};
2018-09-21 01:54:12 +08:00
2019-03-23 21:29:07 +08:00
use crate::aliases::{TMat3, TMat4, TVec2, TVec3};
2021-08-08 18:59:40 +08:00
use crate::traits::{Number, RealNumber};
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()`]
/// * [`translation()`]
/// * [`rotation2d()`]
/// * [`scaling2d()`]
/// * [`translation2d()`]
2021-08-08 18:59:40 +08:00
pub fn rotation<T: RealNumber>(angle: T, v: &TVec3<T>) -> TMat4<T> {
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()`]
/// * [`translation()`]
/// * [`rotation2d()`]
/// * [`scaling2d()`]
/// * [`translation2d()`]
2021-04-11 17:00:38 +08:00
pub fn scaling<T: Number>(v: &TVec3<T>) -> TMat4<T> {
2018-09-23 20:41:56 +08:00
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()`]
/// * [`scaling()`]
/// * [`rotation2d()`]
/// * [`scaling2d()`]
/// * [`translation2d()`]
2021-04-11 17:00:38 +08:00
pub fn translation<T: Number>(v: &TVec3<T>) -> TMat4<T> {
2018-09-23 20:41:56 +08:00
TMat4::new_translation(v)
2018-09-21 01:54:12 +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()`]
/// * [`scaling()`]
/// * [`translation()`]
/// * [`scaling2d()`]
/// * [`translation2d()`]
2021-08-08 18:59:40 +08:00
pub fn rotation2d<T: RealNumber>(angle: T) -> TMat3<T> {
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()`]
/// * [`scaling()`]
/// * [`translation()`]
/// * [`rotation2d()`]
/// * [`translation2d()`]
2021-04-11 17:00:38 +08:00
pub fn scaling2d<T: Number>(v: &TVec2<T>) -> TMat3<T> {
2018-09-23 20:41:56 +08:00
TMat3::new_nonuniform_scaling(v)
}
/// A 3 * 3 translation matrix created from the scaling factor on each axis.
2018-10-08 10:30:16 +08:00
///
/// # See also:
///
/// * [`rotation()`]
/// * [`scaling()`]
/// * [`translation()`]
/// * [`rotation2d()`]
/// * [`scaling2d()`]
2021-04-11 17:00:38 +08:00
pub fn translation2d<T: Number>(v: &TVec2<T>) -> TMat3<T> {
2018-09-23 20:41:56 +08:00
TMat3::new_translation(v)
}