Jelajahi Sumber

Merge pull request #678 from jbousquie/fix.RotationFromAxis

added WithinEpsilon comparison to avoid normalization approximation problems
Raanan Weber 10 tahun lalu
induk
melakukan
2270a2a4e7
1 mengubah file dengan 4 tambahan dan 4 penghapusan
  1. 4 4
      src/Math/babylon.math.ts

+ 4 - 4
src/Math/babylon.math.ts

@@ -1083,16 +1083,16 @@
             var nbRevert = 0;
             var cross: Vector3;
             var dot = 0.0;
-
+            
             // step 1  : rotation around w
             // Rv3(u) = u1, and u1 belongs to plane xOz
             // Rv3(w) = w1 = w invariant
             var u1: Vector3;
             var v1: Vector3;
-            if (w.z == 0) {
+            if (Tools.WithinEpsilon(w.z, 0, Engine.Epsilon)) {
                 z = 1.0;
             }
-            else if (w.x == 0) {
+            else if (Tools.WithinEpsilon(w.x, 0, Engine.Epsilon)) {
                 x = 1.0;
             }
             else {
@@ -1131,7 +1131,7 @@
             y = 0.0;
             z = 0.0;
             sign = -1;
-            if (w.z == 0) {
+            if (Tools.WithinEpsilon(w.z, 0, Engine.Epsilon)) {
                 x = 1.0;
             }
             else {