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_VR_UTIL_H_ | 5 #ifndef CHROME_BROWSER_ANDROID_VR_SHELL_VR_MATH_H_ |
6 #define CHROME_BROWSER_ANDROID_VR_SHELL_VR_UTIL_H_ | 6 #define CHROME_BROWSER_ANDROID_VR_SHELL_VR_MATH_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "third_party/gvr-android-sdk/src/ndk-beta/include/vr/gvr/capi/include/g
vr_types.h" | 10 #include "third_party/gvr-android-sdk/src/ndk-beta/include/vr/gvr/capi/include/g
vr_types.h" |
11 #include "ui/gl/gl_bindings.h" | |
12 | 11 |
13 namespace vr_shell { | 12 namespace vr_shell { |
14 | 13 |
15 // 2D rectangles. Unlike gvr::Rectf and gvr::Recti, these have width and height | 14 // 2D rectangles. Unlike gvr::Rectf and gvr::Recti, these have width and height |
16 // rather than right and top. | 15 // rather than right and top. |
17 typedef struct Recti { | 16 typedef struct Recti { |
18 int x; | 17 int x; |
19 int y; | 18 int y; |
20 int width; | 19 int width; |
21 int height; | 20 int height; |
(...skipping 12 matching lines...) Expand all Loading... |
34 void TranslateMRight(gvr::Mat4f& tmat, | 33 void TranslateMRight(gvr::Mat4f& tmat, |
35 gvr::Mat4f& mat, | 34 gvr::Mat4f& mat, |
36 float x, | 35 float x, |
37 float y, | 36 float y, |
38 float z); | 37 float z); |
39 | 38 |
40 void ScaleM(gvr::Mat4f& tmat, const gvr::Mat4f& mat, float x, float y, float z); | 39 void ScaleM(gvr::Mat4f& tmat, const gvr::Mat4f& mat, float x, float y, float z); |
41 void ScaleMRight(gvr::Mat4f& tmat, const gvr::Mat4f& mat, | 40 void ScaleMRight(gvr::Mat4f& tmat, const gvr::Mat4f& mat, |
42 float x, float y, float z); | 41 float x, float y, float z); |
43 | 42 |
44 std::array<float, 16> MatrixToGLArray(const gvr::Mat4f& matrix); | |
45 | |
46 // Util functions that are copied from the treasure_hunt NDK demo in | 43 // Util functions that are copied from the treasure_hunt NDK demo in |
47 // third_party/gvr-andoir-sdk/ folder. | 44 // third_party/gvr-andoir-sdk/ folder. |
48 gvr::Mat4f MatrixTranspose(const gvr::Mat4f& mat); | 45 gvr::Mat4f MatrixTranspose(const gvr::Mat4f& mat); |
49 std::array<float, 4> MatrixVectorMul(const gvr::Mat4f& matrix, | 46 std::array<float, 4> MatrixVectorMul(const gvr::Mat4f& matrix, |
50 const std::array<float, 4>& vec); | 47 const std::array<float, 4>& vec); |
51 std::array<float, 3> MatrixVectorMul(const gvr::Mat4f& matrix, | 48 std::array<float, 3> MatrixVectorMul(const gvr::Mat4f& matrix, |
52 const std::array<float, 3>& vec); | 49 const std::array<float, 3>& vec); |
53 gvr::Vec3f MatrixVectorMul(const gvr::Mat4f& m, const gvr::Vec3f& v); | 50 gvr::Vec3f MatrixVectorMul(const gvr::Mat4f& m, const gvr::Vec3f& v); |
54 gvr::Vec3f MatrixVectorRotate(const gvr::Mat4f& m, const gvr::Vec3f& v); | 51 gvr::Vec3f MatrixVectorRotate(const gvr::Mat4f& m, const gvr::Vec3f& v); |
55 gvr::Mat4f MatrixMul(const gvr::Mat4f& matrix1, const gvr::Mat4f& matrix2); | 52 gvr::Mat4f MatrixMul(const gvr::Mat4f& matrix1, const gvr::Mat4f& matrix2); |
56 gvr::Mat4f PerspectiveMatrixFromView(const gvr::Rectf& fov, | 53 gvr::Mat4f PerspectiveMatrixFromView(const gvr::Rectf& fov, |
57 float z_near, | 54 float z_near, |
58 float z_far); | 55 float z_far); |
59 gvr::Rectf ModulateRect(const gvr::Rectf& rect, float width, float height); | |
60 gvr::Recti CalculatePixelSpaceRect(const gvr::Sizei& texture_size, | |
61 const gvr::Rectf& texture_rect); | |
62 | 56 |
63 // Provides the direction the head is looking towards as a 3x1 unit vector. | 57 // Provides the direction the head is looking towards as a 3x1 unit vector. |
64 gvr::Vec3f getForwardVector(const gvr::Mat4f& matrix); | 58 gvr::Vec3f getForwardVector(const gvr::Mat4f& matrix); |
65 | 59 |
66 // Provides the relative translation of the head as a 3x1 vector. | 60 // Provides the relative translation of the head as a 3x1 vector. |
67 gvr::Vec3f getTranslation(const gvr::Mat4f& matrix); | 61 gvr::Vec3f getTranslation(const gvr::Mat4f& matrix); |
68 | 62 |
69 // Compile a shader. | |
70 GLuint CompileShader(GLenum shader_type, | |
71 const GLchar* shader_source, | |
72 std::string& error); | |
73 | |
74 // Compile and link a program. | |
75 GLuint CreateAndLinkProgram(GLuint vertex_shader_handle, | |
76 GLuint fragment_shader_handle, | |
77 int num_attributes, | |
78 const GLchar** attributes, | |
79 std::string& error); | |
80 | |
81 gvr::Quatf QuatMultiply(const gvr::Quatf& a, const gvr::Quatf& b); | 63 gvr::Quatf QuatMultiply(const gvr::Quatf& a, const gvr::Quatf& b); |
82 | 64 |
83 gvr::Mat4f QuatToMatrix(const gvr::Quatf& quat); | 65 gvr::Mat4f QuatToMatrix(const gvr::Quatf& quat); |
84 | 66 |
85 float VectorLength(const gvr::Vec3f& vec); | 67 float VectorLength(const gvr::Vec3f& vec); |
86 | 68 |
87 void NormalizeVector(gvr::Vec3f& vec); | 69 void NormalizeVector(gvr::Vec3f& vec); |
88 | 70 |
89 float VectorDot(const gvr::Vec3f& a, const gvr::Vec3f& b); | 71 float VectorDot(const gvr::Vec3f& a, const gvr::Vec3f& b); |
90 | 72 |
91 void NormalizeQuat(gvr::Quatf& quat); | 73 void NormalizeQuat(gvr::Quatf& quat); |
92 | 74 |
93 gvr::Quatf QuatFromAxisAngle(float x, float y, float z, float angle); | 75 gvr::Quatf QuatFromAxisAngle(float x, float y, float z, float angle); |
94 | 76 |
95 } // namespace vr_shell | 77 } // namespace vr_shell |
96 | 78 |
97 #endif // CHROME_BROWSER_ANDROID_VR_SHELL_VR_UTIL_H_ | 79 #endif // CHROME_BROWSER_ANDROID_VR_SHELL_VR_MATH_H_ |
OLD | NEW |