| 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..e8f800e1c690d04f6e16f37cd5862204eba05599
|
| --- /dev/null
|
| +++ b/chrome/browser/android/vr_shell/ui_elements.cc
|
| @@ -0,0 +1,91 @@
|
| +// 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"
|
| +
|
| +namespace vr_shell {
|
| +
|
| +namespace {
|
| +
|
| +float getRayPlaneIntersection(gvr::Vec3f rayOrigin,
|
| + gvr::Vec3f rayVector,
|
| + gvr::Vec3f planeOrigin,
|
| + gvr::Vec3f planeNormal) {
|
| + float denom = vr_shell::VectorDot(rayVector, planeNormal);
|
| + if (denom == 0) {
|
| + return -std::numeric_limits<float>::infinity();
|
| + }
|
| + gvr::Vec3f rel;
|
| + rel.x = rayOrigin.x - planeOrigin.x;
|
| + rel.y = rayOrigin.y - planeOrigin.y;
|
| + rel.z = rayOrigin.z - planeOrigin.z;
|
| +
|
| + return -vr_shell::VectorDot(planeNormal, rel) / denom;
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +ReversibleTransform::ReversibleTransform() { SetIdentity(); }
|
| +
|
| +void ReversibleTransform::SetIdentity() {
|
| + setIdentityM(mToWorld);
|
| + setIdentityM(mFromWorld);
|
| + mOrientation.qx = mOrientation.qy = mOrientation.qz = 0.0f;
|
| + mOrientation.qw = 1.0f;
|
| +}
|
| +
|
| +void ReversibleTransform::Rotate(gvr::Quatf quat) {
|
| + mOrientation = QuatMultiply(quat, mOrientation);
|
| +
|
| + // TODO(klausw): use specialized rotation code? Constructing the matrix
|
| + // via axis-angle quaternion is inefficient.
|
| + gvr::Mat4f forward = QuatToMatrix(quat);
|
| + mToWorld = MatrixMul(forward, mToWorld);
|
| + gvr::Mat4f reverse = MatrixTranspose(forward);
|
| + mFromWorld = MatrixMul(mFromWorld, 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(mToWorld, mToWorld, tx, ty, tz);
|
| + translateMRight(mFromWorld, mFromWorld, -tx, -ty, -tz);
|
| +}
|
| +
|
| +void ReversibleTransform::Scale(float sx, float sy, float sz) {
|
| + scaleM(mToWorld, mToWorld, sx, sy, sz);
|
| + scaleMRight(mFromWorld, mFromWorld, 1.0f / sx, 1.0f / sy, 1.0f / sz);
|
| +}
|
| +
|
| +gvr::Vec3f WorldRectangle::getCenter() const {
|
| + const gvr::Vec3f origin = {0.0f, 0.0f, 0.0f};
|
| + return MatrixVectorMul(mTransform.mToWorld, origin);
|
| +}
|
| +
|
| +gvr::Vec3f WorldRectangle::getNormal() const {
|
| + const gvr::Vec3f normalOrig = {0.0f, 0.0f, -1.0f};
|
| + return MatrixVectorRotate(mTransform.mToWorld, normalOrig);
|
| +}
|
| +
|
| +float WorldRectangle::getRayDistance(gvr::Vec3f rayOrigin,
|
| + gvr::Vec3f rayVector) const {
|
| + return getRayPlaneIntersection(rayOrigin, rayVector, getCenter(),
|
| + getNormal());
|
| +}
|
| +
|
| +ContentRectangle::ContentRectangle() {}
|
| +
|
| +ContentRectangle::~ContentRectangle() {}
|
| +
|
| +} // namespace vr_shell
|
| +
|
|
|