OLD | NEW |
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/ui_element.h" | 5 #include "chrome/browser/android/vr_shell/ui_elements/ui_element.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 *distance = -gfx::DotProduct(plane_normal, rel) / denom; | 29 *distance = -gfx::DotProduct(plane_normal, rel) / denom; |
30 return true; | 30 return true; |
31 } | 31 } |
32 | 32 |
33 } // namespace | 33 } // namespace |
34 | 34 |
35 Transform::Transform() { | 35 Transform::Transform() { |
36 MakeIdentity(); | 36 MakeIdentity(); |
37 } | 37 } |
38 | 38 |
| 39 Transform::Transform(const Transform& other) { |
| 40 to_world = other.to_world; |
| 41 } |
| 42 |
39 void Transform::MakeIdentity() { | 43 void Transform::MakeIdentity() { |
40 vr::SetIdentityM(&to_world); | 44 vr::SetIdentityM(&to_world); |
41 } | 45 } |
42 | 46 |
43 void Transform::Rotate(const vr::Quatf& quat) { | 47 void Transform::Rotate(const vr::Quatf& quat) { |
44 // TODO(klausw): use specialized rotation code? Constructing the matrix | 48 // TODO(klausw): use specialized rotation code? Constructing the matrix |
45 // via axis-angle quaternion is inefficient. | 49 // via axis-angle quaternion is inefficient. |
46 vr::Mat4f forward; | 50 vr::Mat4f forward; |
47 vr::QuatToMatrix(quat, &forward); | 51 vr::QuatToMatrix(quat, &forward); |
48 vr::MatrixMul(forward, to_world, &to_world); | 52 vr::MatrixMul(forward, to_world, &to_world); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 | 118 |
115 void UiElement::OnHoverEnter() {} | 119 void UiElement::OnHoverEnter() {} |
116 | 120 |
117 void UiElement::OnHoverLeave() {} | 121 void UiElement::OnHoverLeave() {} |
118 | 122 |
119 void UiElement::OnButtonDown() {} | 123 void UiElement::OnButtonDown() {} |
120 | 124 |
121 void UiElement::OnButtonUp() {} | 125 void UiElement::OnButtonUp() {} |
122 | 126 |
123 void UiElement::Animate(const base::TimeTicks& time) { | 127 void UiElement::Animate(const base::TimeTicks& time) { |
124 for (auto& it : animations) { | 128 for (auto& it : animations_) { |
125 Animation& animation = *it; | 129 Animation& animation = *it; |
126 if (time < animation.start) | 130 if (time < animation.start) |
127 continue; | 131 continue; |
128 | 132 |
129 // If |from| is not specified, start at the current values. | 133 // If |from| is not specified, start at the current values. |
130 if (animation.from.size() == 0) { | 134 if (animation.from.size() == 0) { |
131 switch (animation.property) { | 135 switch (animation.property) { |
132 case Animation::SIZE: | 136 case Animation::SIZE: |
133 animation.from.push_back(size.x()); | 137 animation.from.push_back(size_.x()); |
134 animation.from.push_back(size.y()); | 138 animation.from.push_back(size_.y()); |
135 break; | 139 break; |
136 case Animation::SCALE: | 140 case Animation::SCALE: |
137 animation.from.push_back(scale.x()); | 141 animation.from.push_back(scale_.x()); |
138 animation.from.push_back(scale.y()); | 142 animation.from.push_back(scale_.y()); |
139 animation.from.push_back(scale.z()); | 143 animation.from.push_back(scale_.z()); |
140 break; | 144 break; |
141 case Animation::ROTATION: | 145 case Animation::ROTATION: |
142 animation.from.push_back(rotation.x); | 146 animation.from.push_back(rotation_.x); |
143 animation.from.push_back(rotation.y); | 147 animation.from.push_back(rotation_.y); |
144 animation.from.push_back(rotation.z); | 148 animation.from.push_back(rotation_.z); |
145 animation.from.push_back(rotation.angle); | 149 animation.from.push_back(rotation_.angle); |
146 break; | 150 break; |
147 case Animation::TRANSLATION: | 151 case Animation::TRANSLATION: |
148 animation.from.push_back(translation.x()); | 152 animation.from.push_back(translation_.x()); |
149 animation.from.push_back(translation.y()); | 153 animation.from.push_back(translation_.y()); |
150 animation.from.push_back(translation.z()); | 154 animation.from.push_back(translation_.z()); |
151 break; | 155 break; |
152 case Animation::OPACITY: | 156 case Animation::OPACITY: |
153 animation.from.push_back(opacity); | 157 animation.from.push_back(opacity_); |
154 break; | 158 break; |
155 } | 159 } |
156 } | 160 } |
157 CHECK_EQ(animation.from.size(), animation.to.size()); | 161 CHECK_EQ(animation.from.size(), animation.to.size()); |
158 | 162 |
159 std::vector<float> values(animation.from.size()); | 163 std::vector<float> values(animation.from.size()); |
160 for (std::size_t i = 0; i < animation.from.size(); ++i) { | 164 for (std::size_t i = 0; i < animation.from.size(); ++i) { |
161 if (animation.to[i] == animation.from[i] || | 165 if (animation.to[i] == animation.from[i] || |
162 time >= (animation.start + animation.duration)) { | 166 time >= (animation.start + animation.duration)) { |
163 values[i] = animation.to[i]; | 167 values[i] = animation.to[i]; |
164 continue; | 168 continue; |
165 } | 169 } |
166 double value = animation.easing->CalculateValue( | 170 double value = animation.easing->CalculateValue( |
167 (time - animation.start).InMillisecondsF() / | 171 (time - animation.start).InMillisecondsF() / |
168 animation.duration.InMillisecondsF()); | 172 animation.duration.InMillisecondsF()); |
169 values[i] = | 173 values[i] = |
170 animation.from[i] + (value * (animation.to[i] - animation.from[i])); | 174 animation.from[i] + (value * (animation.to[i] - animation.from[i])); |
171 } | 175 } |
172 switch (animation.property) { | 176 switch (animation.property) { |
173 case Animation::SIZE: | 177 case Animation::SIZE: |
174 CHECK_EQ(animation.from.size(), 2u); | 178 CHECK_EQ(animation.from.size(), 2u); |
175 size.set_x(values[0]); | 179 size_.set_x(values[0]); |
176 size.set_y(values[1]); | 180 size_.set_y(values[1]); |
177 break; | 181 break; |
178 case Animation::SCALE: | 182 case Animation::SCALE: |
179 CHECK_EQ(animation.from.size(), 3u); | 183 CHECK_EQ(animation.from.size(), 3u); |
180 scale = {values[0], values[1], values[2]}; | 184 scale_ = {values[0], values[1], values[2]}; |
181 break; | 185 break; |
182 case Animation::ROTATION: | 186 case Animation::ROTATION: |
183 CHECK_EQ(animation.from.size(), 4u); | 187 CHECK_EQ(animation.from.size(), 4u); |
184 rotation.x = values[0]; | 188 rotation_.x = values[0]; |
185 rotation.y = values[1]; | 189 rotation_.y = values[1]; |
186 rotation.z = values[2]; | 190 rotation_.z = values[2]; |
187 rotation.angle = values[3]; | 191 rotation_.angle = values[3]; |
188 break; | 192 break; |
189 case Animation::TRANSLATION: | 193 case Animation::TRANSLATION: |
190 CHECK_EQ(animation.from.size(), 3u); | 194 CHECK_EQ(animation.from.size(), 3u); |
191 translation = {values[0], values[1], values[2]}; | 195 translation_ = {values[0], values[1], values[2]}; |
192 break; | 196 break; |
193 case Animation::OPACITY: | 197 case Animation::OPACITY: |
194 CHECK_EQ(animation.from.size(), 1u); | 198 CHECK_EQ(animation.from.size(), 1u); |
195 opacity = values[0]; | 199 opacity_ = values[0]; |
196 break; | 200 break; |
197 } | 201 } |
198 } | 202 } |
199 for (auto it = animations.begin(); it != animations.end();) { | 203 for (auto it = animations_.begin(); it != animations_.end();) { |
200 const Animation& animation = **it; | 204 const Animation& animation = **it; |
201 if (time >= (animation.start + animation.duration)) { | 205 if (time >= (animation.start + animation.duration)) { |
202 it = animations.erase(it); | 206 it = animations_.erase(it); |
203 } else { | 207 } else { |
204 ++it; | 208 ++it; |
205 } | 209 } |
206 } | 210 } |
207 } | 211 } |
208 | 212 |
209 bool UiElement::IsVisible() const { | 213 bool UiElement::IsVisible() const { |
210 return visible && computed_opacity > 0.0f; | 214 return visible_ && computed_opacity_ > 0.0f; |
211 } | 215 } |
212 | 216 |
213 bool UiElement::IsHitTestable() const { | 217 bool UiElement::IsHitTestable() const { |
214 return IsVisible() && hit_testable; | 218 return IsVisible() && hit_testable_; |
215 } | 219 } |
216 | 220 |
217 } // namespace vr_shell | 221 } // namespace vr_shell |
OLD | NEW |