1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "XRNativeOriginLocal.h"
8 #include "VRDisplayClient.h"
10 namespace mozilla::dom
{
12 XRNativeOriginLocal::XRNativeOriginLocal(gfx::VRDisplayClient
* aDisplay
)
13 : mDisplay(aDisplay
), mInitialPositionValid(false) {
17 gfx::PointDouble3D
XRNativeOriginLocal::GetPosition() {
18 // Keep returning {0,0,0} until a position can be found
19 if (!mInitialPositionValid
) {
20 const gfx::VRHMDSensorState
& sensorState
= mDisplay
->GetSensorState();
21 gfx::PointDouble3D origin
;
22 if (sensorState
.flags
& gfx::VRDisplayCapabilityFlags::Cap_Position
||
24 gfx::VRDisplayCapabilityFlags::Cap_PositionEmulated
) {
25 mInitialPosition
.x
= sensorState
.pose
.position
[0];
26 mInitialPosition
.y
= sensorState
.pose
.position
[1];
27 mInitialPosition
.z
= sensorState
.pose
.position
[2];
28 mInitialPositionValid
= true;
31 return mInitialPosition
;
34 } // namespace mozilla::dom