From ba71cb4a37b32743aff0a98b0cd51378df067e31 Mon Sep 17 00:00:00 2001 From: Lennart Date: Sun, 26 Jan 2014 21:33:30 -0800 Subject: [PATCH 1/2] Fix quat::Quat::from_angle_{x|y|z} These functions were broken due to mistakenly using the full angle theta in one place instead of theta / 2. This resulted in non-unit quaternions that definitely did not rotate things correctly. --- src/cgmath/quaternion.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/cgmath/quaternion.rs b/src/cgmath/quaternion.rs index f86295b..819a2a4 100644 --- a/src/cgmath/quaternion.rs +++ b/src/cgmath/quaternion.rs @@ -50,19 +50,22 @@ Quat { /// Create a matrix from a rotation around the `x` axis (pitch). #[inline] pub fn from_angle_x(theta: Rad) -> Quat { - Quat::new(cos(theta.mul_s(cast(0.5).unwrap())), sin(theta), zero(), zero()) + let (s, c) = sin_cos(theta.mul_s(cast(0.5).unwrap())); + Quat::new(c, s, zero(), zero()) } /// Create a matrix from a rotation around the `y` axis (yaw). #[inline] pub fn from_angle_y(theta: Rad) -> Quat { - Quat::new(cos(theta.mul_s(cast(0.5).unwrap())), zero(), sin(theta), zero()) + let (s, c) = sin_cos(theta.mul_s(cast(0.5).unwrap())); + Quat::new(c, zero(), s, zero()) } /// Create a matrix from a rotation around the `z` axis (roll). #[inline] pub fn from_angle_z(theta: Rad) -> Quat { - Quat::new(cos(theta.mul_s(cast(0.5).unwrap())), zero(), zero(), sin(theta)) + let (s, c) = sin_cos(theta.mul_s(cast(0.5).unwrap())); + Quat::new(c, zero(), zero(), s) } /// Create a quaternion from a set of euler angles. From e9fcf971da94446c126e45b211912b39a1eabfca Mon Sep 17 00:00:00 2001 From: Lennart Date: Sun, 26 Jan 2014 21:47:03 -0800 Subject: [PATCH 2/2] Fix comments on Quat::from_angle_{x|y|z} functions --- src/cgmath/quaternion.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cgmath/quaternion.rs b/src/cgmath/quaternion.rs index 819a2a4..32792fc 100644 --- a/src/cgmath/quaternion.rs +++ b/src/cgmath/quaternion.rs @@ -47,21 +47,21 @@ Quat { Quat { s: s, v: v } } - /// Create a matrix from a rotation around the `x` axis (pitch). + /// Create a quaternion from a rotation around the `x` axis (pitch). #[inline] pub fn from_angle_x(theta: Rad) -> Quat { let (s, c) = sin_cos(theta.mul_s(cast(0.5).unwrap())); Quat::new(c, s, zero(), zero()) } - /// Create a matrix from a rotation around the `y` axis (yaw). + /// Create a quaternion from a rotation around the `y` axis (yaw). #[inline] pub fn from_angle_y(theta: Rad) -> Quat { let (s, c) = sin_cos(theta.mul_s(cast(0.5).unwrap())); Quat::new(c, zero(), s, zero()) } - /// Create a matrix from a rotation around the `z` axis (roll). + /// Create a quaternion from a rotation around the `z` axis (roll). #[inline] pub fn from_angle_z(theta: Rad) -> Quat { let (s, c) = sin_cos(theta.mul_s(cast(0.5).unwrap()));