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 } | |
sof
2015/02/24 12:35:28
// namespace
| |
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 == "left") | |
40 return VREyeLeft; | |
41 if (whichEye == "right") | |
42 return VREyeRight; | |
43 return VREyeNone; | |
44 } | |
45 | |
46 void HMDVRDevice::updateFromWebVRDevice(const WebVRDevice& device) | |
47 { | |
48 VRDevice::updateFromWebVRDevice(device); | |
49 const blink::WebVRHMDInfo &hmdInfo = device.hmdInfo; | |
50 | |
51 m_recommendedFOVLeft->setFromWebVRFieldOfView(hmdInfo.recommendedFOVLeft); | |
52 m_recommendedFOVRight->setFromWebVRFieldOfView(hmdInfo.recommendedFOVRight); | |
53 m_maximumFOVLeft->setFromWebVRFieldOfView(hmdInfo.maximumFOVLeft); | |
54 m_maximumFOVRight->setFromWebVRFieldOfView(hmdInfo.maximumFOVRight); | |
55 setDomPoint(m_eyeTranslationLeft, hmdInfo.eyeTranslationLeft); | |
56 setDomPoint(m_eyeTranslationRight, hmdInfo.eyeTranslationRight); | |
57 hardwareUnit()->setFieldOfView(0, m_recommendedFOVLeft); | |
58 hardwareUnit()->setFieldOfView(1, m_recommendedFOVRight); | |
59 } | |
60 | |
61 DOMPoint* HMDVRDevice::getEyeTranslation(const String& whichEye) | |
62 { | |
63 switch (StringToVREye(whichEye)) { | |
64 case VREyeLeft: | |
65 return m_eyeTranslationLeft; | |
66 case VREyeRight: | |
67 return m_eyeTranslationRight; | |
68 default: | |
69 return DOMPoint::create(0, 0, 0, 0); | |
70 } | |
71 } | |
72 | |
73 VRFieldOfView* HMDVRDevice::getCurrentEyeFieldOfView(const String& whichEye) | |
74 { | |
75 return hardwareUnit()->getCurrentEyeFieldOfView(StringToVREye(whichEye)); | |
76 } | |
77 | |
78 VRFieldOfView* HMDVRDevice::getRecommendedEyeFieldOfView(const String& whichEye) | |
79 { | |
80 switch (StringToVREye(whichEye)) { | |
81 case VREyeLeft: | |
82 return new VRFieldOfView(*m_recommendedFOVLeft); | |
83 case VREyeRight: | |
84 return new VRFieldOfView(*m_recommendedFOVRight); | |
85 default: | |
86 return new VRFieldOfView(); | |
87 } | |
88 } | |
89 | |
90 VRFieldOfView* HMDVRDevice::getMaximumEyeFieldOfView(const String& whichEye) | |
91 { | |
92 switch (StringToVREye(whichEye)) { | |
93 case VREyeLeft: | |
94 return new VRFieldOfView(*m_maximumFOVLeft); | |
95 case VREyeRight: | |
96 return new VRFieldOfView(*m_maximumFOVRight); | |
97 default: | |
98 return new VRFieldOfView(); | |
99 } | |
100 } | |
101 | |
102 DOMRect* HMDVRDevice::getRecommendedEyeRenderRect(const String& whichEye) | |
103 { | |
104 // TODO(bajones): This doesn't change unless you reset the FOV. Cache it. | |
sof
2015/02/24 12:35:28
nit: FIXMEs in Blink.
| |
105 blink::WebSize size; | |
106 blink::Platform::current()->getVRRenderTargetSize(index(), | |
107 hardwareUnit()->getFieldOfView(HMDVRDevice::VREyeLeft), | |
108 hardwareUnit()->getFieldOfView(HMDVRDevice::VREyeRight), | |
109 &size); | |
110 | |
111 // TODO(bajones): We can actually fetch individual eye rects from the Oculus SDK. | |
112 // Plumb that through and expose it here. | |
113 switch (StringToVREye(whichEye)) { | |
114 case VREyeLeft: | |
115 return DOMRect::create(0, 0, size.width / 2.0f, size.height); | |
116 case VREyeRight: | |
117 return DOMRect::create(size.width / 2.0f, 0, size.width / 2.0f, size.hei ght); | |
118 default: | |
119 return DOMRect::create(0, 0, 0, 0); | |
120 } | |
121 } | |
122 | |
123 void HMDVRDevice::setFieldOfView(VRFieldOfView* leftFov, VRFieldOfView* rightFov ) | |
124 { | |
125 // TODO(bajones): Clamp to maxFOV | |
126 | |
127 if (leftFov) { | |
128 hardwareUnit()->setFieldOfView(0, leftFov); | |
129 } else { | |
130 hardwareUnit()->setFieldOfView(0, m_recommendedFOVLeft); | |
131 } | |
132 | |
133 if (rightFov) { | |
134 hardwareUnit()->setFieldOfView(1, rightFov); | |
135 } else { | |
136 hardwareUnit()->setFieldOfView(1, m_recommendedFOVRight); | |
137 } | |
138 } | |
139 | |
140 void HMDVRDevice::trace(Visitor* visitor) | |
141 { | |
142 VRDevice::trace(visitor); | |
sof
2015/02/24 12:35:28
nit: preference is to trace the subclasses last.
| |
143 | |
144 visitor->trace(m_recommendedFOVLeft); | |
145 visitor->trace(m_recommendedFOVRight); | |
146 visitor->trace(m_maximumFOVLeft); | |
147 visitor->trace(m_maximumFOVRight); | |
148 visitor->trace(m_eyeTranslationLeft); | |
149 visitor->trace(m_eyeTranslationRight); | |
150 } | |
151 | |
152 } // namespace blink | |
OLD | NEW |