Merge pull request #46 from ForTehLose/optionalControllers
Optional controllers
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
use bevy::log::{debug, info};
|
||||
use bevy::prelude::{
|
||||
Color, Gizmos, GlobalTransform, Plugin, Quat, Query, Res, Transform, Update, Vec2, Vec3, With,
|
||||
Without,
|
||||
};
|
||||
use bevy::log::info;
|
||||
|
||||
use crate::{
|
||||
input::XrInput,
|
||||
@@ -103,11 +103,22 @@ pub fn draw_gizmos(
|
||||
Err(_) => info!("too many tracking roots"),
|
||||
}
|
||||
//draw the hands
|
||||
let left_transform = left_controller_query.get_single().unwrap().0;
|
||||
let right_transform = right_controller_query.get_single().unwrap().0;
|
||||
|
||||
draw_hand_gizmo(&mut gizmos, &controller, Hand::Right, right_transform);
|
||||
draw_hand_gizmo(&mut gizmos, &controller, Hand::Left, left_transform);
|
||||
//left
|
||||
let left_transform = left_controller_query.get_single();
|
||||
match left_transform {
|
||||
Ok(left_entity) => {
|
||||
draw_hand_gizmo(&mut gizmos, &controller, Hand::Left, left_entity.0);
|
||||
}
|
||||
Err(_) => debug!("no left controller entity for debug gizmos"),
|
||||
}
|
||||
//right
|
||||
let right_transform = right_controller_query.get_single();
|
||||
match right_transform {
|
||||
Ok(right_entity) => {
|
||||
draw_hand_gizmo(&mut gizmos, &controller, Hand::Right, right_entity.0);
|
||||
}
|
||||
Err(_) => debug!("no right controller entity for debug gizmos"),
|
||||
}
|
||||
}
|
||||
|
||||
fn draw_hand_gizmo(
|
||||
|
||||
@@ -144,6 +144,9 @@ pub(crate) fn update_hand_skeleton_from_emulated(
|
||||
),
|
||||
>,
|
||||
) {
|
||||
//get the transforms outside the loop
|
||||
let left = left_controller_transform.get_single();
|
||||
let right = right_controller_transform.get_single();
|
||||
let mut data: [[Transform; 26]; 2] = [[Transform::default(); 26]; 2];
|
||||
for (subaction_path, hand) in [
|
||||
(
|
||||
@@ -189,14 +192,11 @@ pub(crate) fn update_hand_skeleton_from_emulated(
|
||||
.state(&session, subaction_path)
|
||||
.unwrap()
|
||||
.current_state;
|
||||
data[match hand {
|
||||
Hand::Left => 0,
|
||||
Hand::Right => 1,
|
||||
}] = update_hand_bones_emulated(
|
||||
match hand {
|
||||
Hand::Left => left_controller_transform.single(),
|
||||
Hand::Right => right_controller_transform.single(),
|
||||
},
|
||||
Hand::Left => match left {
|
||||
Ok(hand_transform) => {
|
||||
data[0] = update_hand_bones_emulated(
|
||||
hand_transform,
|
||||
hand,
|
||||
thumb_curl,
|
||||
index_curl,
|
||||
@@ -205,6 +205,24 @@ pub(crate) fn update_hand_skeleton_from_emulated(
|
||||
little_curl,
|
||||
);
|
||||
}
|
||||
Err(_) => debug!("no left controller transform for hand bone emulation"),
|
||||
},
|
||||
Hand::Right => match right {
|
||||
Ok(hand_transform) => {
|
||||
data[1] = update_hand_bones_emulated(
|
||||
hand_transform,
|
||||
hand,
|
||||
thumb_curl,
|
||||
index_curl,
|
||||
middle_curl,
|
||||
ring_curl,
|
||||
little_curl,
|
||||
);
|
||||
}
|
||||
Err(_) => debug!("no right controller transform for hand bone emulation"),
|
||||
},
|
||||
}
|
||||
}
|
||||
let trt = tracking_root_transform.single();
|
||||
for (mut t, bone, hand, status, mut radius) in bones.iter_mut() {
|
||||
match status {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use bevy::log::info;
|
||||
use bevy::log::{debug, info};
|
||||
use bevy::prelude::{
|
||||
Added, BuildChildren, Commands, Component, Entity, Query, Res, Transform, Vec3, With, Without,
|
||||
};
|
||||
@@ -74,8 +74,11 @@ pub fn update_open_xr_controllers(
|
||||
let left_grip_space = controller.grip_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_aim_pose = left_controller_query.get_single_mut().unwrap().1;
|
||||
//TODO figure out how to not get the entity multiple times
|
||||
let left_aim_pose = left_controller_query.get_single_mut();
|
||||
//set aim pose
|
||||
match left_aim_pose {
|
||||
Ok(left_entity) => match left_entity.1 {
|
||||
Some(mut pose) => {
|
||||
*pose = AimPose(Transform {
|
||||
translation: left_aim_space.0.pose.position.to_vec3(),
|
||||
@@ -84,23 +87,31 @@ pub fn update_open_xr_controllers(
|
||||
});
|
||||
}
|
||||
None => (),
|
||||
},
|
||||
Err(_) => debug!("no left controlelr entity found"),
|
||||
}
|
||||
//set translation
|
||||
let left_translation = left_controller_query.get_single_mut();
|
||||
match left_translation {
|
||||
Ok(mut left_entity) => left_entity.0.translation = left_postion,
|
||||
Err(_) => (),
|
||||
}
|
||||
//set rotation
|
||||
let left_rotataion = left_controller_query.get_single_mut();
|
||||
match left_rotataion {
|
||||
Ok(mut left_entity) => {
|
||||
left_entity.0.rotation = left_grip_space.0.pose.orientation.to_quat()
|
||||
}
|
||||
Err(_) => (),
|
||||
}
|
||||
|
||||
left_controller_query
|
||||
.get_single_mut()
|
||||
.unwrap()
|
||||
.0
|
||||
.translation = left_postion;
|
||||
|
||||
left_controller_query.get_single_mut().unwrap().0.rotation =
|
||||
left_grip_space.0.pose.orientation.to_quat();
|
||||
//get right controller
|
||||
let right_grip_space = controller.grip_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_aim_pose = right_controller_query.get_single_mut().unwrap().1;
|
||||
let right_aim_pose = right_controller_query.get_single_mut();
|
||||
match right_aim_pose {
|
||||
Ok(right_entity) => match right_entity.1 {
|
||||
Some(mut pose) => {
|
||||
*pose = AimPose(Transform {
|
||||
translation: right_aim_space.0.pose.position.to_vec3(),
|
||||
@@ -109,14 +120,21 @@ pub fn update_open_xr_controllers(
|
||||
});
|
||||
}
|
||||
None => (),
|
||||
},
|
||||
Err(_) => debug!("no right controlelr entity found"),
|
||||
}
|
||||
//set translation
|
||||
let right_translation = right_controller_query.get_single_mut();
|
||||
match right_translation {
|
||||
Ok(mut right_entity) => right_entity.0.translation = right_postion,
|
||||
Err(_) => (),
|
||||
}
|
||||
//set rotation
|
||||
let right_rotataion = right_controller_query.get_single_mut();
|
||||
match right_rotataion {
|
||||
Ok(mut right_entity) => {
|
||||
right_entity.0.rotation = right_grip_space.0.pose.orientation.to_quat()
|
||||
}
|
||||
Err(_) => (),
|
||||
}
|
||||
|
||||
right_controller_query
|
||||
.get_single_mut()
|
||||
.unwrap()
|
||||
.0
|
||||
.translation = right_postion;
|
||||
|
||||
right_controller_query.get_single_mut().unwrap().0.rotation =
|
||||
right_grip_space.0.pose.orientation.to_quat();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user