feat: use dbus for hmd

This commit is contained in:
Nova
2024-06-24 19:26:01 -04:00
parent f5e8156400
commit 5be25da46f
8 changed files with 549 additions and 61 deletions

28
src/objects/hmd.rs Normal file
View File

@@ -0,0 +1,28 @@
use crate::{
core::client::INTERNAL_CLIENT,
nodes::{
spatial::{Spatial, EXPORTED_SPATIALS},
Node,
},
};
use glam::Mat4;
use std::sync::Arc;
use zbus::{interface, Connection};
pub struct HMD;
impl HMD {
pub async fn create(connection: &Connection) -> Arc<Spatial> {
let node = Arc::new(Node::generate(&INTERNAL_CLIENT, false));
let spatial = Spatial::add_to(&node, None, Mat4::IDENTITY, false);
EXPORTED_SPATIALS.lock().insert(0, node);
connection.object_server().at("/hmd", Self).await.unwrap();
spatial
}
}
#[interface(name = "org.stardustxr.SpatialRef")]
impl HMD {
#[zbus(property)]
pub fn uid(&self) -> u64 {
0
}
}

View File

@@ -1,18 +1,23 @@
use crate::nodes::spatial::Spatial;
use glam::{vec3, Mat4};
use input::{
eye_pointer::EyePointer, mouse_pointer::MousePointer, sk_controller::SkController,
sk_hand::SkHand,
};
use play_space::PlaySpace;
use std::sync::Arc;
use stereokit_rust::{
sk::{DisplayMode, MainThreadToken, Sk},
system::{Handed, World},
system::{Handed, Input, World},
util::Device,
};
pub mod hmd;
pub mod input;
pub mod play_space;
pub struct ServerObjects {
hmd: Arc<Spatial>,
mouse_pointer: Option<MousePointer>,
hands: Option<(SkHand, SkHand)>,
controllers: Option<(SkController, SkController)>,
@@ -20,8 +25,9 @@ pub struct ServerObjects {
play_space: Option<PlaySpace>,
}
impl ServerObjects {
pub fn new(intentional_flatscreen: bool, sk: &Sk) -> ServerObjects {
pub fn new(intentional_flatscreen: bool, sk: &Sk, hmd: Arc<Spatial>) -> ServerObjects {
ServerObjects {
hmd,
mouse_pointer: intentional_flatscreen
.then(MousePointer::new)
.transpose()
@@ -50,6 +56,14 @@ impl ServerObjects {
}
pub fn update(&mut self, sk: &Sk, token: &MainThreadToken) {
let hmd_pose = Input::get_head();
self.hmd
.set_local_transform(Mat4::from_scale_rotation_translation(
vec3(1.0, 1.0, 1.0),
hmd_pose.orientation.into(),
hmd_pose.position.into(),
));
if let Some(mouse_pointer) = self.mouse_pointer.as_mut() {
mouse_pointer.update();
}