inputdata
This commit is contained in:
parent
0a2a8bf1ac
commit
f8c43b0a69
1 changed files with 53 additions and 9 deletions
62
src/main.rs
62
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<f32>,
|
||||
}
|
||||
|
||||
struct Root {
|
||||
model: Model,
|
||||
field: BoxField,
|
||||
grabbable: Grabbable,
|
||||
input_handler: HandlerWrapper<InputHandler, InputActionHandler<()>>,
|
||||
color_hover: BaseInputAction<()>,
|
||||
input_handler: HandlerWrapper<InputHandler, InputActionHandler<State>>,
|
||||
color_hover: BaseInputAction<State>,
|
||||
pub hover_color: Vector3<f32>,
|
||||
}
|
||||
|
||||
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<f32>, point: Vector3<f32>) -> 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<f32> {
|
||||
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(
|
||||
|
|
Loading…
Add table
Reference in a new issue