Skip to content

Commit

Permalink
Added last orientation. Attempted to fix the issue on pico side, comm…
Browse files Browse the repository at this point in the history
…ented on the issue.
  • Loading branch information
Meister1593 committed Jul 6, 2023
1 parent 00a19bf commit 1dfb433
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
40 changes: 37 additions & 3 deletions alvr/client_openxr/src/interaction.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
use crate::{to_pose, to_quat, to_vec3, Platform};
use alvr_common::{glam::Vec3, *};
use alvr_common::{
glam::{Quat, Vec3},
prelude::warn,
*,
};
use alvr_packets::{ButtonEntry, ButtonValue};
use openxr as xr;
use std::collections::HashMap;
Expand Down Expand Up @@ -460,24 +464,36 @@ pub fn get_hand_motion(
reference_space: &xr::Space,
time: xr::Time,
hand_source: &HandSource,
last_orientation: &mut Quat,
last_position: &mut Vec3,
) -> (Option<DeviceMotion>, Option<[Pose; 26]>) {
// on pico, isActive is true whenever it is tracked or not, not just being active
// this sounds like a spec violation as it should be active even when hands aren't visible, but hand tracking active
if let Some(tracker) = &hand_source.skeleton_tracker {
if let Some(joint_locations) = reference_space
.locate_hand_joints(tracker, time)
.ok()
.flatten()
{
if joint_locations[0]
.location_flags
.contains(xr::SpaceLocationFlags::ORIENTATION_VALID)
{
warn!("last orientation stored");
*last_orientation = to_quat(joint_locations[0].pose.orientation);
}

if joint_locations[0]
.location_flags
.contains(xr::SpaceLocationFlags::POSITION_VALID)
{
warn!("last position stored");
*last_position = to_vec3(joint_locations[0].pose.position);
}

let root_motion = DeviceMotion {
pose: Pose {
orientation: to_quat(joint_locations[0].pose.orientation),
orientation: *last_orientation,
position: *last_position,
},
linear_velocity: Vec3::ZERO,
Expand All @@ -500,20 +516,26 @@ pub fn get_hand_motion(
.is_active(session, xr::Path::NULL)
.unwrap_or(false)
{
warn!("grip action inactive");
return (None, None);
}

let Ok((location, velocity)) = hand_source
.grip_space
.relate(reference_space, time)
else {
warn!("grip space invalid");
return (None, None);
};

if !location
.location_flags
.contains(xr::SpaceLocationFlags::ORIENTATION_VALID)
{
warn!("orientation invalid");
// on pico, considered invalid when hands aren't visible and you're in overlay, this produces "desired" behaviour
// - as hand stays at exactly the same place
// but it's not right and definitely sounds like a bug considering isActive
return (None, None);
}

Expand All @@ -522,16 +544,28 @@ pub fn get_hand_motion(
.contains(xr::SpaceLocationFlags::POSITION_VALID)
{
*last_position = to_vec3(location.pose.position);
// on pico, considered valid when hand aren't visible and you're in app, which instantly jumps hand poses to controllers
warn!("last position valid and velocity is valid");
}

if location
.location_flags
.contains(xr::SpaceLocationFlags::ORIENTATION_VALID)
{
// on pico, considered valid when aren't visible and you're in app, which instantly jumps hand orientations to controllers
*last_orientation = to_quat(location.pose.orientation);
warn!("last orientation valid and velocity is valid");
}

let hand_motion = DeviceMotion {
pose: Pose {
orientation: to_quat(location.pose.orientation),
orientation: *last_orientation,
position: *last_position,
},
linear_velocity: to_vec3(velocity.linear_velocity),
angular_velocity: to_vec3(velocity.angular_velocity),
};
warn!("hand_motion");

(Some(hand_motion), None)
}
Expand Down
4 changes: 4 additions & 0 deletions alvr/client_openxr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ struct StreamingInputContext {
reference_space: Arc<xr::Space>,
last_ipd: f32,
last_hand_positions: [Vec3; 2],
last_hand_orientations: [Quat; 2],
}

#[allow(unused)]
Expand Down Expand Up @@ -296,13 +297,15 @@ fn update_streaming_input(ctx: &mut StreamingInputContext) {
&ctx.reference_space,
tracker_time,
&ctx.hands_context.hand_sources[0],
&mut ctx.last_hand_orientations[0],
&mut ctx.last_hand_positions[0],
);
let (right_hand_motion, right_hand_skeleton) = interaction::get_hand_motion(
&ctx.xr_session,
&ctx.reference_space,
tracker_time,
&ctx.hands_context.hand_sources[1],
&mut ctx.last_hand_orientations[1],
&mut ctx.last_hand_positions[1],
);

Expand Down Expand Up @@ -686,6 +689,7 @@ pub fn entry_point() {
reference_space: Arc::clone(&reference_space),
last_ipd: 0.0,
last_hand_positions: [Vec3::ZERO; 2],
last_hand_orientations: [Quat::IDENTITY; 2],
};

let is_streaming = Arc::clone(&is_streaming);
Expand Down

0 comments on commit 1dfb433

Please sign in to comment.