XRNativeOriginLocal.cpp (1272B)
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 "XRNativeOriginLocal.h" 8 9 #include "VRDisplayClient.h" 10 11 namespace mozilla::dom { 12 13 XRNativeOriginLocal::XRNativeOriginLocal(gfx::VRDisplayClient* aDisplay) 14 : mDisplay(aDisplay), mInitialPositionValid(false) { 15 MOZ_ASSERT(aDisplay); 16 } 17 18 gfx::PointDouble3D XRNativeOriginLocal::GetPosition() { 19 // Keep returning {0,0,0} until a position can be found 20 if (!mInitialPositionValid) { 21 const gfx::VRHMDSensorState& sensorState = mDisplay->GetSensorState(); 22 gfx::PointDouble3D origin; 23 if (sensorState.flags & gfx::VRDisplayCapabilityFlags::Cap_Position || 24 sensorState.flags & 25 gfx::VRDisplayCapabilityFlags::Cap_PositionEmulated) { 26 mInitialPosition.x = sensorState.pose.position[0]; 27 mInitialPosition.y = sensorState.pose.position[1]; 28 mInitialPosition.z = sensorState.pose.position[2]; 29 mInitialPositionValid = true; 30 } 31 } 32 return mInitialPosition; 33 } 34 35 } // namespace mozilla::dom