From 6c9a039ffaf31df77f3b2501289ba8ba0e9e515f Mon Sep 17 00:00:00 2001 From: Joshua Simmons Date: Sun, 13 Nov 2022 22:49:41 +0100 Subject: [PATCH] Add note about rotation direction --- narcissus-maths/src/mat3.rs | 10 ++++++++++ narcissus-maths/src/mat4.rs | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/narcissus-maths/src/mat3.rs b/narcissus-maths/src/mat3.rs index c2692bd..b0db8b4 100644 --- a/narcissus-maths/src/mat3.rs +++ b/narcissus-maths/src/mat3.rs @@ -53,6 +53,9 @@ impl Mat3 { } /// Constructs a transformation matrix which rotates around the given `axis` by `angle`. + /// + /// In a right-handed coordinate system, positive angles rotate counter-clockwise around `axis` + /// where `axis` is pointing toward the observer. pub fn from_axis_rotation(axis: Vec3, rotation: HalfTurn) -> Mat3 { let (sin, cos) = sin_cos_pi_f32(rotation.as_f32()); let axis_sin = axis * sin; @@ -257,6 +260,13 @@ mod tests { assert_eq!(rot_180_z * Vec3::Z, Vec3::Z); assert_eq!(rot_180_z * Vec2::X, -Vec2::X); assert_eq!(rot_180_z * Vec2::Y, -Vec2::Y); + + // Check we're rotating the right way, counter-clockwise. + let rot_90_y = Mat3::from_axis_rotation(Vec3::Y, HalfTurn::new(0.5)); + assert_eq!(rot_90_y * Vec3::Z, Vec3::X); + assert_eq!(rot_90_y * -Vec3::Z, -Vec3::X); + assert_eq!(rot_90_y * Vec3::X, -Vec3::Z); + assert_eq!(rot_90_y * -Vec3::X, Vec3::Z); } #[test] diff --git a/narcissus-maths/src/mat4.rs b/narcissus-maths/src/mat4.rs index 76b0925..afa7104 100644 --- a/narcissus-maths/src/mat4.rs +++ b/narcissus-maths/src/mat4.rs @@ -111,6 +111,9 @@ impl Mat4 { } /// Constructs a transformation matrix which rotates around the given `axis` by `angle`. + /// + /// In a right-handed coordinate system, positive angles rotate counter-clockwise around `axis` + /// where `axis` is pointing toward the observer. pub fn from_axis_rotation(axis: Vec3, rotation: HalfTurn) -> Mat4 { let (sin, cos) = sin_cos_pi_f32(rotation.as_f32()); let axis_sin = axis * sin; @@ -567,6 +570,13 @@ mod tests { assert_eq!(rot_180_z * Vec3::Z, Vec3::Z); assert_eq!(rot_180_z * Vec2::X, -Vec2::X); assert_eq!(rot_180_z * Vec2::Y, -Vec2::Y); + + // Check we're rotating the right way, counter-clockwise. + let rot_90_y = Mat4::from_axis_rotation(Vec3::Y, HalfTurn::new(0.5)); + assert_eq!(rot_90_y * Vec3::Z, Vec3::X); + assert_eq!(rot_90_y * -Vec3::Z, -Vec3::X); + assert_eq!(rot_90_y * Vec3::X, -Vec3::Z); + assert_eq!(rot_90_y * -Vec3::X, Vec3::Z); } #[test] -- 2.49.0