Bug 1880216 - Migrate Fenix docs into Sphinx. r=owlish,geckoview-reviewers,android...
[gecko.git] / dom / vr / XRNativeOriginLocal.cpp
blobfd4590cf9ec81022c22df59352906ea4830bf8c2
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) {
14 MOZ_ASSERT(aDisplay);
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 ||
23 sensorState.flags &
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