Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tracking rewrite #2481

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions alvr/server_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,22 @@ impl ServerCoreContext {
.get_device_motion(device_id, sample_timestamp)
}

pub fn get_predicted_device_motion(
&self,
device_id: u64,
sample_timestamp: Duration,
target_timestamp: Duration,
) -> Option<DeviceMotion> {
dbg_server_core!(
"get_predicted_device_motion: dev={device_id} sample_ts={sample_timestamp:?} target_ts={target_timestamp:?}"
);

self.connection_context
.tracking_manager
.read()
.get_predicted_device_motion(device_id, sample_timestamp, target_timestamp)
}

pub fn get_hand_skeleton(
&self,
hand_type: HandType,
Expand Down Expand Up @@ -288,12 +304,14 @@ impl ServerCoreContext {
pub fn get_tracker_pose_time_offset(&self) -> Duration {
dbg_server_core!("get_tracker_pose_time_offset");

self.connection_context
.statistics_manager
.read()
.as_ref()
.map(|stats| stats.tracker_pose_time_offset())
.unwrap_or_default()
// self.connection_context
// .statistics_manager
// .read()
// .as_ref()
// .map(|stats| stats.tracker_pose_time_offset())
// .unwrap_or_default()

Duration::from_millis(0)
}

pub fn send_haptics(&self, haptics: Haptics) {
Expand Down
29 changes: 29 additions & 0 deletions alvr/server_core/src/tracking/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,35 @@ impl TrackingManager {
})
}

pub fn get_predicted_device_motion(
&self,
device_id: u64,
sample_timestamp: Duration,
target_timestamp: Duration,
) -> Option<DeviceMotion> {
let motion = self.get_device_motion(device_id, sample_timestamp)?;

// There is no simple sub for Duration, this is needed to get signed difference
let delta_time_s = target_timestamp
.saturating_sub(sample_timestamp)
.as_secs_f32()
- sample_timestamp
.saturating_sub(target_timestamp)
.as_secs_f32();

let delta_position = motion.linear_velocity * delta_time_s;
let delta_orientation = Quat::from_scaled_axis(motion.angular_velocity * delta_time_s);

Some(DeviceMotion {
pose: Pose {
orientation: delta_orientation * motion.pose.orientation,
position: motion.pose.position + delta_position,
},
linear_velocity: motion.linear_velocity,
angular_velocity: motion.angular_velocity,
})
}

pub fn report_hand_skeleton(
&mut self,
hand_type: HandType,
Expand Down
12 changes: 8 additions & 4 deletions alvr/server_openvr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,21 @@ extern "C" fn driver_ready_idle(set_default_chap: bool) {
.unwrap_or(false);

if let Some(context) = &*SERVER_CORE_CONTEXT.read() {
let target_timestamp =
sample_timestamp + context.get_motion_to_photon_latency();
let controllers_pose_time_offset = context.get_tracker_pose_time_offset();
let controllers_timestamp =
target_timestamp.saturating_sub(controllers_pose_time_offset);

let ffi_head_motion = context
.get_device_motion(*HEAD_ID, sample_timestamp)
.get_device_motion(*HEAD_ID, target_timestamp)
.map(|m| tracking::to_ffi_motion(*HEAD_ID, m))
.unwrap_or_else(FfiDeviceMotion::default);
let ffi_left_controller_motion = context
.get_device_motion(*HAND_LEFT_ID, sample_timestamp)
.get_device_motion(*HAND_LEFT_ID, controllers_timestamp)
.map(|m| tracking::to_ffi_motion(*HAND_LEFT_ID, m));
let ffi_right_controller_motion = context
.get_device_motion(*HAND_RIGHT_ID, sample_timestamp)
.get_device_motion(*HAND_RIGHT_ID, controllers_timestamp)
.map(|m| tracking::to_ffi_motion(*HAND_RIGHT_ID, m));

let (
Expand Down Expand Up @@ -222,7 +226,7 @@ extern "C" fn driver_ready_idle(set_default_chap: bool) {
// independently. Selection is done by setting deviceIsConnected.
unsafe {
SetTracking(
sample_timestamp.as_nanos() as _,
target_timestamp.as_nanos() as _,
controllers_pose_time_offset.as_secs_f32(),
ffi_head_motion,
ffi_left_hand_data,
Expand Down
Loading