Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/android/vr_shell/ui_elements.h" | |
| 6 | |
| 7 #include <cmath> | |
| 8 #include <vector> | |
| 9 | |
| 10 #include "base/logging.h" | |
| 11 | |
| 12 namespace vr_shell { | |
| 13 | |
| 14 namespace { | |
| 15 | |
| 16 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.
| |
| 17 gvr::Vec3f rayVector, | |
| 18 gvr::Vec3f planeOrigin, | |
| 19 gvr::Vec3f planeNormal) { | |
| 20 float denom = vr_shell::VectorDot(rayVector, planeNormal); | |
| 21 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
| |
| 22 return -std::numeric_limits<float>::infinity(); | |
| 23 } | |
| 24 gvr::Vec3f rel; | |
| 25 rel.x = rayOrigin.x - planeOrigin.x; | |
| 26 rel.y = rayOrigin.y - planeOrigin.y; | |
| 27 rel.z = rayOrigin.z - planeOrigin.z; | |
| 28 | |
| 29 return -vr_shell::VectorDot(planeNormal, rel) / denom; | |
| 30 } | |
| 31 | |
| 32 } // namespace | |
| 33 | |
| 34 ReversibleTransform::ReversibleTransform() { SetIdentity(); } | |
| 35 | |
| 36 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.
| |
| 37 setIdentityM(mToWorld); | |
| 38 setIdentityM(mFromWorld); | |
| 39 mOrientation.qx = mOrientation.qy = mOrientation.qz = 0.0f; | |
| 40 mOrientation.qw = 1.0f; | |
| 41 } | |
| 42 | |
| 43 void ReversibleTransform::Rotate(gvr::Quatf quat) { | |
| 44 mOrientation = QuatMultiply(quat, mOrientation); | |
| 45 | |
| 46 // TODO(klausw): use specialized rotation code? Constructing the matrix | |
| 47 // via axis-angle quaternion is inefficient. | |
| 48 gvr::Mat4f forward = QuatToMatrix(quat); | |
| 49 mToWorld = MatrixMul(forward, mToWorld); | |
| 50 gvr::Mat4f reverse = MatrixTranspose(forward); | |
| 51 mFromWorld = MatrixMul(mFromWorld, reverse); | |
| 52 } | |
| 53 | |
| 54 void ReversibleTransform::Rotate(float ax, float ay, float az, float rad) { | |
| 55 // TODO(klausw): use specialized rotation code? Constructing the matrix | |
| 56 // via axis-angle quaternion is inefficient. | |
| 57 Rotate(QuatFromAxisAngle(ax, ay, az, rad)); | |
| 58 } | |
| 59 | |
| 60 void ReversibleTransform::Translate(float tx, float ty, float tz) { | |
| 61 translateM(mToWorld, mToWorld, tx, ty, tz); | |
| 62 translateMRight(mFromWorld, mFromWorld, -tx, -ty, -tz); | |
| 63 } | |
| 64 | |
| 65 void ReversibleTransform::Scale(float sx, float sy, float sz) { | |
| 66 scaleM(mToWorld, mToWorld, sx, sy, sz); | |
| 67 scaleMRight(mFromWorld, mFromWorld, 1.0f / sx, 1.0f / sy, 1.0f / sz); | |
| 68 } | |
| 69 | |
| 70 gvr::Vec3f WorldRectangle::getCenter() const { | |
| 71 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.
| |
| 72 return MatrixVectorMul(mTransform.mToWorld, origin); | |
| 73 } | |
| 74 | |
| 75 gvr::Vec3f WorldRectangle::getNormal() const { | |
| 76 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.
| |
| 77 return MatrixVectorRotate(mTransform.mToWorld, normalOrig); | |
| 78 } | |
| 79 | |
| 80 float WorldRectangle::getRayDistance(gvr::Vec3f rayOrigin, | |
| 81 gvr::Vec3f rayVector) const { | |
| 82 return getRayPlaneIntersection(rayOrigin, rayVector, getCenter(), | |
| 83 getNormal()); | |
| 84 } | |
| 85 | |
| 86 ContentRectangle::ContentRectangle() {} | |
|
David Trainor- moved to gerrit
2016/09/08 05:49:29
= default
mthiesse
2016/09/08 17:44:40
Done.
| |
| 87 | |
| 88 ContentRectangle::~ContentRectangle() {} | |
|
David Trainor- moved to gerrit
2016/09/08 05:49:29
= default
mthiesse
2016/09/08 17:44:40
Done.
| |
| 89 | |
| 90 } // namespace vr_shell | |
| 91 | |
| OLD | NEW |