瀏覽代碼

added WithinEpsilon comparison to avoid normalization approximation problems

jbousquie 10 年之前
父節點
當前提交
aa89d1540b
共有 1 個文件被更改,包括 4 次插入3 次删除
  1. 4 3
      src/Math/babylon.math.ts

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

@@ -1083,16 +1083,17 @@
             var nbRevert = 0;
             var cross: Vector3;
             var dot = 0.0;
+            var epsilon = 0.001;
 
             // 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, epsilon)) {
                 z = 1.0;
             }
-            else if (w.x == 0) {
+            else if (Tools.WithinEpsilon(w.x, 0, epsilon)) {
                 x = 1.0;
             }
             else {
@@ -1131,7 +1132,7 @@
             y = 0.0;
             z = 0.0;
             sign = -1;
-            if (w.z == 0) {
+            if (Tools.WithinEpsilon(w.z, 0, epsilon)) {
                 x = 1.0;
             }
             else {