RotateTransformOperation.cpp [plain text]
#include "config.h"
#include "RotateTransformOperation.h"
#include "AnimationUtilities.h"
#include "TextStream.h"
#include <algorithm>
#include <wtf/MathExtras.h>
namespace WebCore {
bool RotateTransformOperation::operator==(const TransformOperation& other) const
{
if (!isSameType(other))
return false;
const RotateTransformOperation& r = downcast<RotateTransformOperation>(other);
return m_x == r.m_x && m_y == r.m_y && m_z == r.m_z && m_angle == r.m_angle;
}
Ref<TransformOperation> RotateTransformOperation::blend(const TransformOperation* from, double progress, bool blendToIdentity)
{
if (from && !from->isSameType(*this))
return *this;
if (blendToIdentity)
return RotateTransformOperation::create(m_x, m_y, m_z, m_angle - m_angle * progress, m_type);
const RotateTransformOperation* fromOp = downcast<RotateTransformOperation>(from);
if (!fromOp || (fromOp->m_x == 0 && fromOp->m_y == 0 && fromOp->m_z == 1) ||
(fromOp->m_x == 0 && fromOp->m_y == 1 && fromOp->m_z == 0) ||
(fromOp->m_x == 1 && fromOp->m_y == 0 && fromOp->m_z == 0)) {
double fromAngle = fromOp ? fromOp->m_angle : 0;
return RotateTransformOperation::create(fromOp ? fromOp->m_x : m_x,
fromOp ? fromOp->m_y : m_y,
fromOp ? fromOp->m_z : m_z,
WebCore::blend(fromAngle, m_angle, progress), m_type);
}
const RotateTransformOperation* toOp = this;
TransformationMatrix fromT;
TransformationMatrix toT;
fromT.rotate3d((fromOp ? fromOp->m_x : 0),
(fromOp ? fromOp->m_y : 0),
(fromOp ? fromOp->m_z : 1),
(fromOp ? fromOp->m_angle : 0));
toT.rotate3d((toOp ? toOp->m_x : 0),
(toOp ? toOp->m_y : 0),
(toOp ? toOp->m_z : 1),
(toOp ? toOp->m_angle : 0));
toT.blend(fromT, progress);
TransformationMatrix::Decomposed4Type decomp;
toT.decompose4(decomp);
double x = -decomp.quaternionX;
double y = -decomp.quaternionY;
double z = -decomp.quaternionZ;
double length = sqrt(x * x + y * y + z * z);
double angle = 0;
if (length > 0.00001) {
x /= length;
y /= length;
z /= length;
angle = rad2deg(acos(decomp.quaternionW) * 2);
} else {
x = 0;
y = 0;
z = 1;
}
return RotateTransformOperation::create(x, y, z, angle, ROTATE_3D);
}
void RotateTransformOperation::dump(TextStream& ts) const
{
ts << type() << "(" << TextStream::FormatNumberRespectingIntegers(m_x) << ", " << TextStream::FormatNumberRespectingIntegers(m_y) << ", " << TextStream::FormatNumberRespectingIntegers(m_z) << ", " << TextStream::FormatNumberRespectingIntegers(m_angle) << "deg)";
}
}