OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_ANDROID_VR_SHELL_UI_ELEMENTS_H_ | 5 #ifndef CHROME_BROWSER_ANDROID_VR_SHELL_UI_ELEMENTS_H_ |
6 #define CHROME_BROWSER_ANDROID_VR_SHELL_UI_ELEMENTS_H_ | 6 #define CHROME_BROWSER_ANDROID_VR_SHELL_UI_ELEMENTS_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 26 matching lines...) Expand all Loading... |
37 // center color. | 37 // center color. |
38 OPAQUE_GRADIENT = 2, | 38 OPAQUE_GRADIENT = 2, |
39 // Same as OPAQUE_GRADIENT but the element is drawn as a grid. | 39 // Same as OPAQUE_GRADIENT but the element is drawn as a grid. |
40 GRID_GRADIENT = 3, | 40 GRID_GRADIENT = 3, |
41 // The element is filled with the content web site. Only one content element | 41 // The element is filled with the content web site. Only one content element |
42 // may be added to the | 42 // may be added to the |
43 // scene. | 43 // scene. |
44 CONTENT = 4, | 44 CONTENT = 4, |
45 }; | 45 }; |
46 | 46 |
47 struct ReversibleTransform { | 47 struct Transform { |
48 ReversibleTransform(); | 48 Transform(); |
49 | 49 |
50 void MakeIdentity(); | 50 void MakeIdentity(); |
51 void Rotate(gvr::Quatf quat); | 51 void Rotate(gvr::Quatf quat); |
52 void Rotate(float ax, float ay, float az, float rad); | 52 void Rotate(float ax, float ay, float az, float rad); |
53 void Translate(float tx, float ty, float tz); | 53 void Translate(float tx, float ty, float tz); |
54 void Scale(float sx, float sy, float sz); | 54 void Scale(float sx, float sy, float sz); |
55 | 55 |
56 gvr::Mat4f to_world; | 56 gvr::Mat4f to_world; |
57 gvr::Mat4f from_world; | |
58 | |
59 // This object-to-world orientation quaternion is technically | |
60 // redundant, but it's easy to track it here for use as needed. | |
61 // TODO(klausw): use this instead of MatrixVectorRotation()? | |
62 // Would need quat * vector implementation. | |
63 gvr::Quatf orientation = {0.0f, 0.0f, 0.0f, 1.0f}; | |
64 }; | 57 }; |
65 | 58 |
66 struct WorldObject { | 59 class WorldRectangle { |
67 ReversibleTransform transform; | 60 public: |
68 }; | 61 const gvr::Mat4f& TransformMatrix() const; |
| 62 void SetTransform(const Transform& transform); |
69 | 63 |
70 struct WorldRectangle : public WorldObject { | |
71 gvr::Vec3f GetCenter() const; | 64 gvr::Vec3f GetCenter() const; |
72 gvr::Vec3f GetNormal() const; | 65 gvr::Vec3f GetNormal() const; |
73 float GetRayDistance(gvr::Vec3f rayOrigin, gvr::Vec3f rayVector) const; | 66 |
| 67 // Computes the distance from |ray_origin| to this rectangles's plane, along |
| 68 // |ray_vector|. Returns true and populates |distance| if the calculation is |
| 69 // possible, and false if the ray is parallel to the plane. |
| 70 bool GetRayDistance(const gvr::Vec3f& ray_origin, |
| 71 const gvr::Vec3f& ray_vector, |
| 72 float* distance) const; |
| 73 |
| 74 // Projects a 3D world point onto the X and Y axes of the transformed |
| 75 // rectangle, returning 2D coordinates relative to the un-transformed unit |
| 76 // rectangle. This allows beam intersection points to be mapped to sprite |
| 77 // pixel coordinates. Points that fall onto the rectangle will generate X and |
| 78 // Y values on the interval [-0.5, 0.5]. |
| 79 gvr::Vec2f GetUnitRectangleCoordinates(const gvr::Vec3f& world_point); |
| 80 |
| 81 private: |
| 82 Transform transform_; |
74 }; | 83 }; |
75 | 84 |
76 struct ContentRectangle : public WorldRectangle { | 85 struct ContentRectangle : public WorldRectangle { |
77 ContentRectangle(); | 86 ContentRectangle(); |
78 ~ContentRectangle(); | 87 ~ContentRectangle(); |
79 | 88 |
80 void Animate(int64_t time); | 89 void Animate(int64_t time); |
81 | 90 |
82 // Indicates whether the element should be visually rendered. | 91 // Indicates whether the element should be visually rendered. |
83 bool IsVisible() const; | 92 bool IsVisible() const; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 | 151 |
143 int draw_phase = 1; | 152 int draw_phase = 1; |
144 | 153 |
145 private: | 154 private: |
146 DISALLOW_COPY_AND_ASSIGN(ContentRectangle); | 155 DISALLOW_COPY_AND_ASSIGN(ContentRectangle); |
147 }; | 156 }; |
148 | 157 |
149 } // namespace vr_shell | 158 } // namespace vr_shell |
150 | 159 |
151 #endif // CHROME_BROWSER_ANDROID_VR_SHELL_UI_ELEMENTS_H_ | 160 #endif // CHROME_BROWSER_ANDROID_VR_SHELL_UI_ELEMENTS_H_ |
OLD | NEW |