feat(input): mouse pointer
This commit is contained in:
11
src/main.rs
11
src/main.rs
@@ -1,10 +1,12 @@
|
|||||||
mod core;
|
mod core;
|
||||||
mod nodes;
|
mod nodes;
|
||||||
|
mod objects;
|
||||||
mod wayland;
|
mod wayland;
|
||||||
|
|
||||||
use crate::core::destroy_queue;
|
use crate::core::destroy_queue;
|
||||||
use crate::nodes::hmd;
|
|
||||||
use crate::nodes::model::{MODELS_TO_DROP, MODEL_REGISTRY};
|
use crate::nodes::model::{MODELS_TO_DROP, MODEL_REGISTRY};
|
||||||
|
use crate::nodes::{hmd, input};
|
||||||
|
use crate::objects::input::mouse_pointer::MousePointer;
|
||||||
use crate::wayland::Wayland;
|
use crate::wayland::Wayland;
|
||||||
|
|
||||||
use self::core::eventloop::EventLoop;
|
use self::core::eventloop::EventLoop;
|
||||||
@@ -46,6 +48,8 @@ fn main() -> Result<()> {
|
|||||||
.expect("StereoKit failed to initialize");
|
.expect("StereoKit failed to initialize");
|
||||||
println!("Init StereoKit");
|
println!("Init StereoKit");
|
||||||
|
|
||||||
|
let mouse_pointer = cli_args.flatscreen.then(MousePointer::new);
|
||||||
|
|
||||||
if cli_args.flatscreen {
|
if cli_args.flatscreen {
|
||||||
unsafe {
|
unsafe {
|
||||||
stereokit::sys::input_hand_visible(stereokit::sys::handed__handed_left, false as i32);
|
stereokit::sys::input_hand_visible(stereokit::sys::handed__handed_left, false as i32);
|
||||||
@@ -74,6 +78,11 @@ fn main() -> Result<()> {
|
|||||||
}
|
}
|
||||||
MODELS_TO_DROP.lock().clear();
|
MODELS_TO_DROP.lock().clear();
|
||||||
|
|
||||||
|
if let Some(mouse_pointer) = &mouse_pointer {
|
||||||
|
mouse_pointer.update(&stereokit);
|
||||||
|
}
|
||||||
|
input::process_input();
|
||||||
|
|
||||||
wayland.make_context_current();
|
wayland.make_context_current();
|
||||||
},
|
},
|
||||||
|| {
|
|| {
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
pub mod pointer;
|
||||||
|
|
||||||
|
use self::pointer::Pointer;
|
||||||
use super::core::Node;
|
use super::core::Node;
|
||||||
use super::field::Field;
|
use super::field::Field;
|
||||||
use super::spatial::{get_spatial_parent_flex, get_transform_pose_flex, Spatial};
|
use super::spatial::{get_spatial_parent_flex, get_transform_pose_flex, Spatial};
|
||||||
@@ -7,6 +10,7 @@ use crate::core::registry::Registry;
|
|||||||
use anyhow::{anyhow, ensure, Result};
|
use anyhow::{anyhow, ensure, Result};
|
||||||
use glam::Mat4;
|
use glam::Mat4;
|
||||||
use libstardustxr::schemas::input::{InputData, InputDataArgs, InputDataRaw};
|
use libstardustxr::schemas::input::{InputData, InputDataArgs, InputDataRaw};
|
||||||
|
use nanoid::nanoid;
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
use std::sync::atomic::Ordering;
|
use std::sync::atomic::Ordering;
|
||||||
use std::sync::{Arc, Weak};
|
use std::sync::{Arc, Weak};
|
||||||
@@ -14,7 +18,7 @@ use std::sync::{Arc, Weak};
|
|||||||
static INPUT_METHOD_REGISTRY: Registry<InputMethod> = Registry::new();
|
static INPUT_METHOD_REGISTRY: Registry<InputMethod> = Registry::new();
|
||||||
static INPUT_HANDLER_REGISTRY: Registry<InputHandler> = Registry::new();
|
static INPUT_HANDLER_REGISTRY: Registry<InputHandler> = Registry::new();
|
||||||
|
|
||||||
pub trait InputSpecializationTrait {
|
pub trait InputSpecialization: Send + Sync {
|
||||||
fn distance(&self, space: &Arc<Spatial>, field: &Field) -> f32;
|
fn distance(&self, space: &Arc<Spatial>, field: &Field) -> f32;
|
||||||
fn serialize(
|
fn serialize(
|
||||||
&self,
|
&self,
|
||||||
@@ -27,25 +31,36 @@ pub trait InputSpecializationTrait {
|
|||||||
);
|
);
|
||||||
fn serialize_datamap(&self) -> Vec<u8>;
|
fn serialize_datamap(&self) -> Vec<u8>;
|
||||||
}
|
}
|
||||||
enum InputSpecialization {}
|
pub enum InputType {
|
||||||
impl Deref for InputSpecialization {
|
Pointer(Pointer),
|
||||||
type Target = dyn InputSpecializationTrait;
|
}
|
||||||
|
impl Deref for InputType {
|
||||||
|
type Target = dyn InputSpecialization;
|
||||||
fn deref(&self) -> &Self::Target {
|
fn deref(&self) -> &Self::Target {
|
||||||
todo!()
|
match self {
|
||||||
// match self {
|
InputType::Pointer(p) => p,
|
||||||
// Field::Box(field) => field,
|
}
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct InputMethod {
|
pub struct InputMethod {
|
||||||
uid: String,
|
pub uid: String,
|
||||||
pub spatial: Arc<Spatial>,
|
pub spatial: Arc<Spatial>,
|
||||||
specialization: InputSpecialization,
|
pub specialization: InputType,
|
||||||
|
pub captures: Registry<InputHandler>,
|
||||||
}
|
}
|
||||||
impl InputMethod {
|
impl InputMethod {
|
||||||
|
pub fn new(spatial: Arc<Spatial>, specialization: InputType) -> Arc<InputMethod> {
|
||||||
|
let method = InputMethod {
|
||||||
|
uid: nanoid!(),
|
||||||
|
spatial,
|
||||||
|
specialization,
|
||||||
|
captures: Registry::new(),
|
||||||
|
};
|
||||||
|
INPUT_METHOD_REGISTRY.add(method)
|
||||||
|
}
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
fn add_to(node: &Arc<Node>, specialization: InputSpecialization) -> Result<()> {
|
pub fn add_to(node: &Arc<Node>, specialization: InputType) -> Result<()> {
|
||||||
ensure!(
|
ensure!(
|
||||||
node.spatial.get().is_some(),
|
node.spatial.get().is_some(),
|
||||||
"Internal: Node does not have a spatial attached!"
|
"Internal: Node does not have a spatial attached!"
|
||||||
@@ -55,6 +70,7 @@ impl InputMethod {
|
|||||||
uid: node.uid.clone(),
|
uid: node.uid.clone(),
|
||||||
spatial: node.spatial.get().unwrap().clone(),
|
spatial: node.spatial.get().unwrap().clone(),
|
||||||
specialization,
|
specialization,
|
||||||
|
captures: Registry::new(),
|
||||||
};
|
};
|
||||||
let method = INPUT_METHOD_REGISTRY.add(method);
|
let method = INPUT_METHOD_REGISTRY.add(method);
|
||||||
let _ = node.input_method.set(method);
|
let _ = node.input_method.set(method);
|
||||||
@@ -65,6 +81,9 @@ impl InputMethod {
|
|||||||
.upgrade()
|
.upgrade()
|
||||||
.map(|field| self.specialization.distance(&self.spatial, &field))
|
.map(|field| self.specialization.distance(&self.spatial, &field))
|
||||||
}
|
}
|
||||||
|
fn serialize_datamap(&self) -> Vec<u8> {
|
||||||
|
self.specialization.serialize_datamap()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
impl Drop for InputMethod {
|
impl Drop for InputMethod {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
@@ -74,51 +93,44 @@ impl Drop for InputMethod {
|
|||||||
|
|
||||||
pub struct DistanceLink {
|
pub struct DistanceLink {
|
||||||
pub distance: f32,
|
pub distance: f32,
|
||||||
pub method: Weak<InputMethod>,
|
pub method: Arc<InputMethod>,
|
||||||
pub handler: Weak<InputHandler>,
|
pub handler: Arc<InputHandler>,
|
||||||
}
|
}
|
||||||
impl DistanceLink {
|
impl DistanceLink {
|
||||||
fn from(method: &Arc<InputMethod>, handler: &Arc<InputHandler>) -> Option<Self> {
|
fn from(method: Arc<InputMethod>, handler: Arc<InputHandler>) -> Option<Self> {
|
||||||
Some(DistanceLink {
|
Some(DistanceLink {
|
||||||
distance: method.distance(handler)?,
|
distance: method.distance(&handler)?,
|
||||||
method: Arc::downgrade(method),
|
method,
|
||||||
handler: Arc::downgrade(handler),
|
handler,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
fn serialize(&self) -> Option<Vec<u8>> {
|
|
||||||
self.method.upgrade().and_then(|method| {
|
|
||||||
self.handler.upgrade().map(|handler| {
|
|
||||||
let mut fbb = flatbuffers::FlatBufferBuilder::with_capacity(1024);
|
|
||||||
let uid = Some(fbb.create_string(&method.uid));
|
|
||||||
let datamap = Some(fbb.create_vector(&self.serialize_datamap()));
|
|
||||||
|
|
||||||
let (input_type, input_data) = method.specialization.serialize(
|
fn send_input(&self, frame: u64, datamap: &[u8]) {
|
||||||
&mut fbb,
|
self.handler.send_input(frame, self, datamap);
|
||||||
self,
|
|
||||||
Spatial::space_to_space_matrix(Some(&method.spatial), Some(&handler.spatial)),
|
|
||||||
);
|
|
||||||
|
|
||||||
let root = InputData::create(
|
|
||||||
&mut fbb,
|
|
||||||
&InputDataArgs {
|
|
||||||
uid,
|
|
||||||
input_type,
|
|
||||||
input: Some(input_data),
|
|
||||||
distance: self.distance,
|
|
||||||
datamap,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
fbb.finish(root, None);
|
|
||||||
Vec::from(fbb.finished_data())
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
fn serialize_datamap(&self) -> Vec<u8> {
|
fn serialize(&self, datamap: &[u8]) -> Vec<u8> {
|
||||||
if let Some(method) = self.method.upgrade() {
|
let mut fbb = flatbuffers::FlatBufferBuilder::with_capacity(1024);
|
||||||
method.specialization.serialize_datamap()
|
let uid = Some(fbb.create_string(&self.method.uid));
|
||||||
} else {
|
let datamap = Some(fbb.create_vector(datamap));
|
||||||
Default::default()
|
|
||||||
}
|
let (input_type, input_data) = self.method.specialization.serialize(
|
||||||
|
&mut fbb,
|
||||||
|
self,
|
||||||
|
Spatial::space_to_space_matrix(Some(&self.method.spatial), Some(&self.handler.spatial)),
|
||||||
|
);
|
||||||
|
|
||||||
|
let root = InputData::create(
|
||||||
|
&mut fbb,
|
||||||
|
&InputDataArgs {
|
||||||
|
uid,
|
||||||
|
input_type,
|
||||||
|
input: Some(input_data),
|
||||||
|
distance: self.distance,
|
||||||
|
datamap,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
fbb.finish(root, None);
|
||||||
|
Vec::from(fbb.finished_data())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,43 +156,30 @@ impl InputHandler {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn send_input(
|
fn send_input(&self, frame: u64, distance_link: &DistanceLink, datamap: &[u8]) {
|
||||||
&self,
|
let data = distance_link.serialize(datamap);
|
||||||
old_frame: u64,
|
let node = self.node.upgrade().unwrap();
|
||||||
distance_link: DistanceLink,
|
let method = Arc::downgrade(&distance_link.method);
|
||||||
distance_links: Vec<DistanceLink>,
|
let handler = Arc::downgrade(&distance_link.handler);
|
||||||
) {
|
|
||||||
if old_frame < FRAME.load(Ordering::Relaxed) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
match distance_link.serialize() {
|
tokio::spawn(async move {
|
||||||
None => InputHandler::next_input(old_frame, distance_links),
|
let data = node.execute_remote_method("input", data).await;
|
||||||
Some(data) => {
|
if frame == FRAME.load(Ordering::Relaxed) {
|
||||||
let node = self.node.upgrade().unwrap();
|
if let Ok(data) = data {
|
||||||
|
let capture = flexbuffers::Reader::get_root(data.as_slice())
|
||||||
|
.and_then(|data| data.get_bool())
|
||||||
|
.unwrap_or(false);
|
||||||
|
|
||||||
tokio::spawn(async move {
|
if let Some(method) = method.upgrade() {
|
||||||
let data = node.execute_remote_method("input", data).await;
|
if let Some(handler) = handler.upgrade() {
|
||||||
if let Ok(data) = data {
|
if capture {
|
||||||
let capture = flexbuffers::Reader::get_root(data.as_slice())
|
method.captures.add_raw(&handler);
|
||||||
.and_then(|data| data.get_bool())
|
}
|
||||||
.unwrap_or(false);
|
|
||||||
if !distance_links.is_empty() && !capture {
|
|
||||||
InputHandler::next_input(old_frame, distance_links);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
}
|
|
||||||
|
|
||||||
fn next_input(old_frame: u64, distance_links: Vec<DistanceLink>) {
|
|
||||||
let mut distance_links = distance_links;
|
|
||||||
if let Some(distance_link) = distance_links.pop() {
|
|
||||||
if let Some(handler) = distance_link.handler.upgrade() {
|
|
||||||
handler.send_input(old_frame, distance_link, distance_links);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl Drop for InputHandler {
|
impl Drop for InputHandler {
|
||||||
@@ -190,7 +189,7 @@ impl Drop for InputHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_interface(client: &Arc<Client>) {
|
pub fn create_interface(client: &Arc<Client>) {
|
||||||
let node = Node::create(client, "", "data", false);
|
let node = Node::create(client, "", "input", false);
|
||||||
node.add_local_signal("createInputHandler", create_input_handler_flex);
|
node.add_local_signal("createInputHandler", create_input_handler_flex);
|
||||||
node.add_to_scenegraph();
|
node.add_to_scenegraph();
|
||||||
}
|
}
|
||||||
@@ -225,20 +224,28 @@ pub fn create_input_handler_flex(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub fn process_input() {
|
pub fn process_input() {
|
||||||
for method in INPUT_METHOD_REGISTRY.get_valid_contents() {
|
for method in INPUT_METHOD_REGISTRY.get_valid_contents() {
|
||||||
let mut distance_links: Vec<DistanceLink> = Default::default();
|
let mut distance_links: Vec<DistanceLink> = INPUT_HANDLER_REGISTRY
|
||||||
for handler in INPUT_HANDLER_REGISTRY.get_valid_contents() {
|
.get_valid_contents()
|
||||||
if let Some(distance_link) = DistanceLink::from(&method, &handler) {
|
.into_iter()
|
||||||
distance_links.push(distance_link);
|
.filter_map(|handler| DistanceLink::from(method.clone(), handler))
|
||||||
}
|
.collect();
|
||||||
}
|
|
||||||
if distance_links.is_empty() {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
distance_links
|
distance_links
|
||||||
.sort_unstable_by(|a, b| a.distance.partial_cmp(&b.distance).unwrap().reverse());
|
.sort_unstable_by(|a, b| a.distance.partial_cmp(&b.distance).unwrap().reverse());
|
||||||
InputHandler::next_input(FRAME.load(Ordering::Relaxed), distance_links);
|
|
||||||
|
let datamap = method.serialize_datamap();
|
||||||
|
let frame = FRAME.load(Ordering::Relaxed);
|
||||||
|
let captures = method.captures.get_valid_contents();
|
||||||
|
for distance_link in distance_links {
|
||||||
|
distance_link.send_input(frame, &datamap);
|
||||||
|
if captures
|
||||||
|
.iter()
|
||||||
|
.any(|c| Arc::ptr_eq(c, &distance_link.handler))
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
method.captures.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,13 +1,14 @@
|
|||||||
use super::field::{ray_march, Field, Ray, RayMarchResult};
|
use glam::{vec3, Mat4};
|
||||||
use super::input::{DistanceLink, InputSpecializationTrait};
|
|
||||||
use super::spatial::Spatial;
|
|
||||||
use glam::{vec3, vec3a, Mat4};
|
|
||||||
use libstardustxr::schemas::common;
|
|
||||||
use libstardustxr::schemas::input::InputDataRaw;
|
use libstardustxr::schemas::input::InputDataRaw;
|
||||||
use libstardustxr::schemas::input_pointer;
|
use libstardustxr::schemas::input_pointer;
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use crate::nodes::field::{ray_march, Field, Ray, RayMarchResult};
|
||||||
|
use crate::nodes::spatial::Spatial;
|
||||||
|
|
||||||
|
use super::{DistanceLink, InputSpecialization};
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct Pointer {
|
pub struct Pointer {
|
||||||
grab: AtomicBool,
|
grab: AtomicBool,
|
||||||
@@ -34,7 +35,7 @@ impl Pointer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl InputSpecializationTrait for Pointer {
|
impl InputSpecialization for Pointer {
|
||||||
fn distance(&self, space: &Arc<Spatial>, field: &Field) -> f32 {
|
fn distance(&self, space: &Arc<Spatial>, field: &Field) -> f32 {
|
||||||
self.ray_march(space, field).distance
|
self.ray_march(space, field).distance
|
||||||
}
|
}
|
||||||
@@ -47,31 +48,24 @@ impl InputSpecializationTrait for Pointer {
|
|||||||
InputDataRaw,
|
InputDataRaw,
|
||||||
flatbuffers::WIPOffset<flatbuffers::UnionWIPOffset>,
|
flatbuffers::WIPOffset<flatbuffers::UnionWIPOffset>,
|
||||||
) {
|
) {
|
||||||
let origin = local_to_handler_matrix.transform_point3a(vec3a(0_f32, 0_f32, 0_f32));
|
let (_, orientation, origin) = local_to_handler_matrix.to_scale_rotation_translation();
|
||||||
let direction = local_to_handler_matrix.transform_vector3a(vec3a(0_f32, 0_f32, 1_f32));
|
let direction = local_to_handler_matrix.transform_vector3(vec3(0_f32, 0_f32, 1_f32));
|
||||||
let ray_march = self.ray_march(
|
let ray_march = self.ray_march(
|
||||||
&distance_link.method.upgrade().unwrap().spatial,
|
&distance_link.method.spatial,
|
||||||
&distance_link
|
&distance_link.handler.field.upgrade().unwrap(),
|
||||||
.handler
|
|
||||||
.upgrade()
|
|
||||||
.unwrap()
|
|
||||||
.field
|
|
||||||
.upgrade()
|
|
||||||
.unwrap(),
|
|
||||||
);
|
);
|
||||||
let deepest_point = (direction * ray_march.deepest_point_distance) + origin;
|
let deepest_point = (direction * ray_march.deepest_point_distance) + origin;
|
||||||
|
|
||||||
|
let origin: mint::Vector3<f32> = origin.into();
|
||||||
|
let orientation: mint::Quaternion<f32> = orientation.into();
|
||||||
|
let deepest_point: mint::Vector3<f32> = deepest_point.into();
|
||||||
|
|
||||||
let pointer = input_pointer::Pointer::create(
|
let pointer = input_pointer::Pointer::create(
|
||||||
fbb,
|
fbb,
|
||||||
&input_pointer::PointerArgs {
|
&input_pointer::PointerArgs {
|
||||||
origin: Some(&common::Vec3::new(origin.x, origin.y, origin.z)),
|
origin: Some(&origin.into()),
|
||||||
direction: Some(&common::Vec3::new(direction.x, direction.y, direction.z)),
|
orientation: Some(&orientation.into()),
|
||||||
tilt: 0_f32,
|
deepest_point: Some(&deepest_point.into()),
|
||||||
deepest_point: Some(&common::Vec3::new(
|
|
||||||
deepest_point.x,
|
|
||||||
deepest_point.y,
|
|
||||||
deepest_point.z,
|
|
||||||
)),
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
(InputDataRaw::Pointer, pointer.as_union_value())
|
(InputDataRaw::Pointer, pointer.as_union_value())
|
||||||
@@ -3,7 +3,6 @@ pub mod data;
|
|||||||
pub mod field;
|
pub mod field;
|
||||||
pub mod hmd;
|
pub mod hmd;
|
||||||
pub mod input;
|
pub mod input;
|
||||||
pub mod input_pointer;
|
|
||||||
pub mod item;
|
pub mod item;
|
||||||
pub mod model;
|
pub mod model;
|
||||||
pub mod root;
|
pub mod root;
|
||||||
|
|||||||
@@ -16,6 +16,13 @@ pub struct Spatial {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Spatial {
|
impl Spatial {
|
||||||
|
pub fn new(node: Weak<Node>, parent: Option<Arc<Spatial>>, transform: Mat4) -> Arc<Self> {
|
||||||
|
Arc::new(Spatial {
|
||||||
|
node,
|
||||||
|
parent: Mutex::new(parent),
|
||||||
|
transform: Mutex::new(transform),
|
||||||
|
})
|
||||||
|
}
|
||||||
pub fn add_to(
|
pub fn add_to(
|
||||||
node: &Arc<Node>,
|
node: &Arc<Node>,
|
||||||
parent: Option<Arc<Spatial>>,
|
parent: Option<Arc<Spatial>>,
|
||||||
|
|||||||
1
src/objects/input/mod.rs
Normal file
1
src/objects/input/mod.rs
Normal file
@@ -0,0 +1 @@
|
|||||||
|
pub mod mouse_pointer;
|
||||||
34
src/objects/input/mouse_pointer.rs
Normal file
34
src/objects/input/mouse_pointer.rs
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
use crate::nodes::{
|
||||||
|
input::{pointer::Pointer, InputMethod, InputType},
|
||||||
|
spatial::Spatial,
|
||||||
|
};
|
||||||
|
use glam::{vec3, Mat4};
|
||||||
|
use std::sync::{Arc, Weak};
|
||||||
|
use stereokit::{input::Ray, StereoKit};
|
||||||
|
|
||||||
|
pub struct MousePointer {
|
||||||
|
pointer: Arc<InputMethod>,
|
||||||
|
}
|
||||||
|
impl MousePointer {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
MousePointer {
|
||||||
|
pointer: InputMethod::new(
|
||||||
|
Spatial::new(Weak::new(), None, Mat4::IDENTITY),
|
||||||
|
InputType::Pointer(Pointer::default()),
|
||||||
|
),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub fn update(&self, sk: &StereoKit) {
|
||||||
|
if let Some(ray) = Ray::from_mouse(sk.input_mouse()) {
|
||||||
|
self.pointer.spatial.set_local_transform_components(
|
||||||
|
None,
|
||||||
|
Some(ray.pos.into()),
|
||||||
|
Some(glam::Quat::from_rotation_arc(
|
||||||
|
vec3(0.0, 0.0, 1.0),
|
||||||
|
ray.dir.into(),
|
||||||
|
)),
|
||||||
|
None,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
1
src/objects/mod.rs
Normal file
1
src/objects/mod.rs
Normal file
@@ -0,0 +1 @@
|
|||||||
|
pub mod input;
|
||||||
Reference in New Issue
Block a user