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_MATH_H_ | 5 #ifndef CHROME_BROWSER_ANDROID_VR_SHELL_VR_MATH_H_ |
6 #define CHROME_BROWSER_ANDROID_VR_SHELL_VR_MATH_H_ | 6 #define CHROME_BROWSER_ANDROID_VR_SHELL_VR_MATH_H_ |
7 | 7 |
8 #include <array> | 8 #include <array> |
9 | 9 |
10 #include "third_party/gvr-android-sdk/src/libraries/headers/vr/gvr/capi/include/
gvr_types.h" | 10 #include "third_party/gvr-android-sdk/src/libraries/headers/vr/gvr/capi/include/
gvr_types.h" |
(...skipping 24 matching lines...) Expand all Loading... |
35 } RotationAxisAngle; | 35 } RotationAxisAngle; |
36 | 36 |
37 typedef struct Colorf { | 37 typedef struct Colorf { |
38 float r; | 38 float r; |
39 float g; | 39 float g; |
40 float b; | 40 float b; |
41 float a; | 41 float a; |
42 } Colorf; | 42 } Colorf; |
43 | 43 |
44 void SetIdentityM(gvr::Mat4f& mat); | 44 void SetIdentityM(gvr::Mat4f& mat); |
45 | |
46 void TranslateM(gvr::Mat4f& tmat, gvr::Mat4f& mat, float x, float y, float z); | 45 void TranslateM(gvr::Mat4f& tmat, gvr::Mat4f& mat, float x, float y, float z); |
47 void TranslateMRight(gvr::Mat4f& tmat, | |
48 gvr::Mat4f& mat, | |
49 float x, | |
50 float y, | |
51 float z); | |
52 | |
53 void ScaleM(gvr::Mat4f& tmat, const gvr::Mat4f& mat, float x, float y, float z); | 46 void ScaleM(gvr::Mat4f& tmat, const gvr::Mat4f& mat, float x, float y, float z); |
54 void ScaleMRight(gvr::Mat4f& tmat, | |
55 const gvr::Mat4f& mat, | |
56 float x, | |
57 float y, | |
58 float z); | |
59 | 47 |
60 // Util functions that are copied from the treasure_hunt NDK demo in | 48 // Util functions that are copied from the treasure_hunt NDK demo in |
61 // third_party/gvr-andoir-sdk/ folder. | 49 // third_party/gvr-andoir-sdk/ folder. |
62 gvr::Mat4f MatrixTranspose(const gvr::Mat4f& mat); | |
63 std::array<float, 4> MatrixVectorMul(const gvr::Mat4f& matrix, | |
64 const std::array<float, 4>& vec); | |
65 std::array<float, 3> MatrixVectorMul(const gvr::Mat4f& matrix, | |
66 const std::array<float, 3>& vec); | |
67 gvr::Vec3f MatrixVectorMul(const gvr::Mat4f& m, const gvr::Vec3f& v); | 50 gvr::Vec3f MatrixVectorMul(const gvr::Mat4f& m, const gvr::Vec3f& v); |
68 gvr::Vec3f MatrixVectorRotate(const gvr::Mat4f& m, const gvr::Vec3f& v); | 51 gvr::Vec3f MatrixVectorRotate(const gvr::Mat4f& m, const gvr::Vec3f& v); |
69 gvr::Mat4f MatrixMul(const gvr::Mat4f& matrix1, const gvr::Mat4f& matrix2); | 52 gvr::Mat4f MatrixMul(const gvr::Mat4f& matrix1, const gvr::Mat4f& matrix2); |
70 gvr::Mat4f PerspectiveMatrixFromView(const gvr::Rectf& fov, | 53 gvr::Mat4f PerspectiveMatrixFromView(const gvr::Rectf& fov, |
71 float z_near, | 54 float z_near, |
72 float z_far); | 55 float z_far); |
73 | 56 |
74 // 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. |
75 gvr::Vec3f GetForwardVector(const gvr::Mat4f& matrix); | 58 gvr::Vec3f GetForwardVector(const gvr::Mat4f& matrix); |
76 | 59 |
77 gvr::Vec3f GetTranslation(const gvr::Mat4f& matrix); | 60 gvr::Vec3f GetTranslation(const gvr::Mat4f& matrix); |
78 | 61 |
79 gvr::Quatf QuatMultiply(const gvr::Quatf& a, const gvr::Quatf& b); | |
80 | |
81 gvr::Mat4f QuatToMatrix(const gvr::Quatf& quat); | 62 gvr::Mat4f QuatToMatrix(const gvr::Quatf& quat); |
82 | 63 |
83 float VectorLength(const gvr::Vec3f& vec); | 64 float VectorLength(const gvr::Vec3f& vec); |
| 65 gvr::Vec3f VectorSubtract(const gvr::Vec3f& a, const gvr::Vec3f& b); |
| 66 float VectorDot(const gvr::Vec3f& a, const gvr::Vec3f& b); |
84 | 67 |
85 // Normalize a vector, and return its original length. | 68 // Normalize a vector, and return its original length. |
86 float NormalizeVector(gvr::Vec3f& vec); | 69 float NormalizeVector(gvr::Vec3f& vec); |
87 | 70 |
88 float VectorDot(const gvr::Vec3f& a, const gvr::Vec3f& b); | |
89 | |
90 void NormalizeQuat(gvr::Quatf& quat); | 71 void NormalizeQuat(gvr::Quatf& quat); |
91 | 72 |
92 gvr::Quatf QuatFromAxisAngle(const gvr::Vec3f& axis, float angle); | 73 gvr::Quatf QuatFromAxisAngle(const gvr::Vec3f& axis, float angle); |
93 | 74 |
94 gvr::Vec3f GetRayPoint(const gvr::Vec3f& rayOrigin, | 75 gvr::Vec3f GetRayPoint(const gvr::Vec3f& rayOrigin, |
95 const gvr::Vec3f& rayVector, | 76 const gvr::Vec3f& rayVector, |
96 float scale); | 77 float scale); |
97 | 78 |
98 } // namespace vr_shell | 79 } // namespace vr_shell |
99 | 80 |
100 #endif // CHROME_BROWSER_ANDROID_VR_SHELL_VR_MATH_H_ | 81 #endif // CHROME_BROWSER_ANDROID_VR_SHELL_VR_MATH_H_ |
OLD | NEW |