Skip to content

Commit

Permalink
Expose predict_motion from server_core
Browse files Browse the repository at this point in the history
  • Loading branch information
zmerp committed Dec 15, 2024
1 parent 37693c3 commit b9b678f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 20 deletions.
2 changes: 1 addition & 1 deletion alvr/server_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ mod web_server;

pub use c_api::*;
pub use logging_backend::init_logging;
pub use tracking::HandType;
pub use tracking::{predict_motion, HandType};

use crate::connection::VideoPacket;
use alvr_common::{
Expand Down
46 changes: 27 additions & 19 deletions alvr/server_core/src/tracking/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,32 @@ pub enum HandType {
Right = 1,
}

pub fn predict_motion(
motion: DeviceMotion,
sample_timestamp: Duration,
target_timestamp: Duration,
) -> DeviceMotion {
// 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);

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,
}
}

// todo: Move this struct to Settings and use it for every tracked device
#[derive(Default)]
struct MotionConfig {
Expand Down Expand Up @@ -259,25 +285,7 @@ impl TrackingManager {
) -> 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,
})
Some(predict_motion(motion, sample_timestamp, target_timestamp))
}

pub fn report_hand_skeleton(
Expand Down

0 comments on commit b9b678f

Please sign in to comment.