Only enable mouse movement when pressed in scene_viewer (#4405)
# Objective - Only move the camera when explicitly wanted, otherwise the camera goes crazy if the cursor isn't already in the middle of the window when it opens. ## Solution - Check if the Left mouse button is pressed before updating the mouse delta - Input is configurable
This commit is contained in:
parent
ac29cbecf7
commit
28d0a40028
@ -18,6 +18,8 @@ fn main() {
|
|||||||
println!(
|
println!(
|
||||||
"
|
"
|
||||||
Controls:
|
Controls:
|
||||||
|
MOUSE - Move camera orientation
|
||||||
|
LClick - Enable mouse movement
|
||||||
WSAD - forward/back/strafe left/right
|
WSAD - forward/back/strafe left/right
|
||||||
LShift - 'run'
|
LShift - 'run'
|
||||||
E - up
|
E - up
|
||||||
@ -356,6 +358,7 @@ struct CameraController {
|
|||||||
pub key_up: KeyCode,
|
pub key_up: KeyCode,
|
||||||
pub key_down: KeyCode,
|
pub key_down: KeyCode,
|
||||||
pub key_run: KeyCode,
|
pub key_run: KeyCode,
|
||||||
|
pub key_enable_mouse: MouseButton,
|
||||||
pub walk_speed: f32,
|
pub walk_speed: f32,
|
||||||
pub run_speed: f32,
|
pub run_speed: f32,
|
||||||
pub friction: f32,
|
pub friction: f32,
|
||||||
@ -377,6 +380,7 @@ impl Default for CameraController {
|
|||||||
key_up: KeyCode::E,
|
key_up: KeyCode::E,
|
||||||
key_down: KeyCode::Q,
|
key_down: KeyCode::Q,
|
||||||
key_run: KeyCode::LShift,
|
key_run: KeyCode::LShift,
|
||||||
|
key_enable_mouse: MouseButton::Left,
|
||||||
walk_speed: 5.0,
|
walk_speed: 5.0,
|
||||||
run_speed: 15.0,
|
run_speed: 15.0,
|
||||||
friction: 0.5,
|
friction: 0.5,
|
||||||
@ -390,17 +394,12 @@ impl Default for CameraController {
|
|||||||
fn camera_controller(
|
fn camera_controller(
|
||||||
time: Res<Time>,
|
time: Res<Time>,
|
||||||
mut mouse_events: EventReader<MouseMotion>,
|
mut mouse_events: EventReader<MouseMotion>,
|
||||||
|
mouse_button_input: Res<Input<MouseButton>>,
|
||||||
key_input: Res<Input<KeyCode>>,
|
key_input: Res<Input<KeyCode>>,
|
||||||
mut query: Query<(&mut Transform, &mut CameraController), With<Camera>>,
|
mut query: Query<(&mut Transform, &mut CameraController), With<Camera>>,
|
||||||
) {
|
) {
|
||||||
let dt = time.delta_seconds();
|
let dt = time.delta_seconds();
|
||||||
|
|
||||||
// Handle mouse input
|
|
||||||
let mut mouse_delta = Vec2::ZERO;
|
|
||||||
for mouse_event in mouse_events.iter() {
|
|
||||||
mouse_delta += mouse_event.delta;
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Ok((mut transform, mut options)) = query.get_single_mut() {
|
if let Ok((mut transform, mut options)) = query.get_single_mut() {
|
||||||
if !options.initialized {
|
if !options.initialized {
|
||||||
let (_roll, yaw, pitch) = transform.rotation.to_euler(EulerRot::ZYX);
|
let (_roll, yaw, pitch) = transform.rotation.to_euler(EulerRot::ZYX);
|
||||||
@ -454,6 +453,14 @@ fn camera_controller(
|
|||||||
+ options.velocity.y * dt * Vec3::Y
|
+ options.velocity.y * dt * Vec3::Y
|
||||||
+ options.velocity.z * dt * forward;
|
+ options.velocity.z * dt * forward;
|
||||||
|
|
||||||
|
// Handle mouse input
|
||||||
|
let mut mouse_delta = Vec2::ZERO;
|
||||||
|
if mouse_button_input.pressed(options.key_enable_mouse) {
|
||||||
|
for mouse_event in mouse_events.iter() {
|
||||||
|
mouse_delta += mouse_event.delta;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if mouse_delta != Vec2::ZERO {
|
if mouse_delta != Vec2::ZERO {
|
||||||
// Apply look update
|
// Apply look update
|
||||||
let (pitch, yaw) = (
|
let (pitch, yaw) = (
|
||||||
|
Loading…
Reference in New Issue
Block a user