moved more stuff around
This commit is contained in:
@@ -11,8 +11,8 @@ use bevy_openxr::xr_input::debug_gizmos::OpenXrDebugRenderer;
|
|||||||
use bevy_openxr::xr_input::oculus_touch::OculusController;
|
use bevy_openxr::xr_input::oculus_touch::OculusController;
|
||||||
use bevy_openxr::xr_input::prototype_locomotion::{proto_locomotion, PrototypeLocomotionConfig};
|
use bevy_openxr::xr_input::prototype_locomotion::{proto_locomotion, PrototypeLocomotionConfig};
|
||||||
use bevy_openxr::xr_input::trackers::{
|
use bevy_openxr::xr_input::trackers::{
|
||||||
OpenXRController, OpenXRLeftController, OpenXRRightController, OpenXRTracker,
|
adopt_open_xr_trackers, OpenXRController, OpenXRLeftController, OpenXRRightController,
|
||||||
OpenXRTrackingRoot, adopt_open_xr_trackers,
|
OpenXRTracker, OpenXRTrackingRoot,
|
||||||
};
|
};
|
||||||
use bevy_openxr::xr_input::{Hand, QuatConv, Vec3Conv};
|
use bevy_openxr::xr_input::{Hand, QuatConv, Vec3Conv};
|
||||||
use bevy_openxr::DefaultXrPlugins;
|
use bevy_openxr::DefaultXrPlugins;
|
||||||
@@ -29,8 +29,6 @@ fn main() {
|
|||||||
.add_systems(Startup, setup)
|
.add_systems(Startup, setup)
|
||||||
.add_systems(Update, proto_locomotion)
|
.add_systems(Update, proto_locomotion)
|
||||||
.add_systems(Startup, spawn_controllers_example)
|
.add_systems(Startup, spawn_controllers_example)
|
||||||
.add_systems(Update, update_open_xr_controllers)
|
|
||||||
.add_systems(Update, adopt_open_xr_trackers)
|
|
||||||
.insert_resource(PrototypeLocomotionConfig::default())
|
.insert_resource(PrototypeLocomotionConfig::default())
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
@@ -85,12 +83,6 @@ fn spawn_controllers_example(mut commands: Commands) {
|
|||||||
OpenXRController,
|
OpenXRController,
|
||||||
OpenXRTracker,
|
OpenXRTracker,
|
||||||
SpatialBundle::default(),
|
SpatialBundle::default(),
|
||||||
// PbrBundle {
|
|
||||||
// mesh: meshes.add(Mesh::from(shape::Cube { size: 0.1 })),
|
|
||||||
// material: materials.add(Color::RED.into()),
|
|
||||||
// transform: Transform::from_xyz(0.0, 0.5, 1.0),
|
|
||||||
// ..default()
|
|
||||||
// },
|
|
||||||
));
|
));
|
||||||
//right hand
|
//right hand
|
||||||
commands.spawn((
|
commands.spawn((
|
||||||
@@ -98,59 +90,5 @@ fn spawn_controllers_example(mut commands: Commands) {
|
|||||||
OpenXRController,
|
OpenXRController,
|
||||||
OpenXRTracker,
|
OpenXRTracker,
|
||||||
SpatialBundle::default(),
|
SpatialBundle::default(),
|
||||||
// PbrBundle {
|
|
||||||
// mesh: meshes.add(Mesh::from(shape::Cube { size: 0.1 })),
|
|
||||||
// material: materials.add(Color::BLUE.into()),
|
|
||||||
// transform: Transform::from_xyz(0.0, 0.5, 1.0),
|
|
||||||
// ..default()
|
|
||||||
// },
|
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_open_xr_controllers(
|
|
||||||
oculus_controller: Res<OculusController>,
|
|
||||||
mut left_controller_query: Query<(
|
|
||||||
&mut Transform,
|
|
||||||
With<OpenXRLeftController>,
|
|
||||||
Without<OpenXRRightController>,
|
|
||||||
)>,
|
|
||||||
mut right_controller_query: Query<(
|
|
||||||
&mut Transform,
|
|
||||||
With<OpenXRRightController>,
|
|
||||||
Without<OpenXRLeftController>,
|
|
||||||
)>,
|
|
||||||
frame_state: Res<XrFrameState>,
|
|
||||||
instance: Res<XrInstance>,
|
|
||||||
xr_input: Res<XrInput>,
|
|
||||||
session: Res<XrSession>,
|
|
||||||
) {
|
|
||||||
//lock dat frame?
|
|
||||||
let frame_state = *frame_state.lock().unwrap();
|
|
||||||
//get controller
|
|
||||||
let controller = oculus_controller.get_ref(&instance, &session, &frame_state, &xr_input);
|
|
||||||
//get left controller
|
|
||||||
let left = controller.grip_space(Hand::Left);
|
|
||||||
let left_postion = left.0.pose.position.to_vec3();
|
|
||||||
|
|
||||||
left_controller_query
|
|
||||||
.get_single_mut()
|
|
||||||
.unwrap()
|
|
||||||
.0
|
|
||||||
.translation = left_postion;
|
|
||||||
|
|
||||||
left_controller_query.get_single_mut().unwrap().0.rotation = left.0.pose.orientation.to_quat();
|
|
||||||
//get right controller
|
|
||||||
let right = controller.grip_space(Hand::Right);
|
|
||||||
let right_postion = right.0.pose.position.to_vec3();
|
|
||||||
|
|
||||||
right_controller_query
|
|
||||||
.get_single_mut()
|
|
||||||
.unwrap()
|
|
||||||
.0
|
|
||||||
.translation = right_postion;
|
|
||||||
|
|
||||||
right_controller_query.get_single_mut().unwrap().0.rotation =
|
|
||||||
right.0.pose.orientation.to_quat();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
pub mod controllers;
|
pub mod controllers;
|
||||||
pub mod debug_gizmos;
|
pub mod debug_gizmos;
|
||||||
pub mod oculus_touch;
|
pub mod oculus_touch;
|
||||||
pub mod trackers;
|
|
||||||
pub mod prototype_locomotion;
|
pub mod prototype_locomotion;
|
||||||
|
pub mod trackers;
|
||||||
pub mod xr_camera;
|
pub mod xr_camera;
|
||||||
|
|
||||||
use crate::resources::XrSession;
|
use crate::resources::XrSession;
|
||||||
@@ -13,14 +13,17 @@ use crate::xr_input::xr_camera::{xr_camera_head_sync, Eye, XRProjection, XrCamer
|
|||||||
use bevy::app::{App, PostUpdate, Startup};
|
use bevy::app::{App, PostUpdate, Startup};
|
||||||
use bevy::log::warn;
|
use bevy::log::warn;
|
||||||
use bevy::prelude::{
|
use bevy::prelude::{
|
||||||
default, Commands, Component, Plugin, PreUpdate, Quat, Res, SpatialBundle, Vec3,
|
default, Commands, Component, Plugin, PreUpdate, Quat, Res, SpatialBundle, Update, Vec3,
|
||||||
};
|
};
|
||||||
use bevy::prelude::{BuildChildren, IntoSystemConfigs};
|
use bevy::prelude::{BuildChildren, IntoSystemConfigs};
|
||||||
use bevy::render::camera::CameraProjectionPlugin;
|
use bevy::render::camera::CameraProjectionPlugin;
|
||||||
use bevy::render::view::{update_frusta, VisibilitySystems};
|
use bevy::render::view::{update_frusta, VisibilitySystems};
|
||||||
use bevy::transform::{TransformBundle, TransformSystem};
|
use bevy::transform::{TransformBundle, TransformSystem};
|
||||||
|
|
||||||
use self::trackers::{OpenXRLeftEye, OpenXRRightEye, OpenXRTrackingRoot};
|
use self::trackers::{
|
||||||
|
adopt_open_xr_trackers, update_open_xr_controllers, OpenXRLeftEye, OpenXRRightEye,
|
||||||
|
OpenXRTrackingRoot,
|
||||||
|
};
|
||||||
|
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
pub struct OpenXrInput {
|
pub struct OpenXrInput {
|
||||||
@@ -46,8 +49,12 @@ impl Plugin for OpenXrInput {
|
|||||||
app.add_systems(Startup, setup_oculus_controller);
|
app.add_systems(Startup, setup_oculus_controller);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//adopt any new trackers
|
||||||
|
app.add_systems(PreUpdate, adopt_open_xr_trackers);
|
||||||
app.add_systems(PreUpdate, action_set_system);
|
app.add_systems(PreUpdate, action_set_system);
|
||||||
app.add_systems(PreUpdate, xr_camera_head_sync.after(xr_begin_frame));
|
app.add_systems(PreUpdate, xr_camera_head_sync.after(xr_begin_frame));
|
||||||
|
//update controller trackers
|
||||||
|
app.add_systems(Update, update_open_xr_controllers);
|
||||||
app.add_systems(
|
app.add_systems(
|
||||||
PostUpdate,
|
PostUpdate,
|
||||||
update_frusta::<XRProjection>
|
update_frusta::<XRProjection>
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
use bevy::prelude::{info, Added, BuildChildren, Commands, Component, Entity, Query, With};
|
use bevy::prelude::{info, Added, BuildChildren, Commands, Component, Entity, Query, With, Res, Transform, Without};
|
||||||
|
|
||||||
|
use crate::{resources::{XrFrameState, XrInstance, XrSession}, input::XrInput};
|
||||||
|
|
||||||
|
use super::{oculus_touch::OculusController, Hand, Vec3Conv, QuatConv};
|
||||||
|
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
pub struct OpenXRTrackingRoot;
|
pub struct OpenXRTrackingRoot;
|
||||||
@@ -34,3 +38,50 @@ pub fn adopt_open_xr_trackers(
|
|||||||
Err(_) => info!("root isnt spawned yet?"),
|
Err(_) => info!("root isnt spawned yet?"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn update_open_xr_controllers(
|
||||||
|
oculus_controller: Res<OculusController>,
|
||||||
|
mut left_controller_query: Query<(
|
||||||
|
&mut Transform,
|
||||||
|
With<OpenXRLeftController>,
|
||||||
|
Without<OpenXRRightController>,
|
||||||
|
)>,
|
||||||
|
mut right_controller_query: Query<(
|
||||||
|
&mut Transform,
|
||||||
|
With<OpenXRRightController>,
|
||||||
|
Without<OpenXRLeftController>,
|
||||||
|
)>,
|
||||||
|
frame_state: Res<XrFrameState>,
|
||||||
|
instance: Res<XrInstance>,
|
||||||
|
xr_input: Res<XrInput>,
|
||||||
|
session: Res<XrSession>,
|
||||||
|
) {
|
||||||
|
//lock dat frame?
|
||||||
|
let frame_state = *frame_state.lock().unwrap();
|
||||||
|
//get controller
|
||||||
|
let controller = oculus_controller.get_ref(&instance, &session, &frame_state, &xr_input);
|
||||||
|
//get left controller
|
||||||
|
let left = controller.grip_space(Hand::Left);
|
||||||
|
let left_postion = left.0.pose.position.to_vec3();
|
||||||
|
|
||||||
|
left_controller_query
|
||||||
|
.get_single_mut()
|
||||||
|
.unwrap()
|
||||||
|
.0
|
||||||
|
.translation = left_postion;
|
||||||
|
|
||||||
|
left_controller_query.get_single_mut().unwrap().0.rotation = left.0.pose.orientation.to_quat();
|
||||||
|
//get right controller
|
||||||
|
let right = controller.grip_space(Hand::Right);
|
||||||
|
let right_postion = right.0.pose.position.to_vec3();
|
||||||
|
|
||||||
|
right_controller_query
|
||||||
|
.get_single_mut()
|
||||||
|
.unwrap()
|
||||||
|
.0
|
||||||
|
.translation = right_postion;
|
||||||
|
|
||||||
|
right_controller_query.get_single_mut().unwrap().0.rotation =
|
||||||
|
right.0.pose.orientation.to_quat();
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user