(
time: Res<Time>,
keyboard: Res<ButtonInput<KeyCode>>,
mut transform_query: Query<(&mut Transform, &mut FlyingCamera, &mut Projection)>,
mut motion_evr: EventReader<Mo
| 110 | } |
| 111 | |
| 112 | pub fn player_controller( |
| 113 | time: Res<Time>, |
| 114 | keyboard: Res<ButtonInput<KeyCode>>, |
| 115 | mut transform_query: Query<(&mut Transform, &mut FlyingCamera, &mut Projection)>, |
| 116 | mut motion_evr: EventReader<MouseMotion>, |
| 117 | mut scroll_evr: EventReader<MouseWheel>, |
| 118 | mut exit: EventWriter<AppExit>, |
| 119 | ) { |
| 120 | const MOUSE_SENSITIVITY: f32 = 0.001; |
| 121 | const CAMERA_SPEED: f32 = 10.0; |
| 122 | |
| 123 | let w = keyboard.pressed(KeyCode::KeyW); |
| 124 | let s = keyboard.pressed(KeyCode::KeyS); |
| 125 | let a = keyboard.pressed(KeyCode::KeyA); |
| 126 | let d = keyboard.pressed(KeyCode::KeyD); |
| 127 | let up = keyboard.pressed(KeyCode::ShiftLeft); |
| 128 | let down = keyboard.pressed(KeyCode::ControlLeft); |
| 129 | let escape = keyboard.just_pressed(KeyCode::Escape); |
| 130 | let zero = keyboard.just_pressed(KeyCode::Digit0); |
| 131 | let change_projection = keyboard.just_pressed(KeyCode::Tab); |
| 132 | |
| 133 | for (mut transform, mut looking_at, projection) in &mut transform_query { |
| 134 | let p = projection.into_inner(); |
| 135 | for ev in scroll_evr.read() { |
| 136 | let change_value = ev.y |
| 137 | * match ev.unit { |
| 138 | bevy::input::mouse::MouseScrollUnit::Line => 0.03, |
| 139 | bevy::input::mouse::MouseScrollUnit::Pixel => 0.01, |
| 140 | }; |
| 141 | match p { |
| 142 | Projection::Orthographic(orthographic_projection) => { |
| 143 | orthographic_projection.scale += 0.01*change_value |
| 144 | } |
| 145 | Projection::Perspective(perspective_projection) => { |
| 146 | perspective_projection.fov += change_value |
| 147 | } |
| 148 | } |
| 149 | } |
| 150 | if change_projection { |
| 151 | match p { |
| 152 | Projection::Perspective(_) => { |
| 153 | *p = Projection::Orthographic(OrthographicProjection{scale:0.005, ..OrthographicProjection::default_3d()}) |
| 154 | } |
| 155 | Projection::Orthographic(_) => *p = Projection::Perspective(default()), |
| 156 | } |
| 157 | } |
| 158 | for ev in motion_evr.read() { |
| 159 | // TODO: Add support for axis input reassignment |
| 160 | looking_at.pitch -= MOUSE_SENSITIVITY * ev.delta.y; |
| 161 | looking_at.yaw -= MOUSE_SENSITIVITY * ev.delta.x; |
| 162 | } |
| 163 | if zero { |
| 164 | looking_at.pitch = -0.5 * f32::consts::PI; |
| 165 | looking_at.yaw = 0.0; |
| 166 | } |
| 167 | transform.rotation = |
| 168 | Quat::from_euler(EulerRot::YXZ, looking_at.yaw, looking_at.pitch, 0.0); |
| 169 | let mut shift = Vec3::ZERO; |
nothing calls this directly
no outgoing calls
no test coverage detected