2018-09-20 20:23:31 +08:00
|
|
|
use na::{Real, U3, Unit, UnitQuaternion, Vector3};
|
2018-09-20 16:50:34 +08:00
|
|
|
|
|
|
|
use aliases::{Vec, Qua};
|
|
|
|
|
|
|
|
pub fn 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-20 16:50:34 +08:00
|
|
|
pub fn angleAxis<N: Real>(angle: N, axis: &Vec<N, U3>) -> 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-20 16:50:34 +08:00
|
|
|
pub fn axis<N: Real>(x: &Qua<N>) -> Vec<N, U3> {
|
2018-09-20 20:23:31 +08:00
|
|
|
if let Some(a) = UnitQuaternion::from_quaternion(*x).axis() {
|
|
|
|
a.unwrap()
|
|
|
|
} else {
|
|
|
|
Vector3::zeros()
|
|
|
|
}
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|