From f8c43b0a69099f1f527ae6cc55b567183d380c98 Mon Sep 17 00:00:00 2001 From: spatialfree Date: Fri, 12 Apr 2024 09:04:54 -0400 Subject: [PATCH] inputdata --- src/main.rs | 62 +++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 53 insertions(+), 9 deletions(-) diff --git a/src/main.rs b/src/main.rs index fbcc4d6..63ecd7f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,15 +1,22 @@ use manifest_dir_macros::directory_relative_path; +use mint::{Vector2, Vector3}; use stardust_xr_fusion::{ - client::{Client, RootHandler}, core::values::ResourceID, drawable::Model, fields::BoxField, input::InputHandler, spatial::{SpatialAspect, Transform}, HandlerWrapper + client::{Client, RootHandler}, core::values::ResourceID, drawable::Model, fields::BoxField, input::{InputData, InputDataType, InputHandler}, spatial::{SpatialAspect, Transform}, HandlerWrapper }; use stardust_xr_molecules::{input_action::{BaseInputAction, InputActionHandler}, Grabbable, GrabbableSettings}; +#[derive(Debug, Clone, Copy)] +struct State { + size: Vector2, +} + struct Root { model: Model, field: BoxField, grabbable: Grabbable, - input_handler: HandlerWrapper>, - color_hover: BaseInputAction<()>, + input_handler: HandlerWrapper>, + color_hover: BaseInputAction, + pub hover_color: Vector3, } impl Root { @@ -26,7 +33,7 @@ impl Root { ).unwrap(); let field = - BoxField::create(&model, Transform::none(), mint::Vector3 { x: 0.4, y: 0.4, z: 0.4 }).unwrap(); + BoxField::create(&model, Transform::none(), [0.4; 3]).unwrap(); let grab_settings = GrabbableSettings { zoneable: true, @@ -46,31 +53,68 @@ impl Root { Transform::none(), &field, ).unwrap(), - (), + State { size: [0.1, 0.1].into() }, ).unwrap(); let color_hover = BaseInputAction::new( false, - |d, _| d.distance < 0.0, + Self::hover_action ); + let hover_color = [0.5; 3].into(); + Root { model, field, grabbable, input_handler, color_hover, + hover_color, } } + + fn hover(size: Vector2, point: Vector3) -> bool { + point.x.abs() < size.x && point.y.abs() < size.y + } + fn hover_action(input: &InputData, state: &State) -> bool { + match &input.input { + InputDataType::Pointer(_) => input.distance < 0.0, + InputDataType::Hand(h) => { + Self::hover(state.size, h.index.tip.position) + } + InputDataType::Tip(t) => { + Self::hover(state.size, t.origin) + } + } + } + fn hover_point(&self, input: &InputData) -> Vector3 { + let hover_point = match &input.input { + InputDataType::Pointer(p) => { + [0.0; 3].into() + } + InputDataType::Hand(h) => { + h.index.tip.position + } + InputDataType::Tip(t) => { + t.origin + } + }; + + return hover_point; + } } impl RootHandler for Root { fn frame(&mut self, info: stardust_xr_fusion::client::FrameInfo) { self.grabbable.update(&info).unwrap(); - self.input_handler.lock_wrapped().update_actions( - [&mut self.color_hover], - ); + self.input_handler.lock_wrapped().update_actions([ + &mut self.color_hover, + ]); + + // for input_data in self + // .color_hover + // .started if self.color_hover.currently_acting.is_empty() { self.model.set_local_transform(