first attempt at locomotion
This commit is contained in:
@@ -1,7 +1,11 @@
|
||||
use bevy::diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin};
|
||||
use bevy::prelude::*;
|
||||
use bevy::transform::components::Transform;
|
||||
use bevy_openxr::input::XrInput;
|
||||
use bevy_openxr::resources::{XrFrameState, XrInstance, XrSession};
|
||||
use bevy_openxr::xr_input::debug_gizmos::OpenXrDebugRenderer;
|
||||
use bevy_openxr::xr_input::oculus_touch::OculusController;
|
||||
use bevy_openxr::xr_input::{Hand, TrackingRoot};
|
||||
use bevy_openxr::DefaultXrPlugins;
|
||||
|
||||
fn main() {
|
||||
@@ -14,6 +18,7 @@ fn main() {
|
||||
.add_plugins(LogDiagnosticsPlugin::default())
|
||||
.add_plugins(FrameTimeDiagnosticsPlugin)
|
||||
.add_systems(Startup, setup)
|
||||
.add_systems(Update, proto_locomotion)
|
||||
.run();
|
||||
}
|
||||
|
||||
@@ -36,6 +41,13 @@ fn setup(
|
||||
transform: Transform::from_xyz(0.0, 0.5, 0.0),
|
||||
..default()
|
||||
});
|
||||
// cube
|
||||
commands.spawn(PbrBundle {
|
||||
mesh: meshes.add(Mesh::from(shape::Cube { size: 0.1 })),
|
||||
material: materials.add(Color::rgb(0.8, 0.0, 0.0).into()),
|
||||
transform: Transform::from_xyz(0.0, 0.5, 1.0),
|
||||
..default()
|
||||
});
|
||||
// light
|
||||
commands.spawn(PointLightBundle {
|
||||
point_light: PointLight {
|
||||
@@ -52,3 +64,29 @@ fn setup(
|
||||
..default()
|
||||
},));
|
||||
}
|
||||
|
||||
fn proto_locomotion(
|
||||
time: Res<Time>,
|
||||
mut tracking_root_query: Query<(&mut Transform, With<TrackingRoot>)>,
|
||||
oculus_controller: Res<OculusController>,
|
||||
frame_state: Res<XrFrameState>,
|
||||
xr_input: Res<XrInput>,
|
||||
instance: Res<XrInstance>,
|
||||
session: Res<XrSession>,
|
||||
) {
|
||||
//lock frame
|
||||
let frame_state = *frame_state.lock().unwrap();
|
||||
//get controller
|
||||
let controller = oculus_controller.get_ref(&instance, &session, &frame_state, &xr_input);
|
||||
let root = tracking_root_query.get_single_mut();
|
||||
match root {
|
||||
Ok(mut position) => {
|
||||
//do work here?
|
||||
let stick = controller.thumbstick(Hand::Left);
|
||||
let input = Vec3::new(stick.x, 0.0, -stick.y);
|
||||
let speed = 1.0;
|
||||
position.0.translation += input * speed * time.delta_seconds()
|
||||
}
|
||||
Err(_) => info!("too many tracking roots"),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user