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 "mozilla/StaticPrefs_dom.h"
8 #include "XRNativeOriginLocalFloor.h"
9 #include "VRDisplayClient.h"
11 namespace mozilla::dom
{
13 XRNativeOriginLocalFloor::XRNativeOriginLocalFloor(
14 gfx::VRDisplayClient
* aDisplay
)
15 : mDisplay(aDisplay
), mInitialPositionValid(false) {
18 // To avoid fingerprinting, we offset the floor height.
19 // This should result in the floor being higher than the
20 // real floor in order to avoid breaking content that expects
21 // you to pick objects up off the floor.
22 const double kFloorFuzz
= StaticPrefs::dom_vr_webxr_quantization(); // Meters
23 mFloorRandom
= double(rand()) / double(RAND_MAX
) * kFloorFuzz
;
26 gfx::PointDouble3D
XRNativeOriginLocalFloor::GetPosition() {
27 // Keep returning {0,-fuzz,0} until a position can be found
29 mDisplay
->GetDisplayInfo().GetSittingToStandingTransform();
30 if (!mInitialPositionValid
|| standing
!= mStandingTransform
) {
31 const gfx::VRHMDSensorState
& sensorState
= mDisplay
->GetSensorState();
32 mInitialPosition
.x
= sensorState
.pose
.position
[0];
33 mInitialPosition
.y
= -mFloorRandom
- standing
._42
;
34 mInitialPosition
.z
= sensorState
.pose
.position
[2];
35 mInitialPositionValid
= true;
36 mStandingTransform
= standing
;
38 return mInitialPosition
;
41 } // namespace mozilla::dom