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 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 greater_than(x: &Qua, y: &Qua) -> Vec { ::greater_than(&x.coords, &y.coords) } /// Component-wise `>=` comparison between two quaternions. pub fn greater_than_equal(x: &Qua, y: &Qua) -> Vec { ::greater_than_equal(&x.coords, &y.coords) } /// Component-wise `<` comparison between two quaternions. pub fn less_than(x: &Qua, y: &Qua) -> Vec { ::less_than(&x.coords, &y.coords) } /// Component-wise `<=` comparison between two quaternions. pub fn less_than_equal(x: &Qua, y: &Qua) -> Vec { ::less_than_equal(&x.coords, &y.coords) } /// Convert a quaternion to a rotation matrix. pub fn mat3_cast(x: Qua) -> Mat { let q = UnitQuaternion::new_unchecked(x); q.to_rotation_matrix().unwrap() } /// Convert a quaternion to a rotation matrix in homogeneous coordinates. pub fn mat4_cast(x: Qua) -> Mat { let q = UnitQuaternion::new_unchecked(x); q.to_homogeneous() } /// Convert a rotation matrix to a quaternion. pub fn quat_cast(x: Mat) -> Qua { let rot = Rotation3::from_matrix_unchecked(x); UnitQuaternion::from_rotation_matrix(&rot).unwrap() } /// Convert a rotation matrix in homogeneous coordinates to a quaternion. pub fn quat_cast2(x: Mat) -> Qua { quat_cast(x.fixed_slice::(0, 0).into_owned()) } /// 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 roll(x: &Qua) -> N { // FIXME: optimize this. euler_angles(x).z } /// The "yaw" euler angle of the quaternion `x` assumed to be normalized. pub fn yaw(x: &Qua) -> N { // FIXME: optimize this. euler_angles(x).y } /// The "pitch" euler angle of the quaternion `x` assumed to be normalized. pub fn pitch(x: &Qua) -> N { // FIXME: optimize this. euler_angles(x).x }