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.h" | 5 #include "chrome/browser/android/vr_shell/ui_elements.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 #include <vector> | 8 |
| 9 #include "chrome/browser/android/vr_shell/animation.h" |
9 | 10 |
10 namespace vr_shell { | 11 namespace vr_shell { |
11 | 12 |
12 namespace { | 13 namespace { |
13 | 14 |
14 float GetRayPlaneIntersection(gvr::Vec3f ray_origin, | 15 float GetRayPlaneIntersection(gvr::Vec3f ray_origin, |
15 gvr::Vec3f ray_vector, | 16 gvr::Vec3f ray_vector, |
16 gvr::Vec3f plane_origin, | 17 gvr::Vec3f plane_origin, |
17 gvr::Vec3f plane_normal) { | 18 gvr::Vec3f plane_normal) { |
18 float denom = vr_shell::VectorDot(ray_vector, plane_normal); | 19 float denom = vr_shell::VectorDot(ray_vector, plane_normal); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 float WorldRectangle::GetRayDistance(gvr::Vec3f ray_origin, | 80 float WorldRectangle::GetRayDistance(gvr::Vec3f ray_origin, |
80 gvr::Vec3f ray_vector) const { | 81 gvr::Vec3f ray_vector) const { |
81 return GetRayPlaneIntersection(ray_origin, ray_vector, GetCenter(), | 82 return GetRayPlaneIntersection(ray_origin, ray_vector, GetCenter(), |
82 GetNormal()); | 83 GetNormal()); |
83 } | 84 } |
84 | 85 |
85 ContentRectangle::ContentRectangle() = default; | 86 ContentRectangle::ContentRectangle() = default; |
86 | 87 |
87 ContentRectangle::~ContentRectangle() = default; | 88 ContentRectangle::~ContentRectangle() = default; |
88 | 89 |
| 90 void ContentRectangle::Animate(int64_t time) { |
| 91 for (auto& it : animations) { |
| 92 Animation& animation = *it; |
| 93 if (time < animation.start) |
| 94 continue; |
| 95 |
| 96 // If |from| is not specified, start at the current values. |
| 97 if (animation.from.size() == 0) { |
| 98 switch (animation.property) { |
| 99 case Animation::COPYRECT: |
| 100 animation.from.push_back(copy_rect.x); |
| 101 animation.from.push_back(copy_rect.y); |
| 102 animation.from.push_back(copy_rect.width); |
| 103 animation.from.push_back(copy_rect.height); |
| 104 break; |
| 105 case Animation::SIZE: |
| 106 animation.from.push_back(size.x); |
| 107 animation.from.push_back(size.y); |
| 108 animation.from.push_back(size.z); |
| 109 break; |
| 110 case Animation::TRANSLATION: |
| 111 animation.from.push_back(translation.x); |
| 112 animation.from.push_back(translation.y); |
| 113 animation.from.push_back(translation.z); |
| 114 break; |
| 115 case Animation::ROTATION: |
| 116 animation.from.push_back(rotation_axis_angle[0]); |
| 117 animation.from.push_back(rotation_axis_angle[1]); |
| 118 animation.from.push_back(rotation_axis_angle[2]); |
| 119 animation.from.push_back(rotation_axis_angle[3]); |
| 120 break; |
| 121 case Animation::UNUSED: |
| 122 break; |
| 123 } |
| 124 } |
| 125 DCHECK_EQ(animation.from.size(), animation.to.size()); |
| 126 |
| 127 std::vector<float> values(animation.from.size()); |
| 128 for (std::size_t i = 0; i < animation.from.size(); ++i) { |
| 129 if (animation.to[i] == animation.from[i] || |
| 130 time >= (animation.start + animation.duration)) { |
| 131 values[i] = animation.to[i]; |
| 132 continue; |
| 133 } |
| 134 double value = animation.easing->CalculateValue( |
| 135 (double)(time - animation.start) / (double)animation.duration); |
| 136 values[i] = |
| 137 animation.from[i] + (value * (animation.to[i] - animation.from[i])); |
| 138 } |
| 139 switch (animation.property) { |
| 140 case Animation::COPYRECT: |
| 141 DCHECK_EQ(animation.from.size(), 4u); |
| 142 copy_rect.x = values[0]; |
| 143 copy_rect.y = values[1]; |
| 144 copy_rect.width = values[2]; |
| 145 copy_rect.height = values[3]; |
| 146 break; |
| 147 case Animation::SIZE: |
| 148 DCHECK_EQ(animation.from.size(), 3u); |
| 149 size.x = values[0]; |
| 150 size.y = values[1]; |
| 151 size.z = values[2]; |
| 152 break; |
| 153 case Animation::TRANSLATION: |
| 154 DCHECK_EQ(animation.from.size(), 3u); |
| 155 translation.x = values[0]; |
| 156 translation.y = values[1]; |
| 157 translation.z = values[2]; |
| 158 break; |
| 159 case Animation::ROTATION: |
| 160 DCHECK_EQ(animation.from.size(), 4u); |
| 161 rotation_axis_angle[0] = values[0]; |
| 162 rotation_axis_angle[1] = values[1]; |
| 163 rotation_axis_angle[2] = values[2]; |
| 164 rotation_axis_angle[3] = values[3]; |
| 165 break; |
| 166 case Animation::UNUSED: |
| 167 break; |
| 168 } |
| 169 } |
| 170 for (auto it = animations.begin(); it != animations.end();) { |
| 171 const Animation& animation = **it; |
| 172 if (time >= (animation.start + animation.duration)) { |
| 173 it = animations.erase(it); |
| 174 } else { |
| 175 ++it; |
| 176 } |
| 177 } |
| 178 } |
| 179 |
89 } // namespace vr_shell | 180 } // namespace vr_shell |
90 | 181 |
OLD | NEW |