Skip to content

fix: send full view config to openvr #2775

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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion alvr/client_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,8 @@ impl ClientCoreContext {
if let Some(sender) = &mut *self.connection_context.control_sender.lock() {
sender
.send(&ClientControlPacket::ViewsConfig(ViewsConfig {
pose: [views[0].pose, views[1].pose],
fov: [views[0].fov, views[1].fov],
ipd_m: (views[0].pose.position - views[1].pose.position).length(),
}))
.ok();
}
Expand Down
3 changes: 1 addition & 2 deletions alvr/packets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,7 @@ pub enum ServerControlPacket {

#[derive(Serialize, Deserialize, Clone)]
pub struct ViewsConfig {
// Note: the head-to-eye transform is always a translation along the x axis
pub ipd_m: f32,
pub pose: [Pose; 2],
pub fov: [Fov; 2],
}

Expand Down
17 changes: 4 additions & 13 deletions alvr/server_core/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ use crate::{
use alvr_adb::{WiredConnection, WiredConnectionStatus};
use alvr_common::{
con_bail, dbg_connection, debug, error,
glam::{Quat, UVec2, Vec2, Vec3},
glam::{UVec2, Vec2},
info,
parking_lot::{Condvar, Mutex, RwLock},
settings_schema::Switch,
warn, AnyhowToCon, ConResult, ConnectionError, ConnectionState, LifecycleState, Pose,
BUTTON_INFO, CONTROLLER_PROFILE_INFO, QUEST_CONTROLLER_PROFILE_PATH,
warn, AnyhowToCon, ConResult, ConnectionError, ConnectionState, LifecycleState, BUTTON_INFO,
CONTROLLER_PROFILE_INFO, QUEST_CONTROLLER_PROFILE_PATH,
};
use alvr_events::{AdbEvent, ButtonEvent, EventType};
use alvr_packets::{
Expand Down Expand Up @@ -1214,16 +1214,7 @@ fn connection_pipeline(
ClientControlPacket::ViewsConfig(config) => {
ctx.events_sender
.send(ServerCoreEvent::ViewsConfig(ViewsConfig {
local_view_transforms: [
Pose {
position: Vec3::new(-config.ipd_m / 2., 0., 0.),
orientation: Quat::IDENTITY,
},
Pose {
position: Vec3::new(config.ipd_m / 2., 0., 0.),
orientation: Quat::IDENTITY,
},
],
local_view_transforms: config.pose,
fov: config.fov,
}))
.ok();
Expand Down
25 changes: 17 additions & 8 deletions alvr/server_openvr/cpp/alvr_server/HMD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
#include "platform/linux/CEncoder.h"
#endif

const vr::HmdMatrix34_t MATRIX_IDENTITY
= { { { 1.0, 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0, 0.0 }, { 0.0, 0.0, 1.0, 0.0 } } };

vr::HmdRect2_t fov_to_projection(FfiFov fov) {
auto proj_bounds = vr::HmdRect2_t {};
proj_bounds.vTopLeft.v[0] = tanf(fov.left);
Expand All @@ -31,6 +28,17 @@ vr::HmdRect2_t fov_to_projection(FfiFov fov) {
return proj_bounds;
}

vr::HmdMatrix34_t pose_to_transform(FfiPose pose) {
vr::HmdMatrix34_t transform;
HmdMatrix_QuatToMat(
pose.orientation.w, pose.orientation.x, pose.orientation.y, pose.orientation.z, &transform
);
transform.m[0][3] = pose.position[0];
transform.m[1][3] = pose.position[1];
transform.m[2][3] = pose.position[2];
return transform;
}

Hmd::Hmd()
: TrackedDevice(
HEAD_ID,
Expand All @@ -42,11 +50,13 @@ Hmd::Hmd()
Debug("Hmd::constructor");

auto dummy_fov = FfiFov { -1.0, 1.0, 1.0, -1.0 };
auto identity_pose = FfiPose { { 0, 0, 0, 1 }, { 0, 0, 0 } };

this->views_config = FfiViewsConfig {};
this->views_config.ipd_m = 0.063;
this->views_config.fov[0] = dummy_fov;
this->views_config.fov[1] = dummy_fov;
this->views_config.pose[0] = identity_pose;
this->views_config.pose[1] = identity_pose;

m_poseHistory = std::make_shared<PoseHistory>();

Expand Down Expand Up @@ -286,10 +296,9 @@ void Hmd::SetViewsConfig(FfiViewsConfig config) {
// The OpenXR spec defines the HMD position as the midpoint
// between the eyes, so conversion to this is handled by the
// client.
auto left_transform = MATRIX_IDENTITY;
left_transform.m[0][3] = -config.ipd_m / 2.0;
auto right_transform = MATRIX_IDENTITY;
right_transform.m[0][3] = config.ipd_m / 2.0;
auto left_transform = pose_to_transform(config.pose[0]);
auto right_transform = pose_to_transform(config.pose[1]);

vr::VRServerDriverHost()->SetDisplayEyeToHead(object_id, left_transform, right_transform);

auto left_proj = fov_to_projection(config.fov[0]);
Expand Down
7 changes: 6 additions & 1 deletion alvr/server_openvr/cpp/alvr_server/bindings.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ struct FfiQuat {
float w;
};

struct FfiPose {
FfiQuat orientation;
float position[3];
};

struct FfiHandSkeleton {
float jointPositions[31][3];
FfiQuat jointRotations[31];
Expand Down Expand Up @@ -62,7 +67,7 @@ struct FfiOpenvrProperty {

struct FfiViewsConfig {
FfiFov fov[2];
float ipd_m;
FfiPose pose[2];
};

enum FfiButtonType {
Expand Down
17 changes: 14 additions & 3 deletions alvr/server_openvr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,20 @@ fn event_loop(events_receiver: mpsc::Receiver<ServerCoreEvent>) {
down: config.fov[1].down,
},
],
// todo: send full matrix to steamvr
ipd_m: config.local_view_transforms[1].position.x
- config.local_view_transforms[0].position.x,
pose: [
FfiPose {
orientation: tracking::to_ffi_quat(
config.local_view_transforms[0].orientation,
),
position: config.local_view_transforms[0].position.to_array(),
},
FfiPose {
orientation: tracking::to_ffi_quat(
config.local_view_transforms[1].orientation,
),
position: config.local_view_transforms[1].position.to_array(),
},
],
});
},
ServerCoreEvent::Tracking { sample_timestamp } => {
Expand Down
2 changes: 1 addition & 1 deletion alvr/server_openvr/src/tracking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub static BODY_TRACKER_IDS: Lazy<[u64; 8]> = Lazy::new(|| {
]
});

fn to_ffi_quat(quat: Quat) -> FfiQuat {
pub fn to_ffi_quat(quat: Quat) -> FfiQuat {
FfiQuat {
x: quat.x,
y: quat.y,
Expand Down