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

Unified Diff: chrome/browser/android/vr_shell/ui_elements.cc

Issue 2301633002: Refactor Vr activity into ChromeTabbedActivity. (Closed)
Patch Set: Address comments and rebase 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 side-by-side diff with in-line comments
Download patch
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
new file mode 100644
index 0000000000000000000000000000000000000000..afffb6f3678d5178e3f629ad5ef4d81546857de9
--- /dev/null
+++ b/chrome/browser/android/vr_shell/ui_elements.cc
@@ -0,0 +1,92 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/android/vr_shell/ui_elements.h"
+
+#include <cmath>
+#include <vector>
+
+#include "base/logging.h"
bshe 2016/09/09 14:42:10 seems like unnecessary?
mthiesse 2016/09/09 15:16:38 Good catch
+
+namespace vr_shell {
+
+namespace {
+
+float GetRayPlaneIntersection(gvr::Vec3f ray_origin,
+ gvr::Vec3f ray_vector,
+ gvr::Vec3f plane_origin,
+ gvr::Vec3f plane_normal) {
+ float denom = vr_shell::VectorDot(ray_vector, plane_normal);
+ if (denom == 0) {
+ // TODO(mthiesse): Line could be contained in the plane, do we care?
+ return -std::numeric_limits<float>::infinity();
+ }
+ gvr::Vec3f rel;
+ rel.x = ray_origin.x - plane_origin.x;
+ rel.y = ray_origin.y - plane_origin.y;
+ rel.z = ray_origin.z - plane_origin.z;
+
+ return -vr_shell::VectorDot(plane_normal, rel) / denom;
+}
+
+} // namespace
+
+ReversibleTransform::ReversibleTransform() { MakeIdentity(); }
+
+void ReversibleTransform::MakeIdentity() {
+ SetIdentityM(to_world_);
+ SetIdentityM(from_world_);
+ orientation_.qx = orientation_.qy = orientation_.qz = 0.0f;
+ orientation_.qw = 1.0f;
+}
+
+void ReversibleTransform::Rotate(gvr::Quatf quat) {
+ orientation_ = QuatMultiply(quat, orientation_);
+
+ // TODO(klausw): use specialized rotation code? Constructing the matrix
+ // via axis-angle quaternion is inefficient.
+ gvr::Mat4f forward = QuatToMatrix(quat);
+ to_world_ = MatrixMul(forward, to_world_);
+ gvr::Mat4f reverse = MatrixTranspose(forward);
+ from_world_ = MatrixMul(from_world_, reverse);
+}
+
+void ReversibleTransform::Rotate(float ax, float ay, float az, float rad) {
+ // TODO(klausw): use specialized rotation code? Constructing the matrix
+ // via axis-angle quaternion is inefficient.
+ Rotate(QuatFromAxisAngle(ax, ay, az, rad));
+}
+
+void ReversibleTransform::Translate(float tx, float ty, float tz) {
+ TranslateM(to_world_, to_world_, tx, ty, tz);
+ TranslateMRight(from_world_, from_world_, -tx, -ty, -tz);
+}
+
+void ReversibleTransform::Scale(float sx, float sy, float sz) {
+ ScaleM(to_world_, to_world_, sx, sy, sz);
+ ScaleMRight(from_world_, from_world_, 1.0f / sx, 1.0f / sy, 1.0f / sz);
+}
+
+gvr::Vec3f WorldRectangle::GetCenter() const {
+ const gvr::Vec3f kOrigin = {0.0f, 0.0f, 0.0f};
+ return MatrixVectorMul(transform_.to_world_, kOrigin);
+}
+
+gvr::Vec3f WorldRectangle::GetNormal() const {
+ const gvr::Vec3f kNormalOrig = {0.0f, 0.0f, -1.0f};
+ return MatrixVectorRotate(transform_.to_world_, kNormalOrig);
+}
+
+float WorldRectangle::GetRayDistance(gvr::Vec3f ray_origin,
+ gvr::Vec3f ray_vector) const {
+ return GetRayPlaneIntersection(ray_origin, ray_vector, GetCenter(),
+ GetNormal());
+}
+
+ContentRectangle::ContentRectangle() = default;
+
+ContentRectangle::~ContentRectangle() = default;
+
+} // namespace vr_shell
+

Powered by Google App Engine
This is Rietveld 408576698