diff --git a/Source/Core/Matrix4.js b/Source/Core/Matrix4.js index 12e0a292218b..8a0e14747cff 100644 --- a/Source/Core/Matrix4.js +++ b/Source/Core/Matrix4.js @@ -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; }; /**