瀏覽代碼

Added toEulerAnglesToRef and CopyFromFloats to Quaternion

Yannick Comte 11 年之前
父節點
當前提交
3723830a97
共有 2 個文件被更改,包括 37 次插入3 次删除
  1. 18 1
      Babylon/Math/babylon.math.js
  2. 19 2
      Babylon/Math/babylon.math.ts

+ 18 - 1
Babylon/Math/babylon.math.js

@@ -920,6 +920,13 @@
             this.z = other.z;
             this.w = other.w;
         };
+		
+		Quaternion.prototype.copyFromFloats = function (x, y, z, w) {
+            this.x = x;
+            this.y = y;
+            this.z = z;
+            this.w = w;
+        };
 
         Quaternion.prototype.add = function (other) {
             return new Quaternion(this.x + other.x, this.y + other.y, this.z + other.z, this.w + other.w);
@@ -961,6 +968,14 @@
         };
 
         Quaternion.prototype.toEulerAngles = function () {
+            var result = BABYLON.Vector3.Zero();
+
+            Quaternion.toEulerAnglesToRef(result);
+
+            return result;
+        };
+
+        Quaternion.prototype.toEulerAnglesToRef = function (result) {
             var qx = this.x;
             var qy = this.y;
             var qz = this.z;
@@ -983,7 +998,9 @@
                 roll = 0;
             }
 
-            return new Vector3(pitch, yaw, roll);
+            result.x = pitch;
+            result.y = yaw;
+            result.z = roll;
         };
 
         Quaternion.prototype.toRotationMatrix = function (result) {

+ 19 - 2
Babylon/Math/babylon.math.ts

@@ -885,6 +885,13 @@
             this.z = other.z;
             this.w = other.w;
         }
+		
+		public copyFromFloats(x: number, y: number, z: number, w: number): void {
+            this.x = x;
+            this.y = y;
+            this.z = z;
+            this.w = w;
+        };
 
         public add(other: Quaternion): Quaternion {
             return new Quaternion(this.x + other.x, this.y + other.y, this.z + other.z, this.w + other.w);
@@ -924,8 +931,16 @@
             this.z *= length;
             this.w *= length;
         }
+		
+		public toEulerAngles(): Vector3 {
+            var result = Vector3.Zero();
+
+            this.toEulerAnglesToRef(result);
+
+            return result;
+        }
 
-        public toEulerAngles(): Vector3 {
+        public toEulerAnglesToRef(result: Vector3): void {
             var qx = this.x;
             var qy = this.y;
             var qz = this.z;
@@ -948,7 +963,9 @@
                 roll = 0;
             }
 
-            return new Vector3(pitch, yaw, roll);
+            result.x = pitch;
+            result.y = yaw;
+            result.z = roll;
         }
 
         public toRotationMatrix(result: Matrix): void {