2023-01-25 20:05:29 -06:00
|
|
|
use glam::{Vec3, Mat4, Quat, EulerRot};
|
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() {
|
2023-01-25 20:05:29 -06:00
|
|
|
let (scale, mut rotation, mut translation) = transform.0.to_scale_rotation_translation();
|
|
|
|
let look = inputs.look * settings.mouse_sensitivity;
|
|
|
|
|
|
|
|
//rotation *= Quat::from_axis_angle(Vec3::Y, look.x);
|
|
|
|
|
|
|
|
//old way
|
|
|
|
// rotation = rotation.normalize();
|
|
|
|
// rotation *= Quat::from_euler(EulerRot::ZYX, 0., look.x, look.y).normalize();
|
|
|
|
// rotation = rotation.normalize();
|
|
|
|
|
|
|
|
// let direction = (rotation * Vec3::Z).normalize();
|
|
|
|
// let camera_right = Vec3::Y.cross(direction).normalize();
|
|
|
|
// let camera_up = direction.cross(camera_right);
|
|
|
|
// rotation *= Quat::from_axis_angle(Vec3::Y, look.x);
|
|
|
|
// rotation *= Quat::from_axis_angle(camera_right, look.y);
|
|
|
|
|
|
|
|
//translation += (rotation * Vec3::X) / 4.;
|
|
|
|
|
2023-01-24 20:36:24 -06:00
|
|
|
transform.0 = Mat4::from_scale_rotation_translation(scale, rotation, translation);
|
|
|
|
}
|
|
|
|
}
|