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" | |
|
bshe
2016/09/09 14:42:10
seems like unnecessary?
mthiesse
2016/09/09 15:16:38
Good catch
| |
| 11 | |
| 12 namespace vr_shell { | |
| 13 | |
| 14 namespace { | |
| 15 | |
| 16 float GetRayPlaneIntersection(gvr::Vec3f ray_origin, | |
| 17 gvr::Vec3f ray_vector, | |
| 18 gvr::Vec3f plane_origin, | |
| 19 gvr::Vec3f plane_normal) { | |
| 20 float denom = vr_shell::VectorDot(ray_vector, plane_normal); | |
| 21 if (denom == 0) { | |
| 22 // TODO(mthiesse): Line could be contained in the plane, do we care? | |
| 23 return -std::numeric_limits<float>::infinity(); | |
| 24 } | |
| 25 gvr::Vec3f rel; | |
| 26 rel.x = ray_origin.x - plane_origin.x; | |
| 27 rel.y = ray_origin.y - plane_origin.y; | |
| 28 rel.z = ray_origin.z - plane_origin.z; | |
| 29 | |
| 30 return -vr_shell::VectorDot(plane_normal, rel) / denom; | |
| 31 } | |
| 32 | |
| 33 } // namespace | |
| 34 | |
| 35 ReversibleTransform::ReversibleTransform() { MakeIdentity(); } | |
| 36 | |
| 37 void ReversibleTransform::MakeIdentity() { | |
| 38 SetIdentityM(to_world_); | |
| 39 SetIdentityM(from_world_); | |
| 40 orientation_.qx = orientation_.qy = orientation_.qz = 0.0f; | |
| 41 orientation_.qw = 1.0f; | |
| 42 } | |
| 43 | |
| 44 void ReversibleTransform::Rotate(gvr::Quatf quat) { | |
| 45 orientation_ = QuatMultiply(quat, orientation_); | |
| 46 | |
| 47 // TODO(klausw): use specialized rotation code? Constructing the matrix | |
| 48 // via axis-angle quaternion is inefficient. | |
| 49 gvr::Mat4f forward = QuatToMatrix(quat); | |
| 50 to_world_ = MatrixMul(forward, to_world_); | |
| 51 gvr::Mat4f reverse = MatrixTranspose(forward); | |
| 52 from_world_ = MatrixMul(from_world_, reverse); | |
| 53 } | |
| 54 | |
| 55 void ReversibleTransform::Rotate(float ax, float ay, float az, float rad) { | |
| 56 // TODO(klausw): use specialized rotation code? Constructing the matrix | |
| 57 // via axis-angle quaternion is inefficient. | |
| 58 Rotate(QuatFromAxisAngle(ax, ay, az, rad)); | |
| 59 } | |
| 60 | |
| 61 void ReversibleTransform::Translate(float tx, float ty, float tz) { | |
| 62 TranslateM(to_world_, to_world_, tx, ty, tz); | |
| 63 TranslateMRight(from_world_, from_world_, -tx, -ty, -tz); | |
| 64 } | |
| 65 | |
| 66 void ReversibleTransform::Scale(float sx, float sy, float sz) { | |
| 67 ScaleM(to_world_, to_world_, sx, sy, sz); | |
| 68 ScaleMRight(from_world_, from_world_, 1.0f / sx, 1.0f / sy, 1.0f / sz); | |
| 69 } | |
| 70 | |
| 71 gvr::Vec3f WorldRectangle::GetCenter() const { | |
| 72 const gvr::Vec3f kOrigin = {0.0f, 0.0f, 0.0f}; | |
| 73 return MatrixVectorMul(transform_.to_world_, kOrigin); | |
| 74 } | |
| 75 | |
| 76 gvr::Vec3f WorldRectangle::GetNormal() const { | |
| 77 const gvr::Vec3f kNormalOrig = {0.0f, 0.0f, -1.0f}; | |
| 78 return MatrixVectorRotate(transform_.to_world_, kNormalOrig); | |
| 79 } | |
| 80 | |
| 81 float WorldRectangle::GetRayDistance(gvr::Vec3f ray_origin, | |
| 82 gvr::Vec3f ray_vector) const { | |
| 83 return GetRayPlaneIntersection(ray_origin, ray_vector, GetCenter(), | |
| 84 GetNormal()); | |
| 85 } | |
| 86 | |
| 87 ContentRectangle::ContentRectangle() = default; | |
| 88 | |
| 89 ContentRectangle::~ContentRectangle() = default; | |
| 90 | |
| 91 } // namespace vr_shell | |
| 92 | |
| OLD | NEW |