| 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 #ifndef CHROME_BROWSER_ANDROID_VR_SHELL_VR_UTIL_H_ | |
| 6 #define CHROME_BROWSER_ANDROID_VR_SHELL_VR_UTIL_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 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 | |
| 13 namespace vr_shell { | |
| 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 | |
| 44 std::array<float, 16> MatrixToGLArray(const gvr::Mat4f& matrix); | |
| 45 | |
| 46 // Util functions that are copied from the treasure_hunt NDK demo in | |
| 47 // third_party/gvr-andoir-sdk/ folder. | |
| 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); | |
| 55 gvr::Mat4f MatrixMul(const gvr::Mat4f& matrix1, const gvr::Mat4f& matrix2); | |
| 56 gvr::Mat4f PerspectiveMatrixFromView(const gvr::Rectf& fov, | |
| 57 float z_near, | |
| 58 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 | |
| 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 | |
| 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); | |
| 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 | |
| 95 } // namespace vr_shell | |
| 96 | |
| 97 #endif // CHROME_BROWSER_ANDROID_VR_SHELL_VR_UTIL_H_ | |
| OLD | NEW |