OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 1999 Antti Koivisto (koivisto@kde.org) | 2 * Copyright (C) 1999 Antti Koivisto (koivisto@kde.org) |
3 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. | 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. |
4 * | 4 * |
5 * This library is free software; you can redistribute it and/or | 5 * This library is free software; you can redistribute it and/or |
6 * modify it under the terms of the GNU Library General Public | 6 * modify it under the terms of the GNU Library General Public |
7 * License as published by the Free Software Foundation; either | 7 * License as published by the Free Software Foundation; either |
8 * version 2 of the License, or (at your option) any later version. | 8 * version 2 of the License, or (at your option) any later version. |
9 * | 9 * |
10 * This library is distributed in the hope that it will be useful, | 10 * This library is distributed in the hope that it will be useful, |
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 * Library General Public License for more details. | 13 * Library General Public License for more details. |
14 * | 14 * |
15 * You should have received a copy of the GNU Library General Public License | 15 * You should have received a copy of the GNU Library General Public License |
16 * along with this library; see the file COPYING.LIB. If not, write to | 16 * along with this library; see the file COPYING.LIB. If not, write to |
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
18 * Boston, MA 02110-1301, USA. | 18 * Boston, MA 02110-1301, USA. |
19 * | 19 * |
20 */ | 20 */ |
21 | 21 |
22 #include "config.h" | 22 #include "config.h" |
23 #include "platform/transforms/RotateTransformOperation.h" | 23 #include "platform/transforms/RotateTransformOperation.h" |
24 | 24 |
25 #include "platform/animation/AnimationUtilities.h" | 25 #include "platform/animation/AnimationUtilities.h" |
| 26 #include "platform/geometry/FloatPoint3D.h" |
26 #include "wtf/MathExtras.h" | 27 #include "wtf/MathExtras.h" |
27 #include <algorithm> | 28 #include <algorithm> |
28 | 29 |
29 using namespace std; | 30 using namespace std; |
30 | 31 |
31 namespace WebCore { | 32 namespace WebCore { |
32 | 33 |
| 34 static const double angleEpsilon = 1e-4; |
| 35 |
| 36 FloatPoint3D RotateTransformOperation::axis() const |
| 37 { |
| 38 return FloatPoint3D(x(), y(), z()); |
| 39 } |
| 40 |
| 41 bool RotateTransformOperation::shareSameAxis(const RotateTransformOperation* fro
m, const RotateTransformOperation* to, FloatPoint3D* axis, double* fromAngle, do
uble* toAngle) |
| 42 { |
| 43 *axis = FloatPoint3D(0, 0, 1); |
| 44 *fromAngle = 0; |
| 45 *toAngle = 0; |
| 46 |
| 47 if (!from && !to) |
| 48 return true; |
| 49 |
| 50 bool fromZero = !from || from->axis().isZero(); |
| 51 bool toZero = !to || to->axis().isZero(); |
| 52 |
| 53 if (fromZero && toZero) |
| 54 return true; |
| 55 |
| 56 if (fromZero) { |
| 57 *axis = to->axis(); |
| 58 *toAngle = to->angle(); |
| 59 return true; |
| 60 } |
| 61 |
| 62 if (toZero) { |
| 63 *axis = from->axis(); |
| 64 *fromAngle = from->angle(); |
| 65 return true; |
| 66 } |
| 67 |
| 68 FloatPoint3D fromAxis = from->axis(); |
| 69 FloatPoint3D toAxis = to->axis(); |
| 70 |
| 71 double fromSquared = fromAxis.lengthSquared(); |
| 72 double toSquared = toAxis.lengthSquared(); |
| 73 |
| 74 double dot = fromAxis.dot(toAxis); |
| 75 double error = std::abs(1 - (dot * dot) / (fromSquared * toSquared)); |
| 76 |
| 77 if (error > angleEpsilon) |
| 78 return false; |
| 79 *axis = from->axis(); |
| 80 *fromAngle = from->angle(); |
| 81 *toAngle = to->angle(); |
| 82 return true; |
| 83 } |
| 84 |
33 PassRefPtr<TransformOperation> RotateTransformOperation::blend(const TransformOp
eration* from, double progress, bool blendToIdentity) | 85 PassRefPtr<TransformOperation> RotateTransformOperation::blend(const TransformOp
eration* from, double progress, bool blendToIdentity) |
34 { | 86 { |
35 if (from && !from->isSameType(*this)) | 87 if (from && !from->isSameType(*this)) |
36 return this; | 88 return this; |
37 | 89 |
38 if (blendToIdentity) | 90 if (blendToIdentity) |
39 return RotateTransformOperation::create(m_x, m_y, m_z, m_angle - m_angle
* progress, m_type); | 91 return RotateTransformOperation::create(m_x, m_y, m_z, m_angle - m_angle
* progress, m_type); |
40 | 92 |
41 const RotateTransformOperation* fromOp = static_cast<const RotateTransformOp
eration*>(from); | 93 const RotateTransformOperation* fromOp = static_cast<const RotateTransformOp
eration*>(from); |
42 | 94 |
43 // Optimize for single axis rotation | 95 // Optimize for single axis rotation |
44 if (!fromOp || (fromOp->m_x == 0 && fromOp->m_y == 0 && fromOp->m_z == 1) || | 96 if (!fromOp || (fromOp->m_x == 0 && fromOp->m_y == 0 && fromOp->m_z == 1) || |
45 (fromOp->m_x == 0 && fromOp->m_y == 1 && fromOp->m_z == 0) || | 97 (fromOp->m_x == 0 && fromOp->m_y == 1 && fromOp->m_z == 0) || |
46 (fromOp->m_x == 1 && fromOp->m_y == 0 && fromOp->m_z == 0)) { | 98 (fromOp->m_x == 1 && fromOp->m_y == 0 && fromOp->m_z == 0)) { |
47 double fromAngle = fromOp ? fromOp->m_angle : 0; | 99 double fromAngle = fromOp ? fromOp->m_angle : 0; |
48 return RotateTransformOperation::create(fromOp ? fromOp->m_x : m_x, | 100 return RotateTransformOperation::create(fromOp ? fromOp->m_x : m_x, |
49 fromOp ? fromOp->m_y : m_y, | 101 fromOp ? fromOp->m_y : m_y, |
50 fromOp ? fromOp->m_z : m_z, | 102 fromOp ? fromOp->m_z : m_z, |
51 WebCore::blend(fromAngle, m_angl
e, progress), m_type); | 103 WebCore::blend(fromAngle, m_angl
e, progress), m_type); |
52 } | 104 } |
| 105 double fromAngle; |
| 106 double toAngle; |
| 107 FloatPoint3D axis; |
| 108 |
| 109 if (shareSameAxis(fromOp, this, &axis, &fromAngle, &toAngle)) |
| 110 return RotateTransformOperation::create(axis.x(), axis.y(), axis.z(), We
bCore::blend(fromAngle, toAngle, progress), m_type); |
53 | 111 |
54 const RotateTransformOperation* toOp = this; | 112 const RotateTransformOperation* toOp = this; |
55 | 113 |
56 // Create the 2 rotation matrices | 114 // Create the 2 rotation matrices |
57 TransformationMatrix fromT; | 115 TransformationMatrix fromT; |
58 TransformationMatrix toT; | 116 TransformationMatrix toT; |
59 fromT.rotate3d((fromOp ? fromOp->m_x : 0), | 117 fromT.rotate3d((fromOp ? fromOp->m_x : 0), |
60 (fromOp ? fromOp->m_y : 0), | 118 (fromOp ? fromOp->m_y : 0), |
61 (fromOp ? fromOp->m_z : 1), | 119 (fromOp ? fromOp->m_z : 1), |
62 (fromOp ? fromOp->m_angle : 0)); | 120 (fromOp ? fromOp->m_angle : 0)); |
(...skipping 23 matching lines...) Expand all Loading... |
86 z /= length; | 144 z /= length; |
87 angle = rad2deg(acos(decomp.quaternionW) * 2); | 145 angle = rad2deg(acos(decomp.quaternionW) * 2); |
88 } else { | 146 } else { |
89 x = 0; | 147 x = 0; |
90 y = 0; | 148 y = 0; |
91 z = 1; | 149 z = 1; |
92 } | 150 } |
93 return RotateTransformOperation::create(x, y, z, angle, Rotate3D); | 151 return RotateTransformOperation::create(x, y, z, angle, Rotate3D); |
94 } | 152 } |
95 | 153 |
| 154 bool RotateTransformOperation::canBlendWith(const TransformOperation& other) con
st |
| 155 { |
| 156 return other.isSameType(*this); |
| 157 } |
| 158 |
96 } // namespace WebCore | 159 } // namespace WebCore |
OLD | NEW |