Chromium Code Reviews| 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 |
| + |