nalgebra/nalgebra-glm/src/ext/quaternion_trigonometric.rs

22 lines
683 B
Rust
Raw Normal View History

2018-09-23 20:41:56 +08:00
use na::{Real, Unit, UnitQuaternion};
2018-09-23 20:41:56 +08:00
use aliases::{Qua, TVec3};
/// The rotation angle of this quaternion assumed to be normalized.
pub fn quat_angle<N: Real>(x: &Qua<N>) -> N {
UnitQuaternion::from_quaternion(*x).angle()
}
/// Creates a quaternion from an axis and an angle.
2018-09-23 20:41:56 +08:00
pub fn quat_angle_axis<N: Real>(angle: N, axis: &TVec3<N>) -> Qua<N> {
UnitQuaternion::from_axis_angle(&Unit::new_normalize(*axis), angle).unwrap()
}
/// The rotation axis of a quaternion assumed to be normalized.
2018-09-23 20:41:56 +08:00
pub fn quat_axis<N: Real>(x: &Qua<N>) -> TVec3<N> {
if let Some(a) = UnitQuaternion::from_quaternion(*x).axis() {
a.unwrap()
} else {
2018-09-23 20:41:56 +08:00
TVec3::zeros()
}
}