Commit 5f4f1379 authored by Kevin Qin's avatar Kevin Qin Committed by Commit Bot

OpenXR Update XrPose and XrInputSource emulated_position Each Frame

Right now emulated_position not updated by OpenXR. Send back space
tracking info back from xrLocateSpace using emulated_position.

Bug: 969131
Change-Id: I41bda233a9354f5885d2fb6c3af6ad087c4f68e4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1910559
Commit-Queue: Zheng Qin <zheqi@microsoft.com>
Reviewed-by: default avatarAlexander Cooper <alcooper@chromium.org>
Cr-Commit-Position: refs/heads/master@{#717757}
parent 4bb75242
......@@ -507,7 +507,8 @@ XrTime OpenXrApiWrapper::GetPredictedDisplayTime() const {
XrResult OpenXrApiWrapper::GetHeadPose(
base::Optional<gfx::Quaternion>* orientation,
base::Optional<gfx::Point3F>* position) const {
base::Optional<gfx::Point3F>* position,
bool* emulated_position) const {
DCHECK(HasSpace(XR_REFERENCE_SPACE_TYPE_LOCAL));
DCHECK(HasSpace(XR_REFERENCE_SPACE_TYPE_VIEW));
......@@ -518,7 +519,15 @@ XrResult OpenXrApiWrapper::GetHeadPose(
frame_state_.predictedDisplayTime,
&view_from_local));
if (view_from_local.locationFlags & XR_SPACE_LOCATION_ORIENTATION_VALID_BIT) {
// emulated_position indicates when there is a fallback from a fully-tracked
// (i.e. 6DOF) type case to some form of orientation-only type tracking
// (i.e. 3DOF/IMU type sensors)
// Thus we have to make sure orientation is tracked.
// Valid Bit only indicates it's either tracked or emulated, we have to check
// for XR_SPACE_LOCATION_ORIENTATION_TRACKED_BIT to make sure orientation is
// tracked.
if (view_from_local.locationFlags &
XR_SPACE_LOCATION_ORIENTATION_TRACKED_BIT) {
*orientation = gfx::Quaternion(
view_from_local.pose.orientation.x, view_from_local.pose.orientation.y,
view_from_local.pose.orientation.z, view_from_local.pose.orientation.w);
......@@ -534,6 +543,11 @@ XrResult OpenXrApiWrapper::GetHeadPose(
*position = base::nullopt;
}
*emulated_position = true;
if (view_from_local.locationFlags & XR_SPACE_LOCATION_POSITION_TRACKED_BIT) {
*emulated_position = false;
}
return xr_result;
}
......
......@@ -50,7 +50,8 @@ class OpenXrApiWrapper {
XrResult EndFrame();
XrResult GetHeadPose(base::Optional<gfx::Quaternion>* orientation,
base::Optional<gfx::Point3F>* position) const;
base::Optional<gfx::Point3F>* position,
bool* emulated_position) const;
void GetHeadFromEyes(XrView* left, XrView* right) const;
gfx::Size GetViewSize() const;
......
......@@ -299,25 +299,35 @@ XrResult OpenXrController::UpdateInteractionProfile() {
base::Optional<gfx::Transform> OpenXrController::GetMojoFromGripTransform(
XrTime predicted_display_time,
XrSpace local_space) const {
XrSpace local_space,
bool* emulated_position) const {
return GetTransformFromSpaces(predicted_display_time, grip_pose_space_,
local_space);
local_space, emulated_position);
}
base::Optional<gfx::Transform> OpenXrController::GetPointerFromGripTransform(
XrTime predicted_display_time) const {
bool emulated_position;
return GetTransformFromSpaces(predicted_display_time, pointer_pose_space_,
grip_pose_space_);
grip_pose_space_, &emulated_position);
}
base::Optional<gfx::Transform> OpenXrController::GetTransformFromSpaces(
XrTime predicted_display_time,
XrSpace target,
XrSpace origin) const {
XrSpace origin,
bool* emulated_position) const {
XrSpaceLocation location = {XR_TYPE_SPACE_LOCATION};
// emulated_position indicates when there is a fallback from a fully-tracked
// (i.e. 6DOF) type case to some form of orientation-only type tracking
// (i.e. 3DOF/IMU type sensors)
// Thus we have to make sure orientation is tracked.
// Valid Bit only indicates it's either tracked or emulated, we have to check
// for XR_SPACE_LOCATION_ORIENTATION_TRACKED_BIT to make sure orientation is
// tracked.
if (FAILED(
xrLocateSpace(target, origin, predicted_display_time, &location)) ||
!(location.locationFlags & XR_SPACE_LOCATION_ORIENTATION_VALID_BIT) ||
!(location.locationFlags & XR_SPACE_LOCATION_ORIENTATION_TRACKED_BIT) ||
!(location.locationFlags & XR_SPACE_LOCATION_POSITION_VALID_BIT)) {
return base::nullopt;
}
......@@ -332,6 +342,11 @@ base::Optional<gfx::Transform> OpenXrController::GetTransformFromSpaces(
decomp.translate[1] = location.pose.position.y;
decomp.translate[2] = location.pose.position.z;
*emulated_position = true;
if (location.locationFlags & XR_SPACE_LOCATION_POSITION_TRACKED_BIT) {
*emulated_position = false;
}
return gfx::ComposeTransform(decomp);
}
......
......@@ -62,7 +62,8 @@ class OpenXrController {
base::Optional<gfx::Transform> GetMojoFromGripTransform(
XrTime predicted_display_time,
XrSpace local_space) const;
XrSpace local_space,
bool* emulated_position) const;
XrResult UpdateInteractionProfile();
......@@ -102,7 +103,8 @@ class OpenXrController {
base::Optional<gfx::Transform> GetTransformFromSpaces(
XrTime predicted_display_time,
XrSpace target,
XrSpace origin) const;
XrSpace origin,
bool* emulated_position) const;
std::vector<std::string> GetProfiles() const;
......
......@@ -126,8 +126,7 @@ std::vector<mojom::XRInputSourceStatePtr> OpenXRInputHelper::GetInputState(
}
state->mojo_from_input = controller->GetMojoFromGripTransform(
predicted_display_time, local_space_);
state->emulated_position = false;
predicted_display_time, local_space_, &state->emulated_position);
state->primary_input_pressed = trigger_button.value().pressed;
state->primary_input_clicked =
controller_states_[i].primary_button_pressed &&
......
......@@ -43,8 +43,8 @@ mojom::XRFrameDataPtr OpenXrRenderLoop::GetNextFrameData() {
base::Optional<gfx::Quaternion> orientation;
base::Optional<gfx::Point3F> position;
if (XR_SUCCEEDED(openxr_->GetHeadPose(&orientation, &position))) {
if (XR_SUCCEEDED(openxr_->GetHeadPose(
&orientation, &position, &frame_data->pose->emulated_position))) {
if (orientation.has_value())
frame_data->pose->orientation = orientation;
......
......@@ -629,7 +629,9 @@ XrResult xrLocateSpace(XrSpace space,
g_test_helper.LocateSpace(space, &(location->pose));
location->locationFlags = XR_SPACE_LOCATION_ORIENTATION_VALID_BIT |
XR_SPACE_LOCATION_POSITION_VALID_BIT;
XR_SPACE_LOCATION_POSITION_VALID_BIT |
XR_SPACE_LOCATION_ORIENTATION_TRACKED_BIT |
XR_SPACE_LOCATION_POSITION_TRACKED_BIT;
return XR_SUCCESS;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment