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

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

Issue 2301633002: Refactor Vr activity into ChromeTabbedActivity. (Closed)
Patch Set: UiElements are now structs 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..ce2bcbbc22c2b72095d2c963045fe24757047422
--- /dev/null
+++ b/chrome/browser/android/vr_shell/ui_elements.cc
@@ -0,0 +1,90 @@
+// 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>
+
+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