nalgebra_glm/gtx/
rotate_normalized_axis.rs

1use na::{Rotation3, Unit, UnitQuaternion};
2
3use crate::aliases::{Qua, TMat4, TVec3};
4use crate::RealNumber;
5
6/// Builds a rotation 4 * 4 matrix created from a normalized axis and an angle.
7///
8/// # Parameters:
9///
10/// * `m` - Input matrix multiplied by this rotation matrix.
11/// * `angle` - Rotation angle expressed in radians.
12/// * `axis` - Rotation axis, must be normalized.
13pub fn rotate_normalized_axis<T: RealNumber>(m: &TMat4<T>, angle: T, axis: &TVec3<T>) -> TMat4<T> {
14    m * Rotation3::from_axis_angle(&Unit::new_unchecked(*axis), angle).to_homogeneous()
15}
16
17/// Rotates a quaternion from a vector of 3 components normalized axis and an angle.
18///
19/// # Parameters:
20///
21/// * `q` - Source orientation.
22/// * `angle` - Angle expressed in radians.
23/// * `axis` - Normalized axis of the rotation, must be normalized.
24pub fn quat_rotate_normalized_axis<T: RealNumber>(q: &Qua<T>, angle: T, axis: &TVec3<T>) -> Qua<T> {
25    q * UnitQuaternion::from_axis_angle(&Unit::new_unchecked(*axis), angle).into_inner()
26}