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

@@ -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;