2021-08-08 18:59:40 +08:00
|
|
|
use na::{Rotation3, Unit, UnitQuaternion};
|
2018-09-22 19:18:59 +08:00
|
|
|
|
2019-03-23 21:29:07 +08:00
|
|
|
use crate::aliases::{Qua, TMat4, TVec3};
|
2021-08-08 18:59:40 +08:00
|
|
|
use crate::RealNumber;
|
2018-09-22 19:18:59 +08:00
|
|
|
|
|
|
|
/// Builds a rotation 4 * 4 matrix created from a normalized axis and an angle.
|
|
|
|
///
|
2018-10-08 10:42:02 +08:00
|
|
|
/// # Parameters:
|
|
|
|
///
|
|
|
|
/// * `m` - Input matrix multiplied by this rotation matrix.
|
|
|
|
/// * `angle` - Rotation angle expressed in radians.
|
|
|
|
/// * `axis` - Rotation axis, must be normalized.
|
2021-08-08 18:59:40 +08:00
|
|
|
pub fn rotate_normalized_axis<T: RealNumber>(m: &TMat4<T>, angle: T, axis: &TVec3<T>) -> TMat4<T> {
|
2018-09-22 19:18:59 +08:00
|
|
|
m * Rotation3::from_axis_angle(&Unit::new_unchecked(*axis), angle).to_homogeneous()
|
2018-09-22 22:40:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Rotates a quaternion from a vector of 3 components normalized axis and an angle.
|
|
|
|
///
|
2018-10-08 10:42:02 +08:00
|
|
|
/// # Parameters:
|
|
|
|
///
|
|
|
|
/// * `q` - Source orientation.
|
|
|
|
/// * `angle` - Angle expressed in radians.
|
|
|
|
/// * `axis` - Normalized axis of the rotation, must be normalized.
|
2021-08-08 18:59:40 +08:00
|
|
|
pub fn quat_rotate_normalized_axis<T: RealNumber>(q: &Qua<T>, angle: T, axis: &TVec3<T>) -> Qua<T> {
|
2018-12-29 19:12:56 +08:00
|
|
|
q * UnitQuaternion::from_axis_angle(&Unit::new_unchecked(*axis), angle).into_inner()
|
2018-09-25 11:07:53 +08:00
|
|
|
}
|