Index: chrome/browser/android/vr_shell/ui_elements.cc |
diff --git a/chrome/browser/android/vr_shell/ui_elements.cc b/chrome/browser/android/vr_shell/ui_elements.cc |
index ce2bcbbc22c2b72095d2c963045fe24757047422..c00cd6690c006a65bd8e2356a16bdcc7f89707f2 100644 |
--- a/chrome/browser/android/vr_shell/ui_elements.cc |
+++ b/chrome/browser/android/vr_shell/ui_elements.cc |
@@ -7,6 +7,9 @@ |
#include <cmath> |
#include <vector> |
+#include "chrome/browser/android/vr_shell/animation.h" |
+#include "chrome/browser/android/vr_shell/vr_math.h" |
+ |
namespace vr_shell { |
namespace { |
@@ -86,5 +89,96 @@ ContentRectangle::ContentRectangle() = default; |
ContentRectangle::~ContentRectangle() = default; |
+void ContentRectangle::Animate(int64_t time) { |
+ for (auto& it : animations) { |
+ Animation& animation = *it; |
+ if (time < animation.start) |
+ continue; |
+ |
+ // If no "from" was specified, use the current value. |
bshe
2016/09/12 15:38:26
s/"from"/|from|
|
+ if (animation.from.size() == 0) { |
+ switch (animation.property) { |
+ case Animation::COPYRECT: |
+ animation.from.push_back(copy_rect.x); |
+ animation.from.push_back(copy_rect.y); |
+ animation.from.push_back(copy_rect.width); |
+ animation.from.push_back(copy_rect.height); |
+ break; |
+ case Animation::SIZE: |
+ animation.from.push_back(size.x); |
+ animation.from.push_back(size.y); |
+ animation.from.push_back(size.z); |
+ break; |
+ case Animation::TRANSLATION: |
+ animation.from.push_back(translation.x); |
+ animation.from.push_back(translation.y); |
+ animation.from.push_back(translation.z); |
+ break; |
+ case Animation::ROTATION: |
+ animation.from.push_back(rotation_axis_angle[0]); |
+ animation.from.push_back(rotation_axis_angle[1]); |
+ animation.from.push_back(rotation_axis_angle[2]); |
+ animation.from.push_back(rotation_axis_angle[3]); |
+ break; |
+ case Animation::UNUSED: |
+ break; |
+ } |
+ } else { |
+ DCHECK_EQ(animation.from.size(), animation.to.size()); |
+ } |
+ |
+ std::vector<float> values(animation.from.size()); |
+ for (std::size_t i = 0; i < animation.from.size(); ++i) { |
+ if (animation.to[i] == animation.from[i] || |
+ time >= (animation.start + animation.duration)) { |
+ values[i] = animation.to[i]; |
+ continue; |
+ } |
+ double value = animation.easing->CalculateValue( |
+ (double)(time - animation.start) / (double)animation.duration); |
+ values[i] = |
+ animation.from[i] + (value * (animation.to[i] - animation.from[i])); |
+ } |
+ switch (animation.property) { |
+ case Animation::COPYRECT: |
+ DCHECK_EQ(animation.from.size(), 4UL); |
+ copy_rect.x = values[0]; |
+ copy_rect.y = values[1]; |
+ copy_rect.width = values[2]; |
+ copy_rect.height = values[3]; |
+ break; |
+ case Animation::SIZE: |
+ DCHECK_EQ(animation.from.size(), 3UL); |
+ size.x = values[0]; |
+ size.y = values[1]; |
+ size.z = values[2]; |
+ break; |
+ case Animation::TRANSLATION: |
+ DCHECK_EQ(animation.from.size(), 3UL); |
+ translation.x = values[0]; |
+ translation.y = values[1]; |
+ translation.z = values[2]; |
+ break; |
+ case Animation::ROTATION: |
+ DCHECK_EQ(animation.from.size(), 4UL); |
+ rotation_axis_angle[0] = values[0]; |
+ rotation_axis_angle[1] = values[1]; |
+ rotation_axis_angle[2] = values[2]; |
+ rotation_axis_angle[3] = values[3]; |
+ break; |
+ case Animation::UNUSED: |
+ break; |
+ } |
+ } |
+ 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.
|
+ const Animation& animation = **it; |
+ if (time >= (animation.start + animation.duration)) { |
+ it = animations.erase(it); |
+ } else { |
+ ++it; |
+ } |
+ } |
+} |
+ |
} // namespace vr_shell |