Skip to content

Commit

Permalink
Merge pull request #1281 from AnalyticalGraphicsInc/matrixOpt
Browse files Browse the repository at this point in the history
Translation-Quaternion Rotation-Scale
  • Loading branch information
pjcozzi committed Oct 31, 2013
2 parents 40b58c2 + 1bf524b commit cfc7df9
Showing 1 changed file with 45 additions and 3 deletions.
48 changes: 45 additions & 3 deletions Source/Core/Matrix4.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,51 @@ define([
result = new Matrix4();
}

scratchTrsRotation = Matrix3.fromQuaternion(rotation, scratchTrsRotation);
result = Matrix4.fromRotationTranslation(scratchTrsRotation, translation, result);
return Matrix4.multiplyByScale(result, scale, result);
var scaleX = scale.x;
var scaleY = scale.y;
var scaleZ = scale.z;

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] = m01 * scaleY;
result[5] = m11 * scaleY;
result[6] = m21 * scaleY;
result[7] = 0.0;
result[8] = m02 * scaleZ;
result[9] = m12 * scaleZ;
result[10] = m22 * scaleZ;
result[11] = 0.0;
result[12] = translation.x;
result[13] = translation.y;
result[14] = translation.z;
result[15] = 1.0;

return result;
};

/**
Expand Down

0 comments on commit cfc7df9

Please sign in to comment.