changed inputs to work
This commit is contained in:
37
src/input.rs
37
src/input.rs
@@ -8,8 +8,7 @@ type XrPose = (Vec3, Quat);
|
|||||||
#[derive(Clone, Resource)]
|
#[derive(Clone, Resource)]
|
||||||
pub struct XrInput {
|
pub struct XrInput {
|
||||||
pub action_set: xr::ActionSet,
|
pub action_set: xr::ActionSet,
|
||||||
pub right_action: xr::Action<xr::Posef>,
|
pub hand_pose: xr::Action<xr::Posef>,
|
||||||
pub left_action: xr::Action<xr::Posef>,
|
|
||||||
pub right_space: Arc<xr::Space>,
|
pub right_space: Arc<xr::Space>,
|
||||||
pub left_space: Arc<xr::Space>,
|
pub left_space: Arc<xr::Space>,
|
||||||
pub stage: Arc<xr::Space>,
|
pub stage: Arc<xr::Space>,
|
||||||
@@ -21,34 +20,42 @@ impl XrInput {
|
|||||||
session: xr::Session<xr::AnyGraphics>,
|
session: xr::Session<xr::AnyGraphics>,
|
||||||
) -> xr::Result<Self> {
|
) -> xr::Result<Self> {
|
||||||
let action_set = instance.create_action_set("input", "input pose information", 0)?;
|
let action_set = instance.create_action_set("input", "input pose information", 0)?;
|
||||||
let right_action =
|
let left_hand_subaction_path = instance.string_to_path("/user/hand/left").unwrap();
|
||||||
action_set.create_action::<xr::Posef>("right_hand", "Right Hand Controller", &[])?;
|
let right_hand_subaction_path = instance.string_to_path("/user/hand/right").unwrap();
|
||||||
let left_action =
|
let left_hand_grip_pose_path = instance
|
||||||
action_set.create_action::<xr::Posef>("left_hand", "Left Hand Controller", &[])?;
|
.string_to_path("/user/hand/left/input/grip/pose")
|
||||||
|
.unwrap();
|
||||||
|
let right_hand_grip_pose_path = instance
|
||||||
|
.string_to_path("/user/hand/right/input/grip/pose")
|
||||||
|
.unwrap();
|
||||||
|
let hand_pose =
|
||||||
|
action_set.create_action::<xr::Posef>("hand_pose", "Hand Pose", &[left_hand_subaction_path, right_hand_subaction_path])?;
|
||||||
|
/* let left_action =
|
||||||
|
action_set.create_action::<xr::Posef>("left_hand", "Left Hand Controller", &[])?;*/
|
||||||
instance.suggest_interaction_profile_bindings(
|
instance.suggest_interaction_profile_bindings(
|
||||||
instance.string_to_path("/interaction_profiles/khr/simple_controller")?,
|
instance.string_to_path("/interaction_profiles/khr/simple_controller")?,
|
||||||
&[
|
&[
|
||||||
xr::Binding::new(
|
xr::Binding::new(
|
||||||
&right_action,
|
&hand_pose,
|
||||||
instance.string_to_path("/user/hand/right/input/grip/pose")?,
|
right_hand_grip_pose_path,
|
||||||
),
|
),
|
||||||
xr::Binding::new(
|
xr::Binding::new(
|
||||||
&left_action,
|
&hand_pose,
|
||||||
instance.string_to_path("/user/hand/left/input/grip/pose")?,
|
left_hand_grip_pose_path,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
)?;
|
)?;
|
||||||
session.attach_action_sets(&[&action_set])?;
|
|
||||||
let right_space =
|
let right_space =
|
||||||
right_action.create_space(session.clone(), xr::Path::NULL, xr::Posef::IDENTITY)?;
|
hand_pose.create_space(session.clone(), right_hand_subaction_path, xr::Posef::IDENTITY)?;
|
||||||
let left_space =
|
let left_space =
|
||||||
left_action.create_space(session.clone(), xr::Path::NULL, xr::Posef::IDENTITY)?;
|
hand_pose.create_space(session.clone(), left_hand_subaction_path, xr::Posef::IDENTITY)?;
|
||||||
let stage =
|
let stage =
|
||||||
session.create_reference_space(xr::ReferenceSpaceType::STAGE, xr::Posef::IDENTITY)?;
|
session.create_reference_space(xr::ReferenceSpaceType::STAGE, xr::Posef::IDENTITY)?;
|
||||||
|
session.attach_action_sets(&[&action_set])?;
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
action_set,
|
action_set,
|
||||||
right_action,
|
hand_pose,
|
||||||
left_action,
|
|
||||||
right_space: Arc::new(right_space),
|
right_space: Arc::new(right_space),
|
||||||
left_space: Arc::new(left_space),
|
left_space: Arc::new(left_space),
|
||||||
stage: Arc::new(stage),
|
stage: Arc::new(stage),
|
||||||
|
|||||||
@@ -153,6 +153,7 @@ pub fn pre_frame(
|
|||||||
frame_state: Res<XrFrameState>,
|
frame_state: Res<XrFrameState>,
|
||||||
frame_waiter: Res<XrFrameWaiter>,
|
frame_waiter: Res<XrFrameWaiter>,
|
||||||
swapchain: Res<XrSwapchain>,
|
swapchain: Res<XrSwapchain>,
|
||||||
|
xr_input: Res<XrInput>,
|
||||||
mut manual_texture_views: ResMut<ManualTextureViews>,
|
mut manual_texture_views: ResMut<ManualTextureViews>,
|
||||||
){
|
){
|
||||||
while let Some(event) = instance.poll_event(&mut Default::default()).unwrap() {
|
while let Some(event) = instance.poll_event(&mut Default::default()).unwrap() {
|
||||||
@@ -199,6 +200,13 @@ pub fn pre_frame(
|
|||||||
swapchain.begin().unwrap();
|
swapchain.begin().unwrap();
|
||||||
swapchain.update_render_views();
|
swapchain.update_render_views();
|
||||||
let (left, right) = swapchain.get_render_views();
|
let (left, right) = swapchain.get_render_views();
|
||||||
|
let active_action_set = xr::ActiveActionSet::new(&xr_input.action_set);
|
||||||
|
match session.sync_actions(&[active_action_set]) {
|
||||||
|
Err(err) => {
|
||||||
|
eprintln!("{}", err);
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
let format = swapchain.format();
|
let format = swapchain.format();
|
||||||
let left = ManualTextureView {
|
let left = ManualTextureView {
|
||||||
texture_view: left.into(),
|
texture_view: left.into(),
|
||||||
|
|||||||
Reference in New Issue
Block a user