feat: play space

This commit is contained in:
Nova
2023-07-16 10:42:35 -07:00
parent 89741508e3
commit f63ca4a25b
6 changed files with 71 additions and 8 deletions

View File

@@ -1 +1,2 @@
pub mod input;
pub mod play_space;

50
src/objects/play_space.rs Normal file
View File

@@ -0,0 +1,50 @@
use std::sync::Arc;
use color_eyre::eyre::Result;
use glam::Mat4;
use mint::Vector2;
use nanoid::nanoid;
use serde::{Serialize, Deserialize};
use stereokit::StereoKitMultiThread;
use crate::{nodes::{spatial::Spatial, data::{PulseReceiver, Mask}, Node, fields::{Field, r#box::BoxField}}, core::client::INTERNAL_CLIENT};
#[derive(Debug, Deserialize, Serialize)]
struct PlaySpaceMap {
play_space: (),
size: Vector2<f32>,
}
impl Default for PlaySpaceMap {
fn default() -> Self {
Self { play_space: (), size: [0.0; 2].into() }
}
}
pub struct PlaySpace {
_node: Arc<Node>,
spatial: Arc<Spatial>,
field: Arc<Field>,
_pulse_rx: Arc<PulseReceiver>,
}
impl PlaySpace {
pub fn new() -> Result<Self> {
let node = Node::create(&INTERNAL_CLIENT, "", &nanoid!(), false).add_to_scenegraph()?;
let spatial = Spatial::add_to(&node, None, Mat4::IDENTITY, false)?;
let field = BoxField::add_to(&node, [0.0;3].into())?;
let pulse_rx = PulseReceiver::add_to(&node, field.clone(), Mask::from_struct::<PlaySpaceMap>())?;
Ok(PlaySpace {
_node: node,
spatial,
field,
_pulse_rx: pulse_rx,
})
}
pub fn update(&self, sk: &impl StereoKitMultiThread) {
let pose = sk.world_get_bounds_pose();
self.spatial.set_local_transform(Mat4::from_rotation_translation(pose.orientation, pose.position));
let Field::Box(box_field) = self.field.as_ref() else {return};
box_field.set_size([sk.world_get_bounds_size().x, 0.0, sk.world_get_bounds_size().y].into());
}
}