2018-09-23 20:41:56 +08:00
|
|
|
use na::{Real, Unit, UnitQuaternion};
|
2018-09-20 16:50:34 +08:00
|
|
|
|
2018-09-23 20:41:56 +08:00
|
|
|
use aliases::{Qua, TVec3};
|
2018-09-20 16:50:34 +08:00
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// The rotation angle of this quaternion assumed to be normalized.
|
2018-09-22 22:40:58 +08:00
|
|
|
pub fn quat_angle<N: Real>(x: &Qua<N>) -> N {
|
2018-09-20 20:23:31 +08:00
|
|
|
UnitQuaternion::from_quaternion(*x).angle()
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
2018-09-20 20:23:31 +08:00
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// 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> {
|
2018-09-20 20:23:31 +08:00
|
|
|
UnitQuaternion::from_axis_angle(&Unit::new_normalize(*axis), angle).unwrap()
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
2018-09-20 20:23:31 +08:00
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// 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> {
|
2018-09-20 20:23:31 +08:00
|
|
|
if let Some(a) = UnitQuaternion::from_quaternion(*x).axis() {
|
|
|
|
a.unwrap()
|
|
|
|
} else {
|
2018-09-23 20:41:56 +08:00
|
|
|
TVec3::zeros()
|
2018-09-20 20:23:31 +08:00
|
|
|
}
|
2018-10-22 04:11:27 +08:00
|
|
|
}
|