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

Side by Side Diff: chrome/browser/android/vr_shell/vr_math.cc

Issue 2757213003: Implementing glTF 1.0 parser (Closed)
Patch Set: Resolving merge. Created 3 years, 9 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
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 "chrome/browser/android/vr_shell/vr_math.h" 5 #include "chrome/browser/android/vr_shell/vr_math.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 8
9 #include "base/logging.h"
10
9 namespace vr_shell { 11 namespace vr_shell {
10 12
11 // Internal matrix layout: 13 // Internal matrix layout:
12 // 14 //
13 // m[0][0], m[0][1], m[0][2], m[0][3], 15 // m[0][0], m[0][1], m[0][2], m[0][3],
14 // m[1][0], m[1][1], m[1][2], m[1][3], 16 // m[1][0], m[1][1], m[1][2], m[1][3],
15 // m[2][0], m[2][1], m[2][2], m[2][3], 17 // m[2][0], m[2][1], m[2][2], m[2][3],
16 // m[3][0], m[3][1], m[3][2], m[3][3], 18 // m[3][0], m[3][1], m[3][2], m[3][3],
17 // 19 //
18 // The translation component is in the right column m[i][3]. 20 // The translation component is in the right column m[i][3].
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 101
100 gvr::Mat4f PerspectiveMatrixFromView(const gvr::Rectf& fov, 102 gvr::Mat4f PerspectiveMatrixFromView(const gvr::Rectf& fov,
101 float z_near, 103 float z_near,
102 float z_far) { 104 float z_far) {
103 gvr::Mat4f result; 105 gvr::Mat4f result;
104 const float x_left = -std::tan(fov.left * M_PI / 180.0f) * z_near; 106 const float x_left = -std::tan(fov.left * M_PI / 180.0f) * z_near;
105 const float x_right = std::tan(fov.right * M_PI / 180.0f) * z_near; 107 const float x_right = std::tan(fov.right * M_PI / 180.0f) * z_near;
106 const float y_bottom = -std::tan(fov.bottom * M_PI / 180.0f) * z_near; 108 const float y_bottom = -std::tan(fov.bottom * M_PI / 180.0f) * z_near;
107 const float y_top = std::tan(fov.top * M_PI / 180.0f) * z_near; 109 const float y_top = std::tan(fov.top * M_PI / 180.0f) * z_near;
108 110
109 assert(x_left < x_right && y_bottom < y_top && z_near < z_far && 111 DCHECK(x_left < x_right && y_bottom < y_top && z_near < z_far &&
110 z_near > 0.0f && z_far > 0.0f); 112 z_near > 0.0f && z_far > 0.0f);
111 const float X = (2 * z_near) / (x_right - x_left); 113 const float X = (2 * z_near) / (x_right - x_left);
112 const float Y = (2 * z_near) / (y_top - y_bottom); 114 const float Y = (2 * z_near) / (y_top - y_bottom);
113 const float A = (x_right + x_left) / (x_right - x_left); 115 const float A = (x_right + x_left) / (x_right - x_left);
114 const float B = (y_top + y_bottom) / (y_top - y_bottom); 116 const float B = (y_top + y_bottom) / (y_top - y_bottom);
115 const float C = (z_near + z_far) / (z_near - z_far); 117 const float C = (z_near + z_far) / (z_near - z_far);
116 const float D = (2 * z_near * z_far) / (z_near - z_far); 118 const float D = (2 * z_near * z_far) / (z_near - z_far);
117 119
118 for (int i = 0; i < 4; ++i) { 120 for (int i = 0; i < 4; ++i) {
119 for (int j = 0; j < 4; ++j) { 121 for (int j = 0; j < 4; ++j) {
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 float len1 = VectorLength(vec1); 241 float len1 = VectorLength(vec1);
240 float len2 = VectorLength(vec2); 242 float len2 = VectorLength(vec2);
241 if (len1 == 0 || len2 == 0) 243 if (len1 == 0 || len2 == 0)
242 return false; 244 return false;
243 float cross_p = vec1.x * vec2.z - vec1.z * vec2.x; 245 float cross_p = vec1.x * vec2.z - vec1.z * vec2.x;
244 *angle = asin(cross_p / (len1 * len2)); 246 *angle = asin(cross_p / (len1 * len2));
245 return true; 247 return true;
246 } 248 }
247 249
248 } // namespace vr_shell 250 } // namespace vr_shell
OLDNEW
« no previous file with comments | « chrome/browser/android/vr_shell/test/paths.cc ('k') | chrome/browser/android/vr_shell/vr_shell_gl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698