2018-09-22 19:18:59 +08:00
|
|
|
use na::{self, Real, Unit};
|
2018-09-20 16:50:34 +08:00
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
use aliases::Qua;
|
2018-09-20 16:50:34 +08:00
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// The conjugate of `q`.
|
2018-09-22 22:40:58 +08:00
|
|
|
pub fn quat_conjugate<N: Real>(q: &Qua<N>) -> Qua<N> {
|
2018-09-20 20:23:31 +08:00
|
|
|
q.conjugate()
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// The inverse of `q`.
|
2018-09-22 22:40:58 +08:00
|
|
|
pub fn quat_inverse<N: Real>(q: &Qua<N>) -> Qua<N> {
|
2018-10-05 11:21:38 +08:00
|
|
|
q.try_inverse().unwrap_or_else(na::zero)
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
2018-09-23 20:48:45 +08:00
|
|
|
//pub fn quat_isinf<N: Real>(x: &Qua<N>) -> TVec<bool, U4> {
|
2018-09-20 20:23:31 +08:00
|
|
|
// x.coords.map(|e| e.is_inf())
|
|
|
|
//}
|
2018-09-20 16:50:34 +08:00
|
|
|
|
2018-09-23 20:48:45 +08:00
|
|
|
//pub fn quat_isnan<N: Real>(x: &Qua<N>) -> TVec<bool, U4> {
|
2018-09-20 20:23:31 +08:00
|
|
|
// x.coords.map(|e| e.is_nan())
|
|
|
|
//}
|
2018-09-20 16:50:34 +08:00
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Interpolate linearly between `x` and `y`.
|
2018-09-22 22:40:58 +08:00
|
|
|
pub fn quat_lerp<N: Real>(x: &Qua<N>, y: &Qua<N>, a: N) -> Qua<N> {
|
2018-09-20 20:23:31 +08:00
|
|
|
x.lerp(y, a)
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
2018-09-22 22:40:58 +08:00
|
|
|
//pub fn quat_mix<N: Real>(x: &Qua<N>, y: &Qua<N>, a: N) -> Qua<N> {
|
2018-09-22 19:18:59 +08:00
|
|
|
// x * (N::one() - a) + y * a
|
|
|
|
//}
|
2018-09-20 16:50:34 +08:00
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Interpolate spherically between `x` and `y`.
|
2018-09-22 22:40:58 +08:00
|
|
|
pub fn quat_slerp<N: Real>(x: &Qua<N>, y: &Qua<N>, a: N) -> Qua<N> {
|
2018-10-22 04:11:27 +08:00
|
|
|
Unit::new_normalize(*x)
|
|
|
|
.slerp(&Unit::new_normalize(*y), a)
|
2018-12-29 19:12:56 +08:00
|
|
|
.into_inner()
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|