Skip to content

Commit 16a01a0

Browse files
committed
tracking rewrite (3): server-side prediction (disabled)
1 parent 797c444 commit 16a01a0

File tree

3 files changed

+61
-10
lines changed

3 files changed

+61
-10
lines changed

alvr/server_core/src/lib.rs

+24-6
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,22 @@ impl ServerCoreContext {
258258
.get_device_motion(device_id, sample_timestamp)
259259
}
260260

261+
pub fn get_predicted_device_motion(
262+
&self,
263+
device_id: u64,
264+
sample_timestamp: Duration,
265+
target_timestamp: Duration,
266+
) -> Option<DeviceMotion> {
267+
dbg_server_core!(
268+
"get_predicted_device_motion: dev={device_id} sample_ts={sample_timestamp:?} target_ts={target_timestamp:?}"
269+
);
270+
271+
self.connection_context
272+
.tracking_manager
273+
.read()
274+
.get_predicted_device_motion(device_id, sample_timestamp, target_timestamp)
275+
}
276+
261277
pub fn get_hand_skeleton(
262278
&self,
263279
hand_type: HandType,
@@ -288,12 +304,14 @@ impl ServerCoreContext {
288304
pub fn get_tracker_pose_time_offset(&self) -> Duration {
289305
dbg_server_core!("get_tracker_pose_time_offset");
290306

291-
self.connection_context
292-
.statistics_manager
293-
.read()
294-
.as_ref()
295-
.map(|stats| stats.tracker_pose_time_offset())
296-
.unwrap_or_default()
307+
// self.connection_context
308+
// .statistics_manager
309+
// .read()
310+
// .as_ref()
311+
// .map(|stats| stats.tracker_pose_time_offset())
312+
// .unwrap_or_default()
313+
314+
Duration::from_millis(0)
297315
}
298316

299317
pub fn send_haptics(&self, haptics: Haptics) {

alvr/server_core/src/tracking/mod.rs

+29
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,35 @@ impl TrackingManager {
245245
})
246246
}
247247

248+
pub fn get_predicted_device_motion(
249+
&self,
250+
device_id: u64,
251+
sample_timestamp: Duration,
252+
target_timestamp: Duration,
253+
) -> Option<DeviceMotion> {
254+
let motion = self.get_device_motion(device_id, sample_timestamp)?;
255+
256+
// There is no simple sub for Duration, this is needed to get signed difference
257+
let delta_time_s = target_timestamp
258+
.saturating_sub(sample_timestamp)
259+
.as_secs_f32()
260+
- sample_timestamp
261+
.saturating_sub(target_timestamp)
262+
.as_secs_f32();
263+
264+
let delta_position = motion.linear_velocity * delta_time_s;
265+
let delta_orientation = Quat::from_scaled_axis(motion.angular_velocity * delta_time_s);
266+
267+
Some(DeviceMotion {
268+
pose: Pose {
269+
orientation: delta_orientation * motion.pose.orientation,
270+
position: motion.pose.position + delta_position,
271+
},
272+
linear_velocity: motion.linear_velocity,
273+
angular_velocity: motion.angular_velocity,
274+
})
275+
}
276+
248277
pub fn report_hand_skeleton(
249278
&mut self,
250279
hand_type: HandType,

alvr/server_openvr/src/lib.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -121,17 +121,21 @@ extern "C" fn driver_ready_idle(set_default_chap: bool) {
121121
.unwrap_or(false);
122122

123123
if let Some(context) = &*SERVER_CORE_CONTEXT.read() {
124+
let target_timestamp =
125+
sample_timestamp + context.get_motion_to_photon_latency();
124126
let controllers_pose_time_offset = context.get_tracker_pose_time_offset();
127+
let controllers_timestamp =
128+
target_timestamp.saturating_sub(controllers_pose_time_offset);
125129

126130
let ffi_head_motion = context
127-
.get_device_motion(*HEAD_ID, sample_timestamp)
131+
.get_device_motion(*HEAD_ID, target_timestamp)
128132
.map(|m| tracking::to_ffi_motion(*HEAD_ID, m))
129133
.unwrap_or_else(FfiDeviceMotion::default);
130134
let ffi_left_controller_motion = context
131-
.get_device_motion(*HAND_LEFT_ID, sample_timestamp)
135+
.get_device_motion(*HAND_LEFT_ID, controllers_timestamp)
132136
.map(|m| tracking::to_ffi_motion(*HAND_LEFT_ID, m));
133137
let ffi_right_controller_motion = context
134-
.get_device_motion(*HAND_RIGHT_ID, sample_timestamp)
138+
.get_device_motion(*HAND_RIGHT_ID, controllers_timestamp)
135139
.map(|m| tracking::to_ffi_motion(*HAND_RIGHT_ID, m));
136140

137141
let (
@@ -222,7 +226,7 @@ extern "C" fn driver_ready_idle(set_default_chap: bool) {
222226
// independently. Selection is done by setting deviceIsConnected.
223227
unsafe {
224228
SetTracking(
225-
sample_timestamp.as_nanos() as _,
229+
target_timestamp.as_nanos() as _,
226230
controllers_pose_time_offset.as_secs_f32(),
227231
ffi_head_motion,
228232
ffi_left_hand_data,

0 commit comments

Comments
 (0)