فهرست منبع

Merge pull request #5922 from Eole211/patch-4

Avoid NaN when normalizing a zero Quaternion
David Catuhe 6 سال پیش
والد
کامیت
67d1a113ef
1فایلهای تغییر یافته به همراه11 افزوده شده و 5 حذف شده
  1. 11 5
      src/Maths/math.ts

+ 11 - 5
src/Maths/math.ts

@@ -3897,11 +3897,17 @@ export class Quaternion {
      * @returns the current updated quaternion
      */
     public normalize(): Quaternion {
-        var length = 1.0 / this.length();
-        this.x *= length;
-        this.y *= length;
-        this.z *= length;
-        this.w *= length;
+        var len = this.length();
+
+        if (len === 0) {
+            return this;
+        }
+
+        var inv = 1.0 / len;
+        this.x *= inv;
+        this.y *= inv;
+        this.z *= inv;
+        this.w *= inv;
         return this;
     }