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