reimplement pico view locate quirk

note: stream_tracking should be ported to use the same code
This commit is contained in:
Patrick Nicolas committed 2026-11-04 08:17:37 +01:00
1 parent 32d4fee95e
commit bae0cc3326
3 files changed
+62 -20

No files matched your search

+53
View File
@@ -1841,6 +1841,59 @@ void application::loop()
}
}
std::optional<XrQuaternionf> application::locate_gaze(XrTime time)
{
XrSpaceLocation res{
.type = XR_TYPE_SPACE_LOCATION,
};
if (get_hmd_traits().view_locate)
{
xrLocateSpace(spaces[size_t(xr::spaces::eye_gaze)],
spaces[size_t(xr::spaces::view)],
time,
&res);
}
else
{
XrSpaceLocation tmp{
.type = XR_TYPE_SPACE_LOCATION,
};
auto xr_res = xrLocateSpace(spaces[size_t(xr::spaces::view)],
spaces[size_t(xr::spaces::world)],
time,
&tmp);
if (XR_FAILED(xr_res))
return std::nullopt;
xr_res = xrLocateSpace(spaces[size_t(xr::spaces::eye_gaze)],
spaces[size_t(xr::spaces::world)],
time,
&res);
if (XR_FAILED(xr_res))
return std::nullopt;
glm::quat target_quat(
res.pose.orientation.w,
res.pose.orientation.x,
res.pose.orientation.y,
res.pose.orientation.z);
const glm::quat view_quat(
tmp.pose.orientation.w,
tmp.pose.orientation.x,
tmp.pose.orientation.y,
tmp.pose.orientation.z);
target_quat = glm::conjugate(view_quat) * target_quat;
res.pose.orientation = {
.x = target_quat.x,
.y = target_quat.y,
.z = target_quat.z,
.w = target_quat.w};
res.locationFlags &= tmp.locationFlags;
}
if (res.locationFlags & XR_SPACE_LOCATION_ORIENTATION_VALID_BIT)
return res.pose.orientation;
return std::nullopt;
}
#ifdef __ANDROID__
void application::run()
{
+2
View File
@@ -278,6 +278,8 @@ public:
return std::make_pair(position, orientation);
}
std::optional<XrQuaternionf> locate_gaze(XrTime time);
void run();
static void push_scene(std::shared_ptr<scene>);
+7 -20
View File
@@ -104,29 +104,18 @@ client_foveation::angles target_angles(
}
std::optional<client_foveation::angles> eye_gaze_angles(
XrSpace eye_gaze_space,
XrSpace view_space,
XrTime time,
XrViewStateFlags view_flags,
std::span<const XrView> views)
{
if (not eye_gaze_space or not view_space or views.size() != 2)
return {};
XrSpaceLocation location{
.type = XR_TYPE_SPACE_LOCATION,
};
XrResult res = xrLocateSpace(eye_gaze_space, view_space, time, &location);
if (XR_FAILED(res) or
not(location.locationFlags & XR_SPACE_LOCATION_ORIENTATION_VALID_BIT) or
not(location.locationFlags & XR_SPACE_LOCATION_ORIENTATION_TRACKED_BIT))
return {};
if (not(view_flags & XR_VIEW_STATE_POSITION_VALID_BIT))
return {};
return std::nullopt;
const XrVector2f gaze = yaw_pitch(location.pose.orientation);
auto gaze_quat = application::instance().locate_gaze(time);
if (not gaze_quat)
return std::nullopt;
const XrVector2f gaze = yaw_pitch(*gaze_quat);
return target_angles(-gaze.x, gaze.y, client_foveation::default_convergence_distance, views);
}
@@ -362,9 +351,7 @@ void center::update(std::span<const XrFovf> submitted_fov, std::span<const bool>
}
if (not angles and application::get_eye_gaze_supported())
{
if (auto a = eye_gaze_angles(application::space(xr::spaces::eye_gaze),
view_space,
display_time,
if (auto a = eye_gaze_angles(display_time,
view_flags,
views))
angles = *a;