| 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 "modules/vr/VRFrameData.h" | 5 #include "modules/vr/VRFrameData.h" |
| 6 | 6 |
| 7 #include "modules/vr/VREyeParameters.h" | 7 #include "modules/vr/VREyeParameters.h" |
| 8 #include "modules/vr/VRPose.h" | 8 #include "modules/vr/VRPose.h" |
| 9 | 9 |
| 10 #include <cmath> | 10 #include <cmath> |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 out[9] = ((upTan - downTan) * yScale * 0.5); | 40 out[9] = ((upTan - downTan) * yScale * 0.5); |
| 41 out[10] = (depthNear + depthFar) / (depthNear - depthFar); | 41 out[10] = (depthNear + depthFar) / (depthNear - depthFar); |
| 42 out[11] = -1.0f; | 42 out[11] = -1.0f; |
| 43 out[12] = 0.0f; | 43 out[12] = 0.0f; |
| 44 out[13] = 0.0f; | 44 out[13] = 0.0f; |
| 45 out[14] = (2 * depthFar * depthNear) / (depthNear - depthFar); | 45 out[14] = (2 * depthFar * depthNear) / (depthNear - depthFar); |
| 46 out[15] = 0.0f; | 46 out[15] = 0.0f; |
| 47 } | 47 } |
| 48 | 48 |
| 49 // Create a matrix from a rotation and translation. | 49 // Create a matrix from a rotation and translation. |
| 50 void matrixfromRotationTranslation(DOMFloat32Array* outArray, | 50 void matrixfromRotationTranslation( |
| 51 const mojo::WTFArray<float>& rotation, | 51 DOMFloat32Array* outArray, |
| 52 const mojo::WTFArray<float>& translation) { | 52 const WTF::Optional<WTF::Vector<float>>& rotation, |
| 53 const WTF::Optional<WTF::Vector<float>>& translation) { |
| 53 // Quaternion math | 54 // Quaternion math |
| 54 float x = rotation.is_null() ? 0.0f : rotation[0]; | 55 float x = !rotation ? 0.0f : rotation.value()[0]; |
| 55 float y = rotation.is_null() ? 0.0f : rotation[1]; | 56 float y = !rotation ? 0.0f : rotation.value()[1]; |
| 56 float z = rotation.is_null() ? 0.0f : rotation[2]; | 57 float z = !rotation ? 0.0f : rotation.value()[2]; |
| 57 float w = rotation.is_null() ? 1.0f : rotation[3]; | 58 float w = !rotation ? 1.0f : rotation.value()[3]; |
| 58 float x2 = x + x; | 59 float x2 = x + x; |
| 59 float y2 = y + y; | 60 float y2 = y + y; |
| 60 float z2 = z + z; | 61 float z2 = z + z; |
| 61 | 62 |
| 62 float xx = x * x2; | 63 float xx = x * x2; |
| 63 float xy = x * y2; | 64 float xy = x * y2; |
| 64 float xz = x * z2; | 65 float xz = x * z2; |
| 65 float yy = y * y2; | 66 float yy = y * y2; |
| 66 float yz = y * z2; | 67 float yz = y * z2; |
| 67 float zz = z * z2; | 68 float zz = z * z2; |
| 68 float wx = w * x2; | 69 float wx = w * x2; |
| 69 float wy = w * y2; | 70 float wy = w * y2; |
| 70 float wz = w * z2; | 71 float wz = w * z2; |
| 71 | 72 |
| 72 float* out = outArray->data(); | 73 float* out = outArray->data(); |
| 73 out[0] = 1 - (yy + zz); | 74 out[0] = 1 - (yy + zz); |
| 74 out[1] = xy + wz; | 75 out[1] = xy + wz; |
| 75 out[2] = xz - wy; | 76 out[2] = xz - wy; |
| 76 out[3] = 0; | 77 out[3] = 0; |
| 77 out[4] = xy - wz; | 78 out[4] = xy - wz; |
| 78 out[5] = 1 - (xx + zz); | 79 out[5] = 1 - (xx + zz); |
| 79 out[6] = yz + wx; | 80 out[6] = yz + wx; |
| 80 out[7] = 0; | 81 out[7] = 0; |
| 81 out[8] = xz + wy; | 82 out[8] = xz + wy; |
| 82 out[9] = yz - wx; | 83 out[9] = yz - wx; |
| 83 out[10] = 1 - (xx + yy); | 84 out[10] = 1 - (xx + yy); |
| 84 out[11] = 0; | 85 out[11] = 0; |
| 85 out[12] = translation.is_null() ? 0.0f : translation[0]; | 86 out[12] = !translation ? 0.0f : translation.value()[0]; |
| 86 out[13] = translation.is_null() ? 0.0f : translation[1]; | 87 out[13] = !translation ? 0.0f : translation.value()[1]; |
| 87 out[14] = translation.is_null() ? 0.0f : translation[2]; | 88 out[14] = !translation ? 0.0f : translation.value()[2]; |
| 88 out[15] = 1; | 89 out[15] = 1; |
| 89 } | 90 } |
| 90 | 91 |
| 91 // Translate a matrix | 92 // Translate a matrix |
| 92 void matrixTranslate(DOMFloat32Array* outArray, | 93 void matrixTranslate(DOMFloat32Array* outArray, |
| 93 const DOMFloat32Array* translation) { | 94 const DOMFloat32Array* translation) { |
| 94 if (!translation) | 95 if (!translation) |
| 95 return; | 96 return; |
| 96 | 97 |
| 97 float x = translation->data()[0]; | 98 float x = translation->data()[0]; |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 | 212 |
| 212 DEFINE_TRACE(VRFrameData) { | 213 DEFINE_TRACE(VRFrameData) { |
| 213 visitor->trace(m_leftProjectionMatrix); | 214 visitor->trace(m_leftProjectionMatrix); |
| 214 visitor->trace(m_leftViewMatrix); | 215 visitor->trace(m_leftViewMatrix); |
| 215 visitor->trace(m_rightProjectionMatrix); | 216 visitor->trace(m_rightProjectionMatrix); |
| 216 visitor->trace(m_rightViewMatrix); | 217 visitor->trace(m_rightViewMatrix); |
| 217 visitor->trace(m_pose); | 218 visitor->trace(m_pose); |
| 218 } | 219 } |
| 219 | 220 |
| 220 } // namespace blink | 221 } // namespace blink |
| OLD | NEW |