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::{
|
use bevy::prelude::{
|
||||||
Color, Gizmos, GlobalTransform, Plugin, Quat, Query, Res, Transform, Update, Vec2, Vec3, With,
|
Color, Gizmos, GlobalTransform, Plugin, Quat, Query, Res, Transform, Update, Vec2, Vec3, With,
|
||||||
Without,
|
Without,
|
||||||
};
|
};
|
||||||
use bevy::log::info;
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
input::XrInput,
|
input::XrInput,
|
||||||
@@ -103,11 +103,22 @@ pub fn draw_gizmos(
|
|||||||
Err(_) => info!("too many tracking roots"),
|
Err(_) => info!("too many tracking roots"),
|
||||||
}
|
}
|
||||||
//draw the hands
|
//draw the hands
|
||||||
let left_transform = left_controller_query.get_single().unwrap().0;
|
//left
|
||||||
let right_transform = right_controller_query.get_single().unwrap().0;
|
let left_transform = left_controller_query.get_single();
|
||||||
|
match left_transform {
|
||||||
draw_hand_gizmo(&mut gizmos, &controller, Hand::Right, right_transform);
|
Ok(left_entity) => {
|
||||||
draw_hand_gizmo(&mut gizmos, &controller, Hand::Left, left_transform);
|
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(
|
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];
|
let mut data: [[Transform; 26]; 2] = [[Transform::default(); 26]; 2];
|
||||||
for (subaction_path, hand) in [
|
for (subaction_path, hand) in [
|
||||||
(
|
(
|
||||||
@@ -189,21 +192,36 @@ pub(crate) fn update_hand_skeleton_from_emulated(
|
|||||||
.state(&session, subaction_path)
|
.state(&session, subaction_path)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.current_state;
|
.current_state;
|
||||||
data[match hand {
|
match hand {
|
||||||
Hand::Left => 0,
|
Hand::Left => match left {
|
||||||
Hand::Right => 1,
|
Ok(hand_transform) => {
|
||||||
}] = update_hand_bones_emulated(
|
data[0] = update_hand_bones_emulated(
|
||||||
match hand {
|
hand_transform,
|
||||||
Hand::Left => left_controller_transform.single(),
|
hand,
|
||||||
Hand::Right => right_controller_transform.single(),
|
thumb_curl,
|
||||||
|
index_curl,
|
||||||
|
middle_curl,
|
||||||
|
ring_curl,
|
||||||
|
little_curl,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Err(_) => debug!("no left controller transform for hand bone emulation"),
|
||||||
},
|
},
|
||||||
hand,
|
Hand::Right => match right {
|
||||||
thumb_curl,
|
Ok(hand_transform) => {
|
||||||
index_curl,
|
data[1] = update_hand_bones_emulated(
|
||||||
middle_curl,
|
hand_transform,
|
||||||
ring_curl,
|
hand,
|
||||||
little_curl,
|
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();
|
let trt = tracking_root_transform.single();
|
||||||
for (mut t, bone, hand, status, mut radius) in bones.iter_mut() {
|
for (mut t, bone, hand, status, mut radius) in bones.iter_mut() {
|
||||||
|
|||||||
@@ -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,49 +74,67 @@ 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;
|
//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 {
|
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"),
|
||||||
|
}
|
||||||
|
//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
|
//get right controller
|
||||||
let right_grip_space = controller.grip_space(Hand::Right);
|
let right_grip_space = controller.grip_space(Hand::Right);
|
||||||
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"),
|
||||||
|
}
|
||||||
|
//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