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 kAngleEpsilon = 1e-4; | |
Ian Vollick
2014/06/17 15:54:55
s/kAngleEpsilon/angleEpsilon/
awoloszyn
2014/06/17 20:06:02
Done.
| |
35 | |
36 bool RotateTransformOperation::hasZeroAxis() const | |
37 { | |
38 return(axis().lengthSquared() < kAngleEpsilon); | |
39 } | |
40 | |
41 FloatPoint3D RotateTransformOperation::axis() const | |
42 { | |
43 return(FloatPoint3D(x(), y(), z())); | |
Ian Vollick
2014/06/17 15:54:55
No braces around the return value, pls. Here and a
awoloszyn
2014/06/17 20:06:02
Done.
| |
44 } | |
45 | |
46 bool RotateTransformOperation::shareSameAxis(const RotateTransformOperation* fro m, const RotateTransformOperation* to, FloatPoint3D* axis, double* fromAngle, do uble* toAngle) | |
47 { | |
48 *axis = FloatPoint3D(0, 0, 1); | |
49 *fromAngle = 0; | |
50 *toAngle = 0; | |
51 | |
52 if (!from && !to) | |
53 return true; | |
54 | |
55 bool fromZero = !from || from->hasZeroAxis(); | |
56 bool toZero = !to || to->hasZeroAxis(); | |
57 | |
58 if (fromZero && toZero) | |
59 return true; | |
60 | |
61 if (fromZero) { | |
62 *axis = to->axis(); | |
63 *toAngle = to->angle(); | |
64 return true; | |
65 } | |
66 | |
67 if (toZero) { | |
68 *axis = from->axis(); | |
69 *fromAngle = from->angle(); | |
70 return true; | |
71 } | |
72 | |
73 FloatPoint3D fromAxis = from->axis(); | |
74 FloatPoint3D toAxis = to->axis(); | |
75 | |
76 double fromSquared = fromAxis.lengthSquared(); | |
77 double toSquared = toAxis.lengthSquared(); | |
78 | |
79 double dot = fromAxis.dot(toAxis); | |
80 double error = std::abs(1 - (dot * dot) / (fromSquared * toSquared)); | |
81 | |
82 if (error > kAngleEpsilon) | |
83 return false; | |
84 *axis = from->axis(); | |
85 *fromAngle = from->angle(); | |
86 *toAngle = to->angle(); | |
87 return true; | |
88 } | |
89 | |
33 PassRefPtr<TransformOperation> RotateTransformOperation::blend(const TransformOp eration* from, double progress, bool blendToIdentity) | 90 PassRefPtr<TransformOperation> RotateTransformOperation::blend(const TransformOp eration* from, double progress, bool blendToIdentity) |
34 { | 91 { |
35 if (from && !from->isSameType(*this)) | 92 if (from && !from->isSameType(*this)) |
36 return this; | 93 return this; |
37 | 94 |
38 if (blendToIdentity) | 95 if (blendToIdentity) |
39 return RotateTransformOperation::create(m_x, m_y, m_z, m_angle - m_angle * progress, m_type); | 96 return RotateTransformOperation::create(m_x, m_y, m_z, m_angle - m_angle * progress, m_type); |
40 | 97 |
41 const RotateTransformOperation* fromOp = static_cast<const RotateTransformOp eration*>(from); | 98 const RotateTransformOperation* fromOp = static_cast<const RotateTransformOp eration*>(from); |
42 | 99 |
43 // Optimize for single axis rotation | 100 // Optimize for single axis rotation |
44 if (!fromOp || (fromOp->m_x == 0 && fromOp->m_y == 0 && fromOp->m_z == 1) || | 101 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) || | 102 (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)) { | 103 (fromOp->m_x == 1 && fromOp->m_y == 0 && fromOp->m_z == 0)) { |
47 double fromAngle = fromOp ? fromOp->m_angle : 0; | 104 double fromAngle = fromOp ? fromOp->m_angle : 0; |
48 return RotateTransformOperation::create(fromOp ? fromOp->m_x : m_x, | 105 return RotateTransformOperation::create(fromOp ? fromOp->m_x : m_x, |
49 fromOp ? fromOp->m_y : m_y, | 106 fromOp ? fromOp->m_y : m_y, |
50 fromOp ? fromOp->m_z : m_z, | 107 fromOp ? fromOp->m_z : m_z, |
51 WebCore::blend(fromAngle, m_angl e, progress), m_type); | 108 WebCore::blend(fromAngle, m_angl e, progress), m_type); |
52 } | 109 } |
110 double fromAngle; | |
111 double toAngle; | |
112 FloatPoint3D axis; | |
113 | |
114 if (shareSameAxis(fromOp, this, &axis, &fromAngle, &toAngle)) | |
115 return RotateTransformOperation::create(axis.x(), axis.y(), axis.z(), We bCore::blend(fromAngle, toAngle, progress), m_type); | |
53 | 116 |
54 const RotateTransformOperation* toOp = this; | 117 const RotateTransformOperation* toOp = this; |
55 | 118 |
56 // Create the 2 rotation matrices | 119 // Create the 2 rotation matrices |
57 TransformationMatrix fromT; | 120 TransformationMatrix fromT; |
58 TransformationMatrix toT; | 121 TransformationMatrix toT; |
59 fromT.rotate3d((fromOp ? fromOp->m_x : 0), | 122 fromT.rotate3d((fromOp ? fromOp->m_x : 0), |
60 (fromOp ? fromOp->m_y : 0), | 123 (fromOp ? fromOp->m_y : 0), |
61 (fromOp ? fromOp->m_z : 1), | 124 (fromOp ? fromOp->m_z : 1), |
62 (fromOp ? fromOp->m_angle : 0)); | 125 (fromOp ? fromOp->m_angle : 0)); |
(...skipping 23 matching lines...) Expand all Loading... | |
86 z /= length; | 149 z /= length; |
87 angle = rad2deg(acos(decomp.quaternionW) * 2); | 150 angle = rad2deg(acos(decomp.quaternionW) * 2); |
88 } else { | 151 } else { |
89 x = 0; | 152 x = 0; |
90 y = 0; | 153 y = 0; |
91 z = 1; | 154 z = 1; |
92 } | 155 } |
93 return RotateTransformOperation::create(x, y, z, angle, Rotate3D); | 156 return RotateTransformOperation::create(x, y, z, angle, Rotate3D); |
94 } | 157 } |
95 | 158 |
159 bool RotateTransformOperation::canInterpolateWith(const TransformOperation& othe r) const | |
160 { | |
161 return(other.isSameType(*this)); | |
162 } | |
163 | |
96 } // namespace WebCore | 164 } // namespace WebCore |
OLD | NEW |