make the hex launcher grabbable

This commit is contained in:
Nicola Guerrera
2023-03-02 16:03:29 +01:00
committed by Nova
parent 2824e2dc2a
commit 1c90ed98cf
3 changed files with 53 additions and 58 deletions

View File

@@ -1,5 +1,4 @@
use color_eyre::eyre::Result;
use glam::Quat;
use manifest_dir_macros::directory_relative_path;
use mint::Vector3;
use protostar::{
@@ -8,8 +7,6 @@ use protostar::{
};
use stardust_xr_fusion::{
client::{Client, FrameInfo, RootHandler},
core::values::Transform,
drawable::{Alignment, Bounds, Text, TextFit, TextStyle},
spatial::Spatial,
};
@@ -72,7 +69,6 @@ impl RootHandler for AppGrid {
}
}
struct App {
_text: Text,
_desktop_file: DesktopFile,
protostar: ProtoStar,
}
@@ -82,33 +78,11 @@ impl App {
parent: &Spatial,
position: impl Into<Vector3<f32>>,
desktop_file: DesktopFile,
//style: TextStyle,
) -> Option<Self> {
let position = position.into();
let style = TextStyle {
character_height: APP_SIZE * 0.1,
bounds: Some(Bounds {
bounds: [APP_SIZE; 2].into(),
fit: TextFit::Wrap,
bounds_align: Alignment::XCenter | Alignment::YCenter,
}),
text_align: Alignment::XCenter | Alignment::YCenter,
..Default::default()
};
let protostar =
ProtoStar::create_from_desktop_file(parent, position, desktop_file.clone()).ok()?;
let text = Text::create(
protostar.content_parent(),
Transform::from_position_rotation(
[0.0, 0.0, APP_SIZE / 2.0],
Quat::from_rotation_y(3.14),
),
desktop_file.name.as_deref().unwrap_or("Unknown"),
style,
)
.unwrap();
Some(App {
_text: text,
_desktop_file: desktop_file,
protostar,
})

View File

@@ -10,10 +10,11 @@ use stardust_xr_fusion::{
client::{Client, FrameInfo, RootHandler},
core::values::Transform,
drawable::{MaterialParameter, Model, ResourceID},
fields::BoxField,
node::NodeError,
spatial::Spatial,
};
use stardust_xr_molecules::touch_plane::TouchPlane;
use stardust_xr_molecules::{touch_plane::TouchPlane, GrabData, Grabbable};
use std::f32::consts::PI;
use tween::TweenTime;
@@ -110,7 +111,7 @@ impl AppHexGrid {
};
apps.push(
App::new(
client.get_root(),
button.grabbable.content_parent(),
hex.get_coords(),
desktop_files.pop().unwrap(),
)
@@ -126,7 +127,7 @@ impl AppHexGrid {
}
impl RootHandler for AppHexGrid {
fn frame(&mut self, info: FrameInfo) {
self.button.touch_plane.update();
self.button.frame(info);
if self.button.touch_plane.touch_started() {
let color = [0.0, 1.0, 0.0, 1.0];
self.button
@@ -176,30 +177,48 @@ impl RootHandler for App {
struct Button {
touch_plane: TouchPlane,
grabbable: Grabbable,
model: Model,
}
impl Button {
fn new(client: &Client) -> Result<Self, NodeError> {
let touch_plane = TouchPlane::new(
let field = BoxField::create(client.get_root(), Transform::default(), [APP_SIZE; 3])?;
let grabbable = Grabbable::new(
client.get_root(),
Transform::default(),
&field,
GrabData {
max_distance: 0.01,
..Default::default()
},
)?;
field.set_spatial_parent(grabbable.content_parent())?;
let touch_plane = TouchPlane::new(
grabbable.content_parent(),
Transform::default(),
[(APP_SIZE + PADDING) / 2.0; 2],
(APP_SIZE + PADDING) / 2.0,
)?;
let model = Model::create(
client.get_root(),
grabbable.content_parent(),
Transform::from_rotation_scale(
Quat::from_rotation_x(PI / 2.0) * Quat::from_rotation_y(PI),
[0.03, 0.03, 0.03],
),
&ResourceID::new_namespaced("protostar", "hexagon/hexagon"),
)?;
model
.set_material_parameter(1, "color", MaterialParameter::Color([0.0, 0.0, 1.0, 1.0]))
.unwrap();
Ok(Button { touch_plane, model })
model.set_material_parameter(1, "color", MaterialParameter::Color([0.0, 0.0, 1.0, 1.0]))?;
Ok(Button {
touch_plane,
grabbable,
model,
})
}
}
impl RootHandler for Button {
fn frame(&mut self, _info: FrameInfo) {}
fn frame(&mut self, info: FrameInfo) {
self.touch_plane.update();
self.grabbable.update(&info);
}
}