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

Side by Side Diff: chrome/browser/android/vr_shell/ui_elements.cc

Issue 2335643002: Add VR Shell animation classes and unit test. (Closed)
Patch Set: Created 4 years, 3 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 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/android/vr_shell/ui_elements.h" 5 #include "chrome/browser/android/vr_shell/ui_elements.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 #include <vector> 8 #include <vector>
9 9
10 #include "chrome/browser/android/vr_shell/animation.h"
11 #include "chrome/browser/android/vr_shell/vr_math.h"
12
10 namespace vr_shell { 13 namespace vr_shell {
11 14
12 namespace { 15 namespace {
13 16
14 float GetRayPlaneIntersection(gvr::Vec3f ray_origin, 17 float GetRayPlaneIntersection(gvr::Vec3f ray_origin,
15 gvr::Vec3f ray_vector, 18 gvr::Vec3f ray_vector,
16 gvr::Vec3f plane_origin, 19 gvr::Vec3f plane_origin,
17 gvr::Vec3f plane_normal) { 20 gvr::Vec3f plane_normal) {
18 float denom = vr_shell::VectorDot(ray_vector, plane_normal); 21 float denom = vr_shell::VectorDot(ray_vector, plane_normal);
19 if (denom == 0) { 22 if (denom == 0) {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 float WorldRectangle::GetRayDistance(gvr::Vec3f ray_origin, 82 float WorldRectangle::GetRayDistance(gvr::Vec3f ray_origin,
80 gvr::Vec3f ray_vector) const { 83 gvr::Vec3f ray_vector) const {
81 return GetRayPlaneIntersection(ray_origin, ray_vector, GetCenter(), 84 return GetRayPlaneIntersection(ray_origin, ray_vector, GetCenter(),
82 GetNormal()); 85 GetNormal());
83 } 86 }
84 87
85 ContentRectangle::ContentRectangle() = default; 88 ContentRectangle::ContentRectangle() = default;
86 89
87 ContentRectangle::~ContentRectangle() = default; 90 ContentRectangle::~ContentRectangle() = default;
88 91
92 void ContentRectangle::Animate(int64_t time) {
93 for (auto& it : animations) {
94 Animation& animation = *it;
95 if (time < animation.start)
96 continue;
97
98 // If no "from" was specified, use the current value.
bshe 2016/09/12 15:38:26 s/"from"/|from|
99 if (animation.from.size() == 0) {
100 switch (animation.property) {
101 case Animation::COPYRECT:
102 animation.from.push_back(copy_rect.x);
103 animation.from.push_back(copy_rect.y);
104 animation.from.push_back(copy_rect.width);
105 animation.from.push_back(copy_rect.height);
106 break;
107 case Animation::SIZE:
108 animation.from.push_back(size.x);
109 animation.from.push_back(size.y);
110 animation.from.push_back(size.z);
111 break;
112 case Animation::TRANSLATION:
113 animation.from.push_back(translation.x);
114 animation.from.push_back(translation.y);
115 animation.from.push_back(translation.z);
116 break;
117 case Animation::ROTATION:
118 animation.from.push_back(rotation_axis_angle[0]);
119 animation.from.push_back(rotation_axis_angle[1]);
120 animation.from.push_back(rotation_axis_angle[2]);
121 animation.from.push_back(rotation_axis_angle[3]);
122 break;
123 case Animation::UNUSED:
124 break;
125 }
126 } else {
127 DCHECK_EQ(animation.from.size(), animation.to.size());
128 }
129
130 std::vector<float> values(animation.from.size());
131 for (std::size_t i = 0; i < animation.from.size(); ++i) {
132 if (animation.to[i] == animation.from[i] ||
133 time >= (animation.start + animation.duration)) {
134 values[i] = animation.to[i];
135 continue;
136 }
137 double value = animation.easing->CalculateValue(
138 (double)(time - animation.start) / (double)animation.duration);
139 values[i] =
140 animation.from[i] + (value * (animation.to[i] - animation.from[i]));
141 }
142 switch (animation.property) {
143 case Animation::COPYRECT:
144 DCHECK_EQ(animation.from.size(), 4UL);
145 copy_rect.x = values[0];
146 copy_rect.y = values[1];
147 copy_rect.width = values[2];
148 copy_rect.height = values[3];
149 break;
150 case Animation::SIZE:
151 DCHECK_EQ(animation.from.size(), 3UL);
152 size.x = values[0];
153 size.y = values[1];
154 size.z = values[2];
155 break;
156 case Animation::TRANSLATION:
157 DCHECK_EQ(animation.from.size(), 3UL);
158 translation.x = values[0];
159 translation.y = values[1];
160 translation.z = values[2];
161 break;
162 case Animation::ROTATION:
163 DCHECK_EQ(animation.from.size(), 4UL);
164 rotation_axis_angle[0] = values[0];
165 rotation_axis_angle[1] = values[1];
166 rotation_axis_angle[2] = values[2];
167 rotation_axis_angle[3] = values[3];
168 break;
169 case Animation::UNUSED:
170 break;
171 }
172 }
173 for (auto it = animations.begin(); it != animations.end();) {
bshe 2016/09/12 15:38:26 perhaps use "for (auto& it : animations)" to be co
cjgrant 2016/09/13 17:32:16 Here, we're managing the increment explicitly sinc
bshe 2016/09/13 19:37:22 hah. I see. Missed the erase here.
174 const Animation& animation = **it;
175 if (time >= (animation.start + animation.duration)) {
176 it = animations.erase(it);
177 } else {
178 ++it;
179 }
180 }
181 }
182
89 } // namespace vr_shell 183 } // namespace vr_shell
90 184
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698