use na::{Real, U3, U4, UnitQuaternion, Vector3, Rotation3}; use aliases::{Qua, Vec, Mat}; /// Euler angles of the quaternion `q` as (pitch, yaw, roll). pub fn quat_euler_angles(x: &Qua) -> Vec { let q = UnitQuaternion::new_unchecked(*x); let a = q.to_euler_angles(); Vector3::new(a.2, a.1, a.0) } /// Component-wise `>` comparison between two quaternions. pub fn quat_greater_than(x: &Qua, y: &Qua) -> Vec { ::greater_than(&x.coords, &y.coords) } /// Component-wise `>=` comparison between two quaternions. pub fn quat_greater_than_equal(x: &Qua, y: &Qua) -> Vec { ::greater_than_equal(&x.coords, &y.coords) } /// Component-wise `<` comparison between two quaternions. pub fn quat_less_than(x: &Qua, y: &Qua) -> Vec { ::less_than(&x.coords, &y.coords) } /// Component-wise `<=` comparison between two quaternions. pub fn quat_less_than_equal(x: &Qua, y: &Qua) -> Vec { ::less_than_equal(&x.coords, &y.coords) } /// Convert a quaternion to a rotation matrix in homogeneous coordinates. pub fn quat_cast(x: &Qua) -> Mat { ::quat_to_mat4(x) } /// Convert a rotation matrix to a quaternion. pub fn quat_to_mat3(x: &Mat) -> Qua { let rot = Rotation3::from_matrix_unchecked(x); UnitQuaternion::from_rotation_matrix(&rot).unwrap() } /// Computes a right-handed look-at quaternion (equivalent to a right-handed look-at matrix). pub fn quat_look_at(direction: &Vec, up: &Vec) -> Qua { quat_look_at_rh(direction, up) } /// Computes a left-handed look-at quaternion (equivalent to a left-handed look-at matrix). pub fn quat_look_at_lh(direction: &Vec, up: &Vec) -> Qua { UnitQuaternion::look_at_lh(direction, up).unwrap() } /// Computes a right-handed look-at quaternion (equivalent to a right-handed look-at matrix). pub fn quat_look_at_rh(direction: &Vec, up: &Vec) -> Qua { UnitQuaternion::look_at_rh(direction, up).unwrap() } /// The "roll" euler angle of the quaternion `x` assumed to be normalized. pub fn quat_roll(x: &Qua) -> N { // FIXME: optimize this. quat_euler_angles(x).z } /// The "yaw" euler angle of the quaternion `x` assumed to be normalized. pub fn quat_yaw(x: &Qua) -> N { // FIXME: optimize this. quat_euler_angles(x).y } /// The "pitch" euler angle of the quaternion `x` assumed to be normalized. pub fn quat_pitch(x: &Qua) -> N { // FIXME: optimize this. quat_euler_angles(x).x }