Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(205)

Side by Side Diff: Source/platform/transforms/RotateTransformOperation.cpp

Issue 328333003: Adding Blink-side 3d Box and Bounds calculations to TransformOperations (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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,
(...skipping 12 matching lines...) Expand all
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 "wtf/MathExtras.h" 26 #include "wtf/MathExtras.h"
27 #include <algorithm> 27 #include <algorithm>
28 28
29 using namespace std; 29 using namespace std;
30 30
31 namespace WebCore { 31 namespace WebCore {
32 32
33 const double kAngleEpsilon = 1e-4;
34
35 static bool isZeroAxis(const RotateTransformOperation& from)
Ian Vollick 2014/06/16 15:23:37 Please expose this rather than duplicating in Tran
awoloszyn 2014/06/17 14:26:01 Done.
36 {
37 double length = from.x() * from.x() + from.y() * from.y() + from.z() * from. z();
Ian Vollick 2014/06/16 15:23:37 If you add a FloatPoint3D RotationTransformOperati
awoloszyn 2014/06/17 14:26:00 Done.
38 return(length < kAngleEpsilon);
39 }
40
41 static bool shareSameAxis(const RotateTransformOperation* from, const RotateTran sformOperation* to, double& x, double& y, double& z, double& fromAngle, double& toAngle)
Ian Vollick 2014/06/16 15:23:37 Please expose this, too.
awoloszyn 2014/06/17 14:26:00 Done.
42 {
43 x = 0;
44 y = 0;
45 z = 1;
46 fromAngle = 0;
47 toAngle = 0;
48
49 if (!from && !to)
50 return true;
51
52 bool fromZero = !from || isZeroAxis(*from);
53 bool toZero = !to || isZeroAxis(*to);
54
55 if (fromZero && toZero)
56 return true;
57
58 if (fromZero) {
59 x = to->x();
60 y = to->y();
61 z = to->z();
62 toAngle = to->angle();
63 return true;
64 }
65
66 if (toZero) {
67 x = from->x();
68 y = from->y();
69 z = from->z();
70 fromAngle = from->angle();
71 return true;
72 }
73
74 double fromSquared = from->x() * from->x() + from->y() * from->y() + from->z () * from->z();
75 double toSquared = to->x() * to->x() + to->y() * to->y() + to->z() * to->z();
76
77 double dot = from->x() * to->x() + from->y() * to->y() + from->z() * to->z() ;
78 double error = std::abs(1 - (dot * dot) / (fromSquared * toSquared));
79
80 if (error > kAngleEpsilon)
81 return false;
82 x = from->x();
83 y = from->y();
84 z = from->z();
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 axisX;
111 double axisY;
112 double axisZ;
113 double fromAngle;
114 double toAngle;
115 if (shareSameAxis(fromOp, this, axisX, axisY, axisZ, fromAngle, toAngle)) {
116 return RotateTransformOperation::create(axisX, axisY, axisZ, WebCore::bl end(fromAngle, toAngle, progress), m_type);
117 }
53 118
54 const RotateTransformOperation* toOp = this; 119 const RotateTransformOperation* toOp = this;
55 120
56 // Create the 2 rotation matrices 121 // Create the 2 rotation matrices
57 TransformationMatrix fromT; 122 TransformationMatrix fromT;
58 TransformationMatrix toT; 123 TransformationMatrix toT;
59 fromT.rotate3d((fromOp ? fromOp->m_x : 0), 124 fromT.rotate3d((fromOp ? fromOp->m_x : 0),
60 (fromOp ? fromOp->m_y : 0), 125 (fromOp ? fromOp->m_y : 0),
61 (fromOp ? fromOp->m_z : 1), 126 (fromOp ? fromOp->m_z : 1),
62 (fromOp ? fromOp->m_angle : 0)); 127 (fromOp ? fromOp->m_angle : 0));
(...skipping 23 matching lines...) Expand all
86 z /= length; 151 z /= length;
87 angle = rad2deg(acos(decomp.quaternionW) * 2); 152 angle = rad2deg(acos(decomp.quaternionW) * 2);
88 } else { 153 } else {
89 x = 0; 154 x = 0;
90 y = 0; 155 y = 0;
91 z = 1; 156 z = 1;
92 } 157 }
93 return RotateTransformOperation::create(x, y, z, angle, Rotate3D); 158 return RotateTransformOperation::create(x, y, z, angle, Rotate3D);
94 } 159 }
95 160
161 bool RotateTransformOperation::isCompatibleType(const TransformOperation& other) const
162 {
163 return(other.isSameType(*this));
164 }
165
96 } // namespace WebCore 166 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698