fix: controller
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -7,13 +7,12 @@ use crate::{
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
use color_eyre::eyre::Result;
|
use color_eyre::eyre::Result;
|
||||||
use glam::{Mat4, Vec2};
|
use glam::{Mat4, Vec2, Vec3};
|
||||||
use nanoid::nanoid;
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use stardust_xr::values::Transform;
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use stereokit::{
|
use stereokit::{
|
||||||
ButtonState, Color128, Handed, Model, RenderLayer, StereoKitDraw, StereoKitMultiThread,
|
named_colors::WHITE, ButtonState, Handed, Model, RenderLayer, StereoKitDraw,
|
||||||
|
StereoKitMultiThread,
|
||||||
};
|
};
|
||||||
use tracing::instrument;
|
use tracing::instrument;
|
||||||
|
|
||||||
@@ -33,9 +32,19 @@ pub struct SkController {
|
|||||||
}
|
}
|
||||||
impl SkController {
|
impl SkController {
|
||||||
pub fn new(sk: &impl StereoKitMultiThread, handed: Handed) -> Result<Self> {
|
pub fn new(sk: &impl StereoKitMultiThread, handed: Handed) -> Result<Self> {
|
||||||
let _node = Node::create(&INTERNAL_CLIENT, "", &nanoid!(), false).add_to_scenegraph()?;
|
let _node = Node::create(
|
||||||
|
&INTERNAL_CLIENT,
|
||||||
|
"",
|
||||||
|
if handed == Handed::Left {
|
||||||
|
"controller_left"
|
||||||
|
} else {
|
||||||
|
"controller_right"
|
||||||
|
},
|
||||||
|
false,
|
||||||
|
)
|
||||||
|
.add_to_scenegraph()?;
|
||||||
Spatial::add_to(&_node, None, Mat4::IDENTITY, false)?;
|
Spatial::add_to(&_node, None, Mat4::IDENTITY, false)?;
|
||||||
let model = sk.model_create_mem("cursor", include_bytes!("cursor.glb"), None)?;
|
let model = sk.model_create_mem("cursor.glb", include_bytes!("cursor.glb"), None)?;
|
||||||
let tip = InputType::Tip(Tip::default());
|
let tip = InputType::Tip(Tip::default());
|
||||||
let input = InputMethod::add_to(&_node, tip, None)?;
|
let input = InputMethod::add_to(&_node, tip, None)?;
|
||||||
Ok(SkController {
|
Ok(SkController {
|
||||||
@@ -51,22 +60,17 @@ impl SkController {
|
|||||||
let controller = sk.input_controller(self.handed);
|
let controller = sk.input_controller(self.handed);
|
||||||
*self.input.enabled.lock() = controller.tracked.contains(ButtonState::ACTIVE);
|
*self.input.enabled.lock() = controller.tracked.contains(ButtonState::ACTIVE);
|
||||||
if *self.input.enabled.lock() {
|
if *self.input.enabled.lock() {
|
||||||
|
let world_transform = Mat4::from_rotation_translation(
|
||||||
|
controller.aim.orientation,
|
||||||
|
controller.aim.position,
|
||||||
|
);
|
||||||
sk.model_draw(
|
sk.model_draw(
|
||||||
&self.model,
|
&self.model,
|
||||||
Mat4::from_rotation_translation(
|
world_transform * Mat4::from_scale(Vec3::ONE * 0.02),
|
||||||
controller.aim.orientation,
|
WHITE,
|
||||||
controller.aim.position,
|
RenderLayer::LAYER0,
|
||||||
),
|
|
||||||
Color128::default(),
|
|
||||||
RenderLayer::all(),
|
|
||||||
);
|
|
||||||
self.input.spatial.set_local_transform_components(
|
|
||||||
None,
|
|
||||||
Transform::from_position_rotation(
|
|
||||||
controller.aim.position,
|
|
||||||
controller.aim.orientation,
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
self.input.spatial.set_local_transform(world_transform);
|
||||||
}
|
}
|
||||||
self.datamap.select = controller.trigger;
|
self.datamap.select = controller.trigger;
|
||||||
self.datamap.grab = controller.grip;
|
self.datamap.grab = controller.grip;
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ impl SkHand {
|
|||||||
let sk_hand = sk.input_hand(self.handed);
|
let sk_hand = sk.input_hand(self.handed);
|
||||||
if let InputType::Hand(hand) = &mut *self.input.specialization.lock() {
|
if let InputType::Hand(hand) = &mut *self.input.specialization.lock() {
|
||||||
let controller = sk.input_controller(self.handed);
|
let controller = sk.input_controller(self.handed);
|
||||||
*self.input.enabled.lock() = controller.tracked.contains(ButtonState::INACTIVE)
|
*self.input.enabled.lock() = !controller.tracked.contains(ButtonState::ACTIVE)
|
||||||
&& sk_hand.tracked_state.contains(ButtonState::ACTIVE);
|
&& sk_hand.tracked_state.contains(ButtonState::ACTIVE);
|
||||||
sk.input_hand_visible(self.handed, *self.input.enabled.lock());
|
sk.input_hand_visible(self.handed, *self.input.enabled.lock());
|
||||||
if *self.input.enabled.lock() {
|
if *self.input.enabled.lock() {
|
||||||
|
|||||||
Reference in New Issue
Block a user