]> git.nega.tv - josh/narcissus/commitdiff
Add note about rotation direction
authorJoshua Simmons <josh@nega.tv>
Sun, 13 Nov 2022 21:49:41 +0000 (22:49 +0100)
committerJoshua Simmons <josh@nega.tv>
Sun, 13 Nov 2022 21:49:41 +0000 (22:49 +0100)
narcissus-maths/src/mat3.rs
narcissus-maths/src/mat4.rs

index c2692bd012603043a7eb77180e4cf3d99c9792b2..b0db8b4ce5cafbd8ca84639ef9732b8dd0489391 100644 (file)
@@ -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]
index 76b09255b9e72531fcfab9661cbdb7ebc08137cd..afa71044229656ced77db6c25b2c46c587d974d8 100644 (file)
@@ -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]