浏览代码

Merge pull request #1517 from abow/more_bone_work

added Bone.setRotation and Matrix.FromQuaternionToRef
David Catuhe 8 年之前
父节点
当前提交
0dd20a5fe7
共有 2 个文件被更改,包括 48 次插入0 次删除
  1. 15 0
      src/Bones/babylon.bone.ts
  2. 33 0
      src/Math/babylon.math.ts

+ 15 - 0
src/Bones/babylon.bone.ts

@@ -365,6 +365,21 @@
 
         }
 
+        public setRotation (quat: Quaternion, space = Space.LOCAL, mesh?: AbstractMesh): void {
+
+            var rotMatInv = Tmp.Matrix[0];
+
+            this._getNegativeRotationToRef(rotMatInv, space, mesh);
+
+            var rotMat = Tmp.Matrix[1];
+            Matrix.FromQuaternionToRef(quat, rotMat);
+
+            rotMatInv.multiplyToRef(rotMat, rotMat);
+
+            this._rotateWithMatrix(rotMat, space, mesh);
+
+        }
+
         public setRotationMatrix (rotMat: Matrix, space = Space.LOCAL, mesh?: AbstractMesh): void {
 
             var rotMatInv = Tmp.Matrix[0];

+ 33 - 0
src/Math/babylon.math.ts

@@ -3145,6 +3145,39 @@
 
         }
 
+        public static FromQuaternionToRef(quat:Quaternion, result:Matrix){
+
+            var xx = quat.x * quat.x;
+            var yy = quat.y * quat.y;
+            var zz = quat.z * quat.z;
+            var xy = quat.x * quat.y;
+            var zw = quat.z * quat.w;
+            var zx = quat.z * quat.x;
+            var yw = quat.y * quat.w;
+            var yz = quat.y * quat.z;
+            var xw = quat.x * quat.w;
+
+            result.m[0] = 1.0 - (2.0 * (yy + zz));
+            result.m[1] = 2.0 * (xy + zw);
+            result.m[2] = 2.0 * (zx - yw);
+            result.m[3] = 0;
+            result.m[4] = 2.0 * (xy - zw);
+            result.m[5] = 1.0 - (2.0 * (zz + xx));
+            result.m[6] = 2.0 * (yz + xw);
+            result.m[7] = 0;
+            result.m[8] = 2.0 * (zx + yw);
+            result.m[9] = 2.0 * (yz - xw);
+            result.m[10] = 1.0 - (2.0 * (yy + xx));
+            result.m[11] = 0;
+
+            result.m[12] = 0;
+            result.m[13] = 0;
+            result.m[14] = 0;
+
+            result.m[15] = 1.0;
+
+        }
+
     }
 
     export class Plane {