浏览代码

changed get and set Rotation methods to use Vector3 instead of Quaternion and added get and set RotationQuaternion methods; also fixed and issue with getting quaternion

Adam Bowman 8 年之前
父节点
当前提交
20254da8cb
共有 1 个文件被更改,包括 37 次插入12 次删除
  1. 37 12
      src/Bones/babylon.bone.ts

+ 37 - 12
src/Bones/babylon.bone.ts

@@ -365,7 +365,13 @@
 
         }
 
-        public setRotation (quat: Quaternion, space = Space.LOCAL, mesh?: AbstractMesh): void {
+        public setRotation (rotation: Vector3, space = Space.LOCAL, mesh?: AbstractMesh): void {
+            
+            this.setYawPitchRoll(rotation.y, rotation.x, rotation.z, space, mesh);
+
+        }
+
+        public setRotationQuaternion (quat: Quaternion, space = Space.LOCAL, mesh?: AbstractMesh): void {
 
             var rotMatInv = Tmp.Matrix[0];
 
@@ -627,17 +633,37 @@
 
         }
 
-        public getRotation(space = Space.LOCAL, mesh?: AbstractMesh): Quaternion {
+        public getRotation(space = Space.LOCAL, mesh?: AbstractMesh): Vector3 {
 
-            var result = Quaternion.Identity();
+            var result = BABYLON.Vector3.Zero();
 
             this.getRotationToRef(space, mesh, result);
+            
+            return result;
+
+        }
+
+        public getRotationToRef(space = Space.LOCAL, mesh: AbstractMesh, result: Vector3): void {
+
+            var quat = Tmp.Quaternion[0];
+
+            this.getRotationQuaternionToRef(space, mesh, quat);
+            
+            quat.toEulerAnglesToRef(result);
+
+        }
+
+        public getRotationQuaternion(space = Space.LOCAL, mesh?: AbstractMesh): Quaternion {
+
+            var result = Quaternion.Identity();
+
+            this.getRotationQuaternionToRef(space, mesh, result);
 
             return result;
 
         }
 
-        public getRotationToRef( space = Space.LOCAL, mesh: AbstractMesh, result: Quaternion): void{
+        public getRotationQuaternionToRef( space = Space.LOCAL, mesh: AbstractMesh, result: Quaternion): void{
 
             if(space == Space.LOCAL){
 
@@ -649,17 +675,16 @@
                 var amat = this.getAbsoluteTransform();
 
                 if(mesh){
-
-                    var wmat = mesh.getWorldMatrix();
-                    amat.multiplyToRef(wmat, mat);
-
-                    mat.decompose(Tmp.Vector3[0], result, Tmp.Vector3[1]);
-
+                    amat.multiplyToRef(mesh.getWorldMatrix(), mat);
                 }else{
+                    mat.copyFrom(amat);
+                }
 
-                    amat.decompose(Tmp.Vector3[0], result, Tmp.Vector3[1]);
+                mat.m[0] *= this._scalingDeterminant;
+                mat.m[1] *= this._scalingDeterminant;
+                mat.m[2] *= this._scalingDeterminant;
 
-                }
+                mat.decompose(Tmp.Vector3[0], result, Tmp.Vector3[1]);
 
             }
         }