Skip to content

Commit

Permalink
fix(client_openxr): 🐛 Fix NaN velocities on Pico and Vive (#2702)
Browse files Browse the repository at this point in the history
  • Loading branch information
zmerp authored Feb 13, 2025
1 parent 539b977 commit ba9298c
Showing 1 changed file with 27 additions and 20 deletions.
47 changes: 27 additions & 20 deletions alvr/client_openxr/src/interaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -629,18 +629,19 @@ pub fn get_head_data(
return None;
}

let time_offset_s = future_time
.saturating_sub(time)
.max(Duration::from_millis(1))
.as_secs_f32();

motion.linear_velocity = (crate::from_xr_vec3(predicted_location.pose.position)
- motion.pose.position)
/ time_offset_s;
motion.angular_velocity = (crate::from_xr_quat(predicted_location.pose.orientation)
* motion.pose.orientation.inverse())
.to_scaled_axis()
/ time_offset_s;
let time_offset = future_time.saturating_sub(time);

if !time_offset.is_zero() {
let time_offset_s = time_offset.as_secs_f32();

motion.linear_velocity = (crate::from_xr_vec3(predicted_location.pose.position)
- motion.pose.position)
/ time_offset_s;
motion.angular_velocity = (crate::from_xr_quat(predicted_location.pose.orientation)
* motion.pose.orientation.inverse())
.to_scaled_axis()
/ time_offset_s;
}
}

let last_ipd_m = last_view_params[0]
Expand Down Expand Up @@ -717,14 +718,20 @@ pub fn get_hand_data(
xr::SpaceLocationFlags::ORIENTATION_VALID
| xr::SpaceLocationFlags::POSITION_VALID,
) {
let time_offset_s = future_time.saturating_sub(time).as_secs_f32();
linear_velocity = (crate::from_xr_vec3(future_location.pose.position)
- last_controller_pose.position)
/ time_offset_s;
angular_velocity = (crate::from_xr_quat(future_location.pose.orientation)
* last_controller_pose.orientation.inverse())
.to_scaled_axis()
/ time_offset_s;
let time_offset = future_time.saturating_sub(time);

if !time_offset.is_zero() {
let time_offset_s = time_offset.as_secs_f32();

linear_velocity = (crate::from_xr_vec3(future_location.pose.position)
- last_controller_pose.position)
/ time_offset_s;
angular_velocity =
(crate::from_xr_quat(future_location.pose.orientation)
* last_controller_pose.orientation.inverse())
.to_scaled_axis()
/ time_offset_s;
}
}
}
}
Expand Down

0 comments on commit ba9298c

Please sign in to comment.