Bug 781701 - Interpolate rotate3d rotation angles numerically when we can instead of using matrix decompositon. r=dbaron

This commit is contained in:
Matt Woodrow 2014-08-19 15:58:17 +12:00
parent f574bb0e2e
commit 7c13ca416b
2 changed files with 41 additions and 19 deletions

View File

@ -1813,10 +1813,36 @@ AddTransformLists(double aCoeff1, const nsCSSValueList* aList1,
break;
}
case eCSSKeyword_rotate3d: {
gfxPoint3D vector1(a1->Item(1).GetFloatValue(),
a1->Item(2).GetFloatValue(),
a1->Item(3).GetFloatValue());
vector1.Normalize();
gfxPoint3D vector2(a2->Item(1).GetFloatValue(),
a2->Item(2).GetFloatValue(),
a2->Item(3).GetFloatValue());
vector2.Normalize();
// Handle rotate3d with matched (normalized) vectors,
// otherwise fallthrough to the next switch statement
// and do matrix decomposition.
if (vector1 == vector2) {
// We skipped appending a transform function above for rotate3d,
// so do it now.
arr = StyleAnimationValue::AppendTransformFunction(tfunc, resultTail);
arr->Item(1).SetFloatValue(vector1.x, eCSSUnit_Number);
arr->Item(2).SetFloatValue(vector1.y, eCSSUnit_Number);
arr->Item(3).SetFloatValue(vector1.z, eCSSUnit_Number);
AddCSSValueAngle(aCoeff1, a1->Item(4), aCoeff2, a2->Item(4),
arr->Item(4));
break;
}
// FALL THROUGH
}
case eCSSKeyword_matrix:
case eCSSKeyword_matrix3d:
case eCSSKeyword_interpolatematrix:
case eCSSKeyword_rotate3d:
case eCSSKeyword_perspective: {
// FIXME: If the matrix contains only numbers then we could decompose
// here.

View File

@ -437,33 +437,29 @@ ProcessRotate3D(gfx3DMatrix& aMatrix, const nsCSSValue::Array* aData)
float cosTheta = FlushToZero(cos(theta));
float sinTheta = FlushToZero(sin(theta));
float x = aData->Item(1).GetFloatValue();
float y = aData->Item(2).GetFloatValue();
float z = aData->Item(3).GetFloatValue();
gfxPoint3D vector(aData->Item(1).GetFloatValue(),
aData->Item(2).GetFloatValue(),
aData->Item(3).GetFloatValue());
/* Normalize [x,y,z] */
float length = sqrt(x*x + y*y + z*z);
if (length == 0.0) {
if (!vector.Length()) {
return;
}
x /= length;
y /= length;
z /= length;
vector.Normalize();
gfx3DMatrix temp;
/* Create our matrix */
temp._11 = 1 + (1 - cosTheta) * (x * x - 1);
temp._12 = -z * sinTheta + (1 - cosTheta) * x * y;
temp._13 = y * sinTheta + (1 - cosTheta) * x * z;
temp._11 = 1 + (1 - cosTheta) * (vector.x * vector.x - 1);
temp._12 = -vector.z * sinTheta + (1 - cosTheta) * vector.x * vector.y;
temp._13 = vector.y * sinTheta + (1 - cosTheta) * vector.x * vector.z;
temp._14 = 0.0f;
temp._21 = z * sinTheta + (1 - cosTheta) * x * y;
temp._22 = 1 + (1 - cosTheta) * (y * y - 1);
temp._23 = -x * sinTheta + (1 - cosTheta) * y * z;
temp._21 = vector.z * sinTheta + (1 - cosTheta) * vector.x * vector.y;
temp._22 = 1 + (1 - cosTheta) * (vector.y * vector.y - 1);
temp._23 = -vector.x * sinTheta + (1 - cosTheta) * vector.y * vector.z;
temp._24 = 0.0f;
temp._31 = -y * sinTheta + (1 - cosTheta) * x * z;
temp._32 = x * sinTheta + (1 - cosTheta) * y * z;
temp._33 = 1 + (1 - cosTheta) * (z * z - 1);
temp._31 = -vector.y * sinTheta + (1 - cosTheta) * vector.x * vector.z;
temp._32 = vector.x * sinTheta + (1 - cosTheta) * vector.y * vector.z;
temp._33 = 1 + (1 - cosTheta) * (vector.z * vector.z - 1);
temp._34 = 0.0f;
temp._41 = 0.0f;
temp._42 = 0.0f;