OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "config.h" | |
6 #include "modules/vr/HMDVRDevice.h" | |
7 | |
8 #include "modules/vr/VRFieldOfView.h" | |
9 #include "public/platform/Platform.h" | |
10 #include "public/platform/WebSize.h" | |
11 | |
12 namespace blink { | |
13 | |
14 namespace { | |
15 | |
16 void setDomPoint(DOMPoint* point, const blink::WebVRVector3& vec) | |
17 { | |
18 point->setX(vec.x); | |
19 point->setY(vec.y); | |
20 point->setZ(vec.z); | |
21 point->setW(0.0); | |
22 } | |
23 | |
24 } | |
25 | |
26 HMDVRDevice::HMDVRDevice(VRHardwareUnit* hardwareUnit) | |
27 : VRDevice(hardwareUnit) | |
28 { | |
29 m_recommendedFOVLeft = new VRFieldOfView(); | |
30 m_recommendedFOVRight = new VRFieldOfView(); | |
31 m_maximumFOVLeft = new VRFieldOfView(); | |
32 m_maximumFOVRight = new VRFieldOfView(); | |
33 m_eyeTranslationLeft = DOMPoint::create(0, 0, 0, 0); | |
34 m_eyeTranslationRight = DOMPoint::create(0, 0, 0, 0); | |
35 } | |
36 | |
37 HMDVRDevice::VREye HMDVRDevice::StringToVREye(const String& whichEye) | |
38 { | |
39 if (whichEye == "right") { | |
40 return VREyeRight; | |
41 } | |
42 return VREyeLeft; | |
Ken Russell (switch to Gerrit)
2015/02/04 19:14:00
This should explicitly check for "left" and return
| |
43 } | |
44 | |
45 void HMDVRDevice::updateFromWebVRDevice(const WebVRDevice& device) | |
46 { | |
47 VRDevice::updateFromWebVRDevice(device); | |
48 const blink::WebVRHMDInfo &hmdInfo = device.hmdInfo; | |
49 | |
50 m_recommendedFOVLeft->setFromWebVRFieldOfView(hmdInfo.recommendedFOVLeft); | |
51 m_recommendedFOVRight->setFromWebVRFieldOfView(hmdInfo.recommendedFOVRight); | |
52 m_maximumFOVLeft->setFromWebVRFieldOfView(hmdInfo.maximumFOVLeft); | |
53 m_maximumFOVRight->setFromWebVRFieldOfView(hmdInfo.maximumFOVRight); | |
54 setDomPoint(m_eyeTranslationLeft, hmdInfo.eyeTranslationLeft); | |
55 setDomPoint(m_eyeTranslationRight, hmdInfo.eyeTranslationRight); | |
56 hardwareUnit()->setFieldOfView(0, m_recommendedFOVLeft); | |
57 hardwareUnit()->setFieldOfView(1, m_recommendedFOVRight); | |
58 } | |
59 | |
60 DOMPoint* HMDVRDevice::getEyeTranslation(const String& whichEye) | |
61 { | |
62 switch (StringToVREye(whichEye)) { | |
63 case VREyeRight: | |
64 return m_eyeTranslationRight; | |
65 default: | |
66 return m_eyeTranslationLeft; | |
Ken Russell (switch to Gerrit)
2015/02/04 19:13:59
Throughout, all of the code returning the value fo
| |
67 } | |
68 } | |
69 | |
70 VRFieldOfView* HMDVRDevice::getCurrentEyeFieldOfView(const String& whichEye) | |
71 { | |
72 return hardwareUnit()->getCurrentEyeFieldOfView(StringToVREye(whichEye)); | |
73 } | |
74 | |
75 VRFieldOfView* HMDVRDevice::getRecommendedEyeFieldOfView(const String& whichEye) | |
76 { | |
77 switch (StringToVREye(whichEye)) { | |
78 case VREyeRight: | |
79 return new VRFieldOfView(*m_recommendedFOVRight); | |
80 default: | |
81 return new VRFieldOfView(*m_recommendedFOVLeft); | |
82 } | |
83 } | |
84 | |
85 VRFieldOfView* HMDVRDevice::getMaximumEyeFieldOfView(const String& whichEye) | |
86 { | |
87 switch (StringToVREye(whichEye)) { | |
88 case VREyeRight: | |
89 return new VRFieldOfView(*m_maximumFOVRight); | |
90 default: | |
91 return new VRFieldOfView(*m_maximumFOVLeft); | |
92 } | |
93 } | |
94 | |
95 void HMDVRDevice::setFieldOfView(VRFieldOfView* leftFov, VRFieldOfView* rightFov ) | |
96 { | |
97 // TODO: Clamp to maxFOV | |
98 | |
99 if (leftFov) { | |
100 hardwareUnit()->setFieldOfView(0, leftFov); | |
101 } else { | |
102 hardwareUnit()->setFieldOfView(0, m_recommendedFOVLeft); | |
103 } | |
104 | |
105 if (rightFov) { | |
106 hardwareUnit()->setFieldOfView(1, rightFov); | |
107 } else { | |
108 hardwareUnit()->setFieldOfView(1, m_recommendedFOVRight); | |
109 } | |
110 } | |
111 | |
112 DOMRect* HMDVRDevice::getRecommendedEyeRenderRect(const String& whichEye) | |
113 { | |
114 // 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.
| |
115 blink::WebSize size; | |
116 blink::Platform::current()->getVRRenderTargetSize(index(), | |
117 hardwareUnit()->getFieldOfView(HMDVRDevice::VREyeLeft), | |
118 hardwareUnit()->getFieldOfView(HMDVRDevice::VREyeRight), | |
119 &size); | |
120 | |
121 // TODO: We can actually fetch individual eye rects from the Oculus SDK. | |
122 // Plumb that through and expose it here. | |
123 switch (StringToVREye(whichEye)) { | |
124 case VREyeRight: | |
125 return DOMRect::create(size.width / 2.0f, 0, size.width / 2.0f, size.hei ght); | |
126 default: | |
127 return DOMRect::create(0, 0, size.width / 2.0f, size.height); | |
128 } | |
129 } | |
130 | |
131 void HMDVRDevice::trace(Visitor* visitor) | |
132 { | |
133 VRDevice::trace(visitor); | |
134 | |
135 visitor->trace(m_recommendedFOVLeft); | |
136 visitor->trace(m_recommendedFOVRight); | |
137 visitor->trace(m_maximumFOVLeft); | |
138 visitor->trace(m_maximumFOVRight); | |
139 visitor->trace(m_eyeTranslationLeft); | |
140 visitor->trace(m_eyeTranslationRight); | |
141 } | |
142 | |
143 } // namespace blink | |
OLD | NEW |