Skip to content

Commit

Permalink
Inline quaternion to rotation matrix in fromTranslationQuaternionRota…
Browse files Browse the repository at this point in the history
…tionScale.
  • Loading branch information
bagnell committed Oct 31, 2013
1 parent a62ed71 commit 1bf524b
Showing 1 changed file with 32 additions and 10 deletions.
42 changes: 32 additions & 10 deletions Source/Core/Matrix4.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,19 +266,41 @@ define([
var scaleX = scale.x;
var scaleY = scale.y;
var scaleZ = scale.z;
scratchTrsRotation = Matrix3.fromQuaternion(rotation, scratchTrsRotation);

result[0] = scratchTrsRotation[0] * scaleX;
result[1] = scratchTrsRotation[1] * scaleX;
result[2] = scratchTrsRotation[2] * scaleX;
var x2 = rotation.x * rotation.x;
var xy = rotation.x * rotation.y;
var xz = rotation.x * rotation.z;
var xw = rotation.x * rotation.w;
var y2 = rotation.y * rotation.y;
var yz = rotation.y * rotation.z;
var yw = rotation.y * rotation.w;
var z2 = rotation.z * rotation.z;
var zw = rotation.z * rotation.w;
var w2 = rotation.w * rotation.w;

var m00 = x2 - y2 - z2 + w2;
var m01 = 2.0 * (xy - zw);
var m02 = 2.0 * (xz + yw);

var m10 = 2.0 * (xy + zw);
var m11 = -x2 + y2 - z2 + w2;
var m12 = 2.0 * (yz - xw);

var m20 = 2.0 * (xz - yw);
var m21 = 2.0 * (yz + xw);
var m22 = -x2 - y2 + z2 + w2;

result[0] = m00 * scaleX;
result[1] = m10 * scaleX;
result[2] = m20 * scaleX;
result[3] = 0.0;
result[4] = scratchTrsRotation[3] * scaleY;
result[5] = scratchTrsRotation[4] * scaleY;
result[6] = scratchTrsRotation[5] * scaleY;
result[4] = m01 * scaleY;
result[5] = m11 * scaleY;
result[6] = m21 * scaleY;
result[7] = 0.0;
result[8] = scratchTrsRotation[6] * scaleZ;
result[9] = scratchTrsRotation[7] * scaleZ;
result[10] = scratchTrsRotation[8] * scaleZ;
result[8] = m02 * scaleZ;
result[9] = m12 * scaleZ;
result[10] = m22 * scaleZ;
result[11] = 0.0;
result[12] = translation.x;
result[13] = translation.y;
Expand Down

0 comments on commit 1bf524b

Please sign in to comment.