| OLD | NEW |
| 1 // Copyright (c) 2017 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2017 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 #define _USE_MATH_DEFINES // for M_PI | 5 #define _USE_MATH_DEFINES // for M_PI |
| 6 #include "device/vr/openvr/openvr_device.h" | 6 #include "device/vr/openvr/openvr_device.h" |
| 7 #include <math.h> | 7 #include <math.h> |
| 8 #include "third_party/openvr/src/headers/openvr.h" | 8 #include "third_party/openvr/src/headers/openvr.h" |
| 9 | 9 |
| 10 namespace { | 10 namespace { |
| 11 | 11 |
| 12 constexpr float kRadToDeg = static_cast<float>(180 / M_PI); | 12 constexpr float kRadToDeg = static_cast<float>(180 / M_PI); |
| 13 constexpr float kDefaultIPD = 0.06f; // Default average IPD | 13 constexpr float kDefaultIPD = 0.06f; // Default average IPD |
| 14 | 14 |
| 15 device::mojom::VRFieldOfViewPtr openVRFovToWebVRFov(vr::IVRSystem* vr_system, | 15 device::mojom::VRFieldOfViewPtr openVRFovToWebVRFov(vr::IVRSystem* vr_system, |
| 16 vr::Hmd_Eye eye) { | 16 vr::Hmd_Eye eye) { |
| 17 device::mojom::VRFieldOfViewPtr out = device::mojom::VRFieldOfView::New(); | 17 device::mojom::VRFieldOfViewPtr out = device::mojom::VRFieldOfView::New(); |
| 18 float up_tan, down_tan, left_tan, right_tan; | 18 float up_tan, down_tan, left_tan, right_tan; |
| 19 vr_system->GetProjectionRaw(eye, &left_tan, &right_tan, &up_tan, &down_tan); | 19 vr_system->GetProjectionRaw(eye, &left_tan, &right_tan, &up_tan, &down_tan); |
| 20 out->upDegrees = -(atanf(up_tan) * kRadToDeg); | 20 out->upDegrees = -(atanf(up_tan) * kRadToDeg); |
| 21 out->downDegrees = atanf(down_tan) * kRadToDeg; | 21 out->downDegrees = atanf(down_tan) * kRadToDeg; |
| 22 out->leftDegrees = -(atanf(left_tan) * kRadToDeg); | 22 out->leftDegrees = -(atanf(left_tan) * kRadToDeg); |
| 23 out->rightDegrees = atanf(right_tan) * kRadToDeg; | 23 out->rightDegrees = atanf(right_tan) * kRadToDeg; |
| 24 return out; | 24 return out; |
| 25 } | 25 } |
| 26 | 26 |
| 27 std::vector<float> HmdVector3ToWebVR(const vr::HmdVector3_t& vec) { |
| 28 std::vector<float> out; |
| 29 out.resize(3); |
| 30 out[0] = vec.v[0]; |
| 31 out[1] = vec.v[1]; |
| 32 out[2] = vec.v[2]; |
| 33 return out; |
| 34 } |
| 35 |
| 27 } // namespace | 36 } // namespace |
| 28 | 37 |
| 29 namespace device { | 38 namespace device { |
| 30 | 39 |
| 31 OpenVRDevice::OpenVRDevice() {} | 40 OpenVRDevice::OpenVRDevice() {} |
| 32 OpenVRDevice::~OpenVRDevice() {} | 41 OpenVRDevice::~OpenVRDevice() {} |
| 33 | 42 |
| 34 void OpenVRDevice::CreateVRDisplayInfo( | 43 void OpenVRDevice::CreateVRDisplayInfo( |
| 35 const base::Callback<void(mojom::VRDisplayInfoPtr)>& on_created) { | 44 const base::Callback<void(mojom::VRDisplayInfoPtr)>& on_created) { |
| 36 vr::EVRInitError init_error; | 45 vr::EVRInitError init_error; |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 const auto& m = transform.m; | 166 const auto& m = transform.m; |
| 158 float w = sqrt(1 + m[0][0] + m[1][1] + m[2][2]); | 167 float w = sqrt(1 + m[0][0] + m[1][1] + m[2][2]); |
| 159 pose->orientation.value()[0] = (m[2][1] - m[1][2]) / (4 * w); | 168 pose->orientation.value()[0] = (m[2][1] - m[1][2]) / (4 * w); |
| 160 pose->orientation.value()[1] = (m[0][2] - m[2][0]) / (4 * w); | 169 pose->orientation.value()[1] = (m[0][2] - m[2][0]) / (4 * w); |
| 161 pose->orientation.value()[2] = (m[1][0] - m[0][1]) / (4 * w); | 170 pose->orientation.value()[2] = (m[1][0] - m[0][1]) / (4 * w); |
| 162 pose->orientation.value()[3] = w; | 171 pose->orientation.value()[3] = w; |
| 163 | 172 |
| 164 pose->position.value()[0] = m[0][3]; | 173 pose->position.value()[0] = m[0][3]; |
| 165 pose->position.value()[1] = m[1][3]; | 174 pose->position.value()[1] = m[1][3]; |
| 166 pose->position.value()[2] = m[2][3]; | 175 pose->position.value()[2] = m[2][3]; |
| 176 |
| 177 pose->linearVelocity = HmdVector3ToWebVR(hmdPose.vVelocity); |
| 178 pose->angularVelocity = HmdVector3ToWebVR(hmdPose.vAngularVelocity); |
| 167 } | 179 } |
| 168 | 180 |
| 169 return std::move(pose); | 181 return std::move(pose); |
| 170 } | 182 } |
| 171 | 183 |
| 172 void OpenVRDevice::OpenVRRenderLoop::GetVSync( | 184 void OpenVRDevice::OpenVRRenderLoop::GetVSync( |
| 173 const mojom::VRVSyncProvider::GetVSyncCallback& callback) { | 185 const mojom::VRVSyncProvider::GetVSyncCallback& callback) { |
| 174 static int16_t next_frame = 0; | 186 static int16_t next_frame = 0; |
| 175 int16_t frame = next_frame++; | 187 int16_t frame = next_frame++; |
| 176 | 188 |
| 177 // TODO(BillOrr): Give real values when VSync loop is hooked up. This is the | 189 // TODO(BillOrr): Give real values when VSync loop is hooked up. This is the |
| 178 // presentation time for the frame. Just returning a default value for now | 190 // presentation time for the frame. Just returning a default value for now |
| 179 // since we don't have VSync hooked up. | 191 // since we don't have VSync hooked up. |
| 180 base::TimeDelta time = base::TimeDelta::FromSecondsD(2.0); | 192 base::TimeDelta time = base::TimeDelta::FromSecondsD(2.0); |
| 181 | 193 |
| 182 device::mojom::VRPosePtr pose = getPose(); | 194 device::mojom::VRPosePtr pose = getPose(); |
| 183 Sleep(11); // TODO (billorr): Use real vsync timing instead of a sleep (this | 195 Sleep(11); // TODO (billorr): Use real vsync timing instead of a sleep (this |
| 184 // sleep just throttles vsyncs so we don't fill message queues). | 196 // sleep just throttles vsyncs so we don't fill message queues). |
| 185 callback.Run(std::move(pose), time, frame, | 197 callback.Run(std::move(pose), time, frame, |
| 186 device::mojom::VRVSyncProvider::Status::SUCCESS); | 198 device::mojom::VRVSyncProvider::Status::SUCCESS); |
| 187 } | 199 } |
| 188 | 200 |
| 189 } // namespace device | 201 } // namespace device |
| OLD | NEW |