feat: /hmd

This commit is contained in:
Nova
2022-09-05 01:22:19 -04:00
parent d23d974e34
commit 2ea2ec0b07
5 changed files with 42 additions and 2 deletions

View File

@@ -2,6 +2,7 @@ use super::eventloop::EventLoop;
use super::scenegraph::Scenegraph;
use crate::nodes::data;
use crate::nodes::field;
use crate::nodes::hmd;
use crate::nodes::input;
use crate::nodes::item;
use crate::nodes::model;
@@ -64,6 +65,7 @@ impl Client {
});
let _ = client.scenegraph.client.set(Arc::downgrade(&client));
let _ = client.root.set(Root::create(&client));
hmd::make_alias(&client);
spatial::create_interface(&client);
field::create_interface(&client);
model::create_interface(&client);

View File

@@ -3,6 +3,7 @@ mod nodes;
mod wayland;
use crate::core::destroy_queue;
use crate::nodes::hmd;
use crate::nodes::model::{MODELS_TO_DROP, MODEL_REGISTRY};
use crate::wayland::Wayland;
@@ -63,6 +64,7 @@ fn main() -> Result<()> {
println!("Stardust ready!");
stereokit.run(
|draw_ctx| {
hmd::frame(&stereokit);
wayland.frame(&stereokit);
destroy_queue::clear();

View File

@@ -30,7 +30,7 @@ pub struct Node {
local_methods: DashMap<String, Method, BuildHasherDefault<FxHasher>>,
destroyable: AtomicBool,
alias: OnceCell<Arc<Alias>>,
pub alias: OnceCell<Arc<Alias>>,
aliases: Registry<Alias>,
pub spatial: OnceCell<Arc<Spatial>>,
@@ -198,7 +198,7 @@ impl Node {
#[allow(dead_code)]
pub struct Alias {
node: Weak<Node>,
original: Weak<Node>,
pub original: Weak<Node>,
local_signals: Vec<&'static str>,
local_methods: Vec<&'static str>,

35
src/nodes/hmd.rs Normal file
View File

@@ -0,0 +1,35 @@
use super::{
core::{Alias, Node},
spatial::Spatial,
};
use crate::core::client::{Client, INTERNAL_CLIENT};
use glam::{vec3, Mat4};
use std::sync::Arc;
use stereokit::StereoKit;
lazy_static::lazy_static! {
static ref HMD: Arc<Node> = create();
}
fn create() -> Arc<Node> {
let node = Arc::new(Node::create(&INTERNAL_CLIENT, "", "hmd", false));
Spatial::add_to(&node, None, Mat4::IDENTITY).unwrap();
node
}
pub fn frame(sk: &StereoKit) {
let spatial = HMD.spatial.get().unwrap();
let hmd_pose = sk.input_head();
*spatial.transform.lock() = Mat4::from_scale_rotation_translation(
vec3(1.0, 1.0, 1.0),
hmd_pose.orientation.into(),
hmd_pose.position.into(),
);
}
pub fn make_alias(client: &Arc<Client>) -> Arc<Node> {
let node = Node::create(client, "", "hmd", false).add_to_scenegraph();
Alias::add_to(&node, &HMD, vec!["getTransform"], vec![], vec![], vec![]);
node
}

View File

@@ -1,3 +1,4 @@
pub mod hmd;
pub mod core;
pub mod data;
pub mod field;