| 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 #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 Loading... |
| 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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 const gvr::Vec3f& rayVector, | 227 const gvr::Vec3f& rayVector, |
| 226 float scale) { | 228 float scale) { |
| 227 gvr::Vec3f v; | 229 gvr::Vec3f v; |
| 228 v.x = rayOrigin.x + scale * rayVector.x; | 230 v.x = rayOrigin.x + scale * rayVector.x; |
| 229 v.y = rayOrigin.y + scale * rayVector.y; | 231 v.y = rayOrigin.y + scale * rayVector.y; |
| 230 v.z = rayOrigin.z + scale * rayVector.z; | 232 v.z = rayOrigin.z + scale * rayVector.z; |
| 231 return v; | 233 return v; |
| 232 } | 234 } |
| 233 | 235 |
| 234 } // namespace vr_shell | 236 } // namespace vr_shell |
| OLD | NEW |