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