2023-01-24 20:52:54 -06:00
|
|
|
use glam::{Vec3, Mat4, EulerRot, Quat};
|
2023-01-24 20:36:24 -06:00
|
|
|
use shipyard::{Component, View, ViewMut, IntoIter, UniqueView};
|
2023-01-24 20:52:54 -06:00
|
|
|
use crate::{transform::Transform, input::Inputs, settings::GameSettings};
|
2023-01-24 20:36:24 -06:00
|
|
|
|
|
|
|
#[derive(Component)]
|
|
|
|
pub struct FlyController;
|
|
|
|
|
|
|
|
pub fn update_controllers(
|
|
|
|
controllers: View<FlyController>,
|
|
|
|
mut transforms: ViewMut<Transform>,
|
2023-01-24 20:52:54 -06:00
|
|
|
inputs: UniqueView<Inputs>,
|
|
|
|
settings: UniqueView<GameSettings>,
|
2023-01-24 20:36:24 -06:00
|
|
|
) {
|
|
|
|
for (_, mut transform) in (&controllers, &mut transforms).iter() {
|
|
|
|
let (scale, mut rotation, translation) = transform.0.to_scale_rotation_translation();
|
2023-01-24 20:52:54 -06:00
|
|
|
let look = inputs.look * settings.mouse_sensitivity * -1.;
|
|
|
|
rotation *= Quat::from_euler(EulerRot::YXZ, look.x, look.y, 0.);
|
2023-01-24 20:36:24 -06:00
|
|
|
transform.0 = Mat4::from_scale_rotation_translation(scale, rotation, translation);
|
|
|
|
}
|
|
|
|
}
|