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 // Left multiply a translation matrix. | |
45 void TranslateM(gvr::Mat4f& tmat, gvr::Mat4f& mat, float x, float y, float z); | 46 void TranslateM(gvr::Mat4f& tmat, gvr::Mat4f& mat, float x, float y, float z); |
47 // Left multiply a scale matrix. | |
46 void ScaleM(gvr::Mat4f& tmat, const gvr::Mat4f& mat, float x, float y, float z); | 48 void ScaleM(gvr::Mat4f& tmat, const gvr::Mat4f& mat, float x, float y, float z); |
47 | 49 |
50 float Clampf(float value, float min, float max); | |
51 float ToDegrees(float radians); | |
52 | |
53 // Spherical Linear Interpolation | |
cjgrant
2017/04/03 19:25:00
// Spherical linear interpolation.
acondor_
2017/04/19 18:44:27
Done.
| |
54 gvr::Vec3f QuatSlerp(gvr::Vec3f start, gvr::Vec3f end, float percent); | |
cjgrant
2017/04/03 19:25:00
Pass start and end by const&?
acondor_
2017/04/19 18:44:27
Done.
| |
55 | |
48 // Util functions that are copied from the treasure_hunt NDK demo in | 56 // Util functions that are copied from the treasure_hunt NDK demo in |
49 // third_party/gvr-andoir-sdk/ folder. | 57 // third_party/gvr-andoir-sdk/ folder. |
58 // Rotation only, ignore translation components. | |
50 gvr::Vec3f MatrixVectorMul(const gvr::Mat4f& m, const gvr::Vec3f& v); | 59 gvr::Vec3f MatrixVectorMul(const gvr::Mat4f& m, const gvr::Vec3f& v); |
51 gvr::Vec3f MatrixVectorRotate(const gvr::Mat4f& m, const gvr::Vec3f& v); | 60 gvr::Vec3f MatrixVectorRotate(const gvr::Mat4f& m, const gvr::Vec3f& v); |
52 gvr::Mat4f MatrixMul(const gvr::Mat4f& matrix1, const gvr::Mat4f& matrix2); | 61 gvr::Mat4f MatrixMul(const gvr::Mat4f& matrix1, const gvr::Mat4f& matrix2); |
53 gvr::Mat4f PerspectiveMatrixFromView(const gvr::Rectf& fov, | 62 gvr::Mat4f PerspectiveMatrixFromView(const gvr::Rectf& fov, |
54 float z_near, | 63 float z_near, |
55 float z_far); | 64 float z_far); |
56 | 65 |
57 // Provides the direction the head is looking towards as a 3x1 unit vector. | 66 // Provides the direction the head is looking towards as a 3x1 unit vector. |
58 gvr::Vec3f GetForwardVector(const gvr::Mat4f& matrix); | 67 gvr::Vec3f GetForwardVector(const gvr::Mat4f& matrix); |
59 | 68 |
60 gvr::Vec3f GetTranslation(const gvr::Mat4f& matrix); | 69 gvr::Vec3f GetTranslation(const gvr::Mat4f& matrix); |
61 | 70 |
62 gvr::Mat4f QuatToMatrix(const gvr::Quatf& quat); | 71 gvr::Mat4f QuatToMatrix(const gvr::Quatf& quat); |
63 | 72 |
73 float VectorLengthSquared(const gvr::Vec3f& vec); | |
64 float VectorLength(const gvr::Vec3f& vec); | 74 float VectorLength(const gvr::Vec3f& vec); |
65 gvr::Vec3f VectorSubtract(const gvr::Vec3f& a, const gvr::Vec3f& b); | 75 gvr::Vec3f VectorSubtract(const gvr::Vec3f& a, const gvr::Vec3f& b); |
76 gvr::Vec3f VectorAdd(const gvr::Vec3f& a, const gvr::Vec3f& b); | |
cjgrant
2017/04/03 19:25:00
If you're adding comments to methods above, certai
acondor_
2017/04/19 18:44:27
Done.
| |
66 float VectorDot(const gvr::Vec3f& a, const gvr::Vec3f& b); | 77 float VectorDot(const gvr::Vec3f& a, const gvr::Vec3f& b); |
78 gvr::Vec3f VectorCross(const gvr::Vec3f& a, const gvr::Vec3f& b); | |
79 gvr::Vec3f PointwiseVectorMul(const gvr::Vec3f& a, const gvr::Vec3f& b); | |
80 gvr::Vec3f VectorScalarMul(const gvr::Vec3f& a, float s); | |
81 float VectorAngleDegrees(const gvr::Vec3f& a, const gvr::Vec3f& b); | |
67 | 82 |
68 // Normalize a vector, and return its original length. | 83 // Normalize a vector, and return its original length. |
69 float NormalizeVector(gvr::Vec3f& vec); | 84 float NormalizeVector(gvr::Vec3f& vec); |
70 | 85 |
71 void NormalizeQuat(gvr::Quatf& quat); | 86 void NormalizeQuat(gvr::Quatf& quat); |
72 | 87 |
88 gvr::Quatf QuatMultiply(const gvr::Quatf& a, const gvr::Quatf& b); | |
89 gvr::Quatf QuatAdd(const gvr::Quatf& a, const gvr::Quatf& b); | |
90 gvr::Quatf QuatScalarMul(const gvr::Quatf& quat, float s); | |
91 gvr::Quatf QuatInverted(const gvr::Quatf& quat); | |
92 float QuatAngleDegrees(const gvr::Quatf& a, const gvr::Quatf& b); | |
93 gvr::Quatf QuatLerp(const gvr::Quatf& a, const gvr::Quatf& b, float t); | |
94 | |
73 gvr::Quatf QuatFromAxisAngle(const gvr::Vec3f& axis, float angle); | 95 gvr::Quatf QuatFromAxisAngle(const gvr::Vec3f& axis, float angle); |
96 gvr::Quatf FromToRotation(const gvr::Vec3f& from, const gvr::Vec3f& to); | |
cjgrant
2017/04/03 19:25:00
From the name, I have no idea what this method doe
acondor_
2017/04/19 18:44:27
Done.
| |
74 | 97 |
75 gvr::Vec3f GetRayPoint(const gvr::Vec3f& rayOrigin, | 98 gvr::Vec3f GetRayPoint(const gvr::Vec3f& rayOrigin, |
76 const gvr::Vec3f& rayVector, | 99 const gvr::Vec3f& rayVector, |
77 float scale); | 100 float scale); |
78 | 101 |
79 float Distance(const gvr::Vec3f& vec1, const gvr::Vec3f& vec2); | 102 float Distance(const gvr::Vec3f& vec1, const gvr::Vec3f& vec2); |
80 | 103 |
81 // Angle between the vectors' projections to the XZ plane. | 104 // Angle between the vectors' projections to the XZ plane. |
82 bool XZAngle(const gvr::Vec3f& vec1, const gvr::Vec3f& vec2, float* angle); | 105 bool XZAngle(const gvr::Vec3f& vec1, const gvr::Vec3f& vec2, float* angle); |
83 | 106 |
84 } // namespace vr_shell | 107 } // namespace vr_shell |
85 | 108 |
86 #endif // CHROME_BROWSER_ANDROID_VR_SHELL_VR_MATH_H_ | 109 #endif // CHROME_BROWSER_ANDROID_VR_SHELL_VR_MATH_H_ |
OLD | NEW |