xr controller update now handles no controller entities

This commit is contained in:
Jay Christy
2023-11-21 13:43:01 -05:00
parent 47a5aa0daa
commit e2b506181a

View File

@@ -1,4 +1,4 @@
use bevy::log::info; use bevy::log::{debug, info};
use bevy::prelude::{ use bevy::prelude::{
Added, BuildChildren, Commands, Component, Entity, Query, Res, Transform, Vec3, With, Without, Added, BuildChildren, Commands, Component, Entity, Query, Res, Transform, Vec3, With, Without,
}; };
@@ -74,16 +74,19 @@ pub fn update_open_xr_controllers(
let left_grip_space = controller.grip_space(Hand::Left); let left_grip_space = controller.grip_space(Hand::Left);
let left_aim_space = controller.aim_space(Hand::Left); let left_aim_space = controller.aim_space(Hand::Left);
let left_postion = left_grip_space.0.pose.position.to_vec3(); let left_postion = left_grip_space.0.pose.position.to_vec3();
let left_aim_pose = left_controller_query.get_single_mut().unwrap().1; let left_aim_pose = left_controller_query.get_single_mut();
match left_aim_pose { match left_aim_pose {
Some(mut pose) => { Ok(left_entity) => match left_entity.1 {
*pose = AimPose(Transform { Some(mut pose) => {
translation: left_aim_space.0.pose.position.to_vec3(), *pose = AimPose(Transform {
rotation: left_aim_space.0.pose.orientation.to_quat(), translation: left_aim_space.0.pose.position.to_vec3(),
scale: Vec3::splat(1.0), rotation: left_aim_space.0.pose.orientation.to_quat(),
}); scale: Vec3::splat(1.0),
} });
None => (), }
None => (),
},
Err(_) => debug!("no left controlelr entity found"),
} }
left_controller_query left_controller_query
@@ -99,16 +102,19 @@ pub fn update_open_xr_controllers(
let right_aim_space = controller.aim_space(Hand::Right); let right_aim_space = controller.aim_space(Hand::Right);
let right_postion = right_grip_space.0.pose.position.to_vec3(); let right_postion = right_grip_space.0.pose.position.to_vec3();
let right_aim_pose = right_controller_query.get_single_mut().unwrap().1; let right_aim_pose = right_controller_query.get_single_mut();
match right_aim_pose { match right_aim_pose {
Some(mut pose) => { Ok(right_entity) => match right_entity.1 {
*pose = AimPose(Transform { Some(mut pose) => {
translation: right_aim_space.0.pose.position.to_vec3(), *pose = AimPose(Transform {
rotation: right_aim_space.0.pose.orientation.to_quat(), translation: right_aim_space.0.pose.position.to_vec3(),
scale: Vec3::splat(1.0), rotation: right_aim_space.0.pose.orientation.to_quat(),
}); scale: Vec3::splat(1.0),
} });
None => (), }
None => (),
},
Err(_) => debug!("no right controlelr entity found"),
} }
right_controller_query right_controller_query