basic color picking

This commit is contained in:
ethan merchant 2024-05-10 01:31:47 -04:00
parent a967f71b61
commit 21e6cedfff

View file

@ -1,6 +1,7 @@
use glam::Vec3;
use stardust_xr_fusion::drawable::{MaterialParameter, Model, ModelPart, ModelPartAspect};
use stardust_xr_fusion::input::InputMethodAspect;
use stardust_xr_fusion::spatial;
use stardust_xr_fusion::{
client::{Client, FrameInfo},
core::values::{rgba_linear, Color, ResourceID},
@ -20,7 +21,7 @@ fn is_grabbing(input: &InputData) -> bool {
match &input.input {
InputDataType::Hand(h) => {
// hands have pinch_strength and grab_strenght data but i figured you should know how to get raw joints
Vec3::from(h.index.tip.position).distance(Vec3::from(h.thumb.tip.position)) < 0.005
Vec3::from(h.index.tip.position).distance(Vec3::from(h.thumb.tip.position)) < 0.0075
}
// pointers and tips (tips are like controllers, pens, spatial cursors) have datamaps full of abstract actions (e.g. select) and raw input info
_ => input.datamap.with_data(|d| d.idx("select").as_f32()) > 0.9,
@ -93,6 +94,18 @@ impl ColorCube {
if is_grabbing(data) {
// call this method when you want to make sure the hand is only trying to interact with this handler
method.request_capture(&self.handler).unwrap();
// let tr = self.field.get_relative_bounding_box(&self.field);
let point_pos = interact_point(data);
let bound_pos = Vec3::new(
point_pos.x.clamp(-0.1, 0.1),
point_pos.y.clamp(-0.1, 0.1),
point_pos.z.clamp(-0.1, 0.1),
);
let pos = (bound_pos * 10.0) + Vec3::new(0.5, 0.5, 0.5);
self.hover_color = rgba_linear!(1.0 - pos.x, pos.y, 1.0 - pos.z, 1.0);
let _ = self.circle.set_local_transform(Transform::from_translation(bound_pos));
}
// then check every frame until it is successfully captured (but it might not be ever)
if data.captured {