Chromium Code Reviews| Index: Source/modules/vr/HMDVRDevice.cpp |
| diff --git a/Source/modules/vr/HMDVRDevice.cpp b/Source/modules/vr/HMDVRDevice.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..1f065cecec91bc4b7aa6372f05fb5960782801bf |
| --- /dev/null |
| +++ b/Source/modules/vr/HMDVRDevice.cpp |
| @@ -0,0 +1,143 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "config.h" |
| +#include "modules/vr/HMDVRDevice.h" |
| + |
| +#include "modules/vr/VRFieldOfView.h" |
| +#include "public/platform/Platform.h" |
| +#include "public/platform/WebSize.h" |
| + |
| +namespace blink { |
| + |
| +namespace { |
| + |
| +void setDomPoint(DOMPoint* point, const blink::WebVRVector3& vec) |
| +{ |
| + point->setX(vec.x); |
| + point->setY(vec.y); |
| + point->setZ(vec.z); |
| + point->setW(0.0); |
| +} |
| + |
| +} |
| + |
| +HMDVRDevice::HMDVRDevice(VRHardwareUnit* hardwareUnit) |
| + : VRDevice(hardwareUnit) |
| +{ |
| + m_recommendedFOVLeft = new VRFieldOfView(); |
| + m_recommendedFOVRight = new VRFieldOfView(); |
| + m_maximumFOVLeft = new VRFieldOfView(); |
| + m_maximumFOVRight = new VRFieldOfView(); |
| + m_eyeTranslationLeft = DOMPoint::create(0, 0, 0, 0); |
| + m_eyeTranslationRight = DOMPoint::create(0, 0, 0, 0); |
| +} |
| + |
| +HMDVRDevice::VREye HMDVRDevice::StringToVREye(const String& whichEye) |
| +{ |
| + if (whichEye == "right") { |
| + return VREyeRight; |
| + } |
| + return VREyeLeft; |
|
Ken Russell (switch to Gerrit)
2015/02/04 19:14:00
This should explicitly check for "left" and return
|
| +} |
| + |
| +void HMDVRDevice::updateFromWebVRDevice(const WebVRDevice& device) |
| +{ |
| + VRDevice::updateFromWebVRDevice(device); |
| + const blink::WebVRHMDInfo &hmdInfo = device.hmdInfo; |
| + |
| + m_recommendedFOVLeft->setFromWebVRFieldOfView(hmdInfo.recommendedFOVLeft); |
| + m_recommendedFOVRight->setFromWebVRFieldOfView(hmdInfo.recommendedFOVRight); |
| + m_maximumFOVLeft->setFromWebVRFieldOfView(hmdInfo.maximumFOVLeft); |
| + m_maximumFOVRight->setFromWebVRFieldOfView(hmdInfo.maximumFOVRight); |
| + setDomPoint(m_eyeTranslationLeft, hmdInfo.eyeTranslationLeft); |
| + setDomPoint(m_eyeTranslationRight, hmdInfo.eyeTranslationRight); |
| + hardwareUnit()->setFieldOfView(0, m_recommendedFOVLeft); |
| + hardwareUnit()->setFieldOfView(1, m_recommendedFOVRight); |
| +} |
| + |
| +DOMPoint* HMDVRDevice::getEyeTranslation(const String& whichEye) |
| +{ |
| + switch (StringToVREye(whichEye)) { |
| + case VREyeRight: |
| + return m_eyeTranslationRight; |
| + default: |
| + return m_eyeTranslationLeft; |
|
Ken Russell (switch to Gerrit)
2015/02/04 19:13:59
Throughout, all of the code returning the value fo
|
| + } |
| +} |
| + |
| +VRFieldOfView* HMDVRDevice::getCurrentEyeFieldOfView(const String& whichEye) |
| +{ |
| + return hardwareUnit()->getCurrentEyeFieldOfView(StringToVREye(whichEye)); |
| +} |
| + |
| +VRFieldOfView* HMDVRDevice::getRecommendedEyeFieldOfView(const String& whichEye) |
| +{ |
| + switch (StringToVREye(whichEye)) { |
| + case VREyeRight: |
| + return new VRFieldOfView(*m_recommendedFOVRight); |
| + default: |
| + return new VRFieldOfView(*m_recommendedFOVLeft); |
| + } |
| +} |
| + |
| +VRFieldOfView* HMDVRDevice::getMaximumEyeFieldOfView(const String& whichEye) |
| +{ |
| + switch (StringToVREye(whichEye)) { |
| + case VREyeRight: |
| + return new VRFieldOfView(*m_maximumFOVRight); |
| + default: |
| + return new VRFieldOfView(*m_maximumFOVLeft); |
| + } |
| +} |
| + |
| +void HMDVRDevice::setFieldOfView(VRFieldOfView* leftFov, VRFieldOfView* rightFov) |
| +{ |
| + // TODO: Clamp to maxFOV |
| + |
| + if (leftFov) { |
| + hardwareUnit()->setFieldOfView(0, leftFov); |
| + } else { |
| + hardwareUnit()->setFieldOfView(0, m_recommendedFOVLeft); |
| + } |
| + |
| + if (rightFov) { |
| + hardwareUnit()->setFieldOfView(1, rightFov); |
| + } else { |
| + hardwareUnit()->setFieldOfView(1, m_recommendedFOVRight); |
| + } |
| +} |
| + |
| +DOMRect* HMDVRDevice::getRecommendedEyeRenderRect(const String& whichEye) |
| +{ |
| + // TODO: This doesn't change unless you reset the FOV. Cache it. |
|
Ken Russell (switch to Gerrit)
2015/02/04 19:14:00
Add owner for TODOs throughout.
|
| + blink::WebSize size; |
| + blink::Platform::current()->getVRRenderTargetSize(index(), |
| + hardwareUnit()->getFieldOfView(HMDVRDevice::VREyeLeft), |
| + hardwareUnit()->getFieldOfView(HMDVRDevice::VREyeRight), |
| + &size); |
| + |
| + // TODO: We can actually fetch individual eye rects from the Oculus SDK. |
| + // Plumb that through and expose it here. |
| + switch (StringToVREye(whichEye)) { |
| + case VREyeRight: |
| + return DOMRect::create(size.width / 2.0f, 0, size.width / 2.0f, size.height); |
| + default: |
| + return DOMRect::create(0, 0, size.width / 2.0f, size.height); |
| + } |
| +} |
| + |
| +void HMDVRDevice::trace(Visitor* visitor) |
| +{ |
| + VRDevice::trace(visitor); |
| + |
| + visitor->trace(m_recommendedFOVLeft); |
| + visitor->trace(m_recommendedFOVRight); |
| + visitor->trace(m_maximumFOVLeft); |
| + visitor->trace(m_maximumFOVRight); |
| + visitor->trace(m_eyeTranslationLeft); |
| + visitor->trace(m_eyeTranslationRight); |
| +} |
| + |
| +} // namespace blink |