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

28 lines
777 B
Rust
Raw Normal View History

2019-03-25 18:21:41 +08:00
use na::{RealField, Unit, UnitQuaternion};
2019-03-23 21:29:07 +08:00
use crate::aliases::{Qua, TVec3};
/// Computes the quaternion exponential.
2021-04-11 17:00:38 +08:00
pub fn quat_exp<T: RealField>(q: &Qua<T>) -> Qua<T> {
q.exp()
}
/// Computes the quaternion logarithm.
2021-04-11 17:00:38 +08:00
pub fn quat_log<T: RealField>(q: &Qua<T>) -> Qua<T> {
q.ln()
}
/// Raises the quaternion `q` to the power `y`.
2021-04-11 17:00:38 +08:00
pub fn quat_pow<T: RealField>(q: &Qua<T>, y: T) -> Qua<T> {
q.powf(y)
}
/// Builds a quaternion from an axis and an angle, and right-multiply it to the quaternion `q`.
2021-04-11 17:00:38 +08:00
pub fn quat_rotate<T: RealField>(q: &Qua<T>, angle: T, axis: &TVec3<T>) -> Qua<T> {
2018-12-29 19:12:56 +08:00
q * UnitQuaternion::from_axis_angle(&Unit::new_normalize(*axis), angle).into_inner()
}
2021-04-11 17:00:38 +08:00
//pub fn quat_sqrt<T: RealField>(q: &Qua<T>) -> Qua<T> {
// unimplemented!()
2018-10-22 04:11:27 +08:00
//}