2019-03-25 18:21:41 +08:00
|
|
|
use na::{self, RealField, Unit};
|
2018-09-20 16:50:34 +08:00
|
|
|
|
2019-03-23 21:29:07 +08:00
|
|
|
use crate::aliases::Qua;
|
2018-09-20 16:50:34 +08:00
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// The conjugate of `q`.
|
2021-04-11 17:00:38 +08:00
|
|
|
pub fn quat_conjugate<T: RealField>(q: &Qua<T>) -> Qua<T> {
|
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`.
|
2021-04-11 17:00:38 +08:00
|
|
|
pub fn quat_inverse<T: RealField>(q: &Qua<T>) -> Qua<T> {
|
2018-10-05 11:21:38 +08:00
|
|
|
q.try_inverse().unwrap_or_else(na::zero)
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
2021-04-11 17:00:38 +08:00
|
|
|
//pub fn quat_isinf<T: RealField>(x: &Qua<T>) -> 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
|
|
|
|
2021-04-11 17:00:38 +08:00
|
|
|
//pub fn quat_isnan<T: RealField>(x: &Qua<T>) -> 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`.
|
2021-04-11 17:00:38 +08:00
|
|
|
pub fn quat_lerp<T: RealField>(x: &Qua<T>, y: &Qua<T>, a: T) -> Qua<T> {
|
2018-09-20 20:23:31 +08:00
|
|
|
x.lerp(y, a)
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
2021-04-11 17:00:38 +08:00
|
|
|
//pub fn quat_mix<T: RealField>(x: &Qua<T>, y: &Qua<T>, a: T) -> Qua<T> {
|
|
|
|
// x * (T::one() - a) + y * a
|
2018-09-22 19:18:59 +08:00
|
|
|
//}
|
2018-09-20 16:50:34 +08:00
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Interpolate spherically between `x` and `y`.
|
2021-04-11 17:00:38 +08:00
|
|
|
pub fn quat_slerp<T: RealField>(x: &Qua<T>, y: &Qua<T>, a: T) -> Qua<T> {
|
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
|
|
|
}
|