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..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, |
|
David Trainor- moved to gerrit
2016/09/08 05:49:29
get -> Get. Fix naming scheme on variables too ab
mthiesse
2016/09/08 17:44:40
Done.
|
| + gvr::Vec3f rayVector, |
| + gvr::Vec3f planeOrigin, |
| + gvr::Vec3f planeNormal) { |
| + float denom = vr_shell::VectorDot(rayVector, planeNormal); |
| + if (denom == 0) { |
|
bsheedy_google
2016/09/07 16:47:06
Means that the line and plane are parallel, but th
mthiesse
2016/09/08 17:44:40
I don't think we care as especially in 3DOF world
|
| + 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() { |
|
bsheedy_google
2016/09/07 16:47:06
Might want to consider renaming for clarity. SetId
David Trainor- moved to gerrit
2016/09/08 05:49:29
MakeIdentity()? That's what gfx::Transform does.
mthiesse
2016/09/08 17:44:40
Done.
|
| + 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}; |
|
David Trainor- moved to gerrit
2016/09/08 05:49:29
kOrigin
mthiesse
2016/09/08 17:44:40
Done.
|
| + return MatrixVectorMul(mTransform.mToWorld, origin); |
| +} |
| + |
| +gvr::Vec3f WorldRectangle::getNormal() const { |
| + const gvr::Vec3f normalOrig = {0.0f, 0.0f, -1.0f}; |
|
David Trainor- moved to gerrit
2016/09/08 05:49:29
kNormalOrig
mthiesse
2016/09/08 17:44:40
Done.
|
| + return MatrixVectorRotate(mTransform.mToWorld, normalOrig); |
| +} |
| + |
| +float WorldRectangle::getRayDistance(gvr::Vec3f rayOrigin, |
| + gvr::Vec3f rayVector) const { |
| + return getRayPlaneIntersection(rayOrigin, rayVector, getCenter(), |
| + getNormal()); |
| +} |
| + |
| +ContentRectangle::ContentRectangle() {} |
|
David Trainor- moved to gerrit
2016/09/08 05:49:29
= default
mthiesse
2016/09/08 17:44:40
Done.
|
| + |
| +ContentRectangle::~ContentRectangle() {} |
|
David Trainor- moved to gerrit
2016/09/08 05:49:29
= default
mthiesse
2016/09/08 17:44:40
Done.
|
| + |
| +} // namespace vr_shell |
| + |