Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(571)

Side by Side Diff: device/vr/vr_math.cc

Issue 2816833002: VR: Fix dynamic resizing webVR page, revert FOV calculation changes. (Closed)
Patch Set: Correct diffbase Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « device/vr/vr_math.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "device/vr/vr_math.h" 5 #include "device/vr/vr_math.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 10
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 for (int i = 0; i < 4; ++i) { 92 for (int i = 0; i < 4; ++i) {
93 for (int j = 0; j < 4; ++j) { 93 for (int j = 0; j < 4; ++j) {
94 (*out)[i][j] = 0.0f; 94 (*out)[i][j] = 0.0f;
95 for (int k = 0; k < 4; ++k) { 95 for (int k = 0; k < 4; ++k) {
96 (*out)[i][j] += mat1[i][k] * mat2[k][j]; 96 (*out)[i][j] += mat1[i][k] * mat2[k][j];
97 } 97 }
98 } 98 }
99 } 99 }
100 } 100 }
101 101
102 void PerspectiveMatrixFromView(const gfx::RectF& fov,
103 float z_near,
104 float z_far,
105 Mat4f* out) {
106 const float x_left = -std::tan(fov.x() * M_PI / 180.0f) * z_near;
107 const float x_right = std::tan(fov.right() * M_PI / 180.0f) * z_near;
108 const float y_bottom = -std::tan(fov.bottom() * M_PI / 180.0f) * z_near;
109 const float y_top = std::tan(fov.y() * M_PI / 180.0f) * z_near;
110
111 DCHECK(x_left < x_right && y_bottom < y_top && z_near < z_far &&
112 z_near > 0.0f && z_far > 0.0f);
113 const float X = (2 * z_near) / (x_right - x_left);
114 const float Y = (2 * z_near) / (y_top - y_bottom);
115 const float A = (x_right + x_left) / (x_right - x_left);
116 const float B = (y_top + y_bottom) / (y_top - y_bottom);
117 const float C = (z_near + z_far) / (z_near - z_far);
118 const float D = (2 * z_near * z_far) / (z_near - z_far);
119
120 for (int i = 0; i < 4; ++i) {
121 (*out)[i].fill(0.0f);
122 }
123 (*out)[0][0] = X;
124 (*out)[0][2] = A;
125 (*out)[1][1] = Y;
126 (*out)[1][2] = B;
127 (*out)[2][2] = C;
128 (*out)[2][3] = D;
129 (*out)[3][2] = -1;
130 }
131
132 gfx::Vector3dF GetForwardVector(const Mat4f& matrix) { 102 gfx::Vector3dF GetForwardVector(const Mat4f& matrix) {
133 // Same as multiplying the inverse of the rotation component of the matrix by 103 // Same as multiplying the inverse of the rotation component of the matrix by
134 // (0, 0, -1, 0). 104 // (0, 0, -1, 0).
135 return gfx::Vector3dF(-matrix[2][0], -matrix[2][1], -matrix[2][2]); 105 return gfx::Vector3dF(-matrix[2][0], -matrix[2][1], -matrix[2][2]);
136 } 106 }
137 107
138 gfx::Vector3dF GetTranslation(const Mat4f& matrix) { 108 gfx::Vector3dF GetTranslation(const Mat4f& matrix) {
139 return gfx::Vector3dF(matrix[0][3], matrix[1][3], matrix[2][3]); 109 return gfx::Vector3dF(matrix[0][3], matrix[1][3], matrix[2][3]);
140 } 110 }
141 111
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 float len1 = vec1.Length(); 193 float len1 = vec1.Length();
224 float len2 = vec2.Length(); 194 float len2 = vec2.Length();
225 if (len1 == 0 || len2 == 0) 195 if (len1 == 0 || len2 == 0)
226 return false; 196 return false;
227 float cross_p = vec1.x() * vec2.z() - vec1.z() * vec2.x(); 197 float cross_p = vec1.x() * vec2.z() - vec1.z() * vec2.x();
228 *angle = asin(cross_p / (len1 * len2)); 198 *angle = asin(cross_p / (len1 * len2));
229 return true; 199 return true;
230 } 200 }
231 201
232 } // namespace vr 202 } // namespace vr
OLDNEW
« no previous file with comments | « device/vr/vr_math.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698