Fix unintended roll of fly cam
ci/woodpecker/push/build Pipeline was successful
Details
ci/woodpecker/push/build Pipeline was successful
Details
This commit is contained in:
parent
f3c25b6370
commit
1f534bb1aa
|
@ -5,7 +5,7 @@ use lyra_engine::{
|
|||
ecs::{components::camera::CameraComponent, EventQueue, SimpleSystem},
|
||||
game::Game,
|
||||
input::{InputButtons, KeyCode, MouseMotion},
|
||||
math::{Angle, Quat, Vec3},
|
||||
math::{Angle, Quat, Vec3, EulerRot},
|
||||
plugin::Plugin,
|
||||
};
|
||||
use tracing::debug;
|
||||
|
@ -23,7 +23,7 @@ impl Default for FreeFlyCamera {
|
|||
Self {
|
||||
speed: 0.07,
|
||||
look_speed: 0.01,
|
||||
mouse_sensitivity: 0.03,
|
||||
mouse_sensitivity: 0.04,
|
||||
look_with_keys: false,
|
||||
}
|
||||
}
|
||||
|
@ -86,7 +86,7 @@ impl SimpleSystem for FreeFlyCameraController {
|
|||
{
|
||||
let forward = cam.transform.forward();
|
||||
let left = cam.transform.left();
|
||||
let up = cam.transform.up();
|
||||
let up = Vec3::Y;
|
||||
|
||||
// handle camera movement
|
||||
if let Some(keys) = keys.as_ref() {
|
||||
|
@ -130,9 +130,15 @@ impl SimpleSystem for FreeFlyCameraController {
|
|||
|
||||
if camera_rot != Vec3::ZERO {
|
||||
let look_velocity = camera_rot * fly.look_speed;
|
||||
cam.transform.rotation *= Quat::from_rotation_x(look_velocity.x)
|
||||
* Quat::from_rotation_y(look_velocity.y)
|
||||
* Quat::from_rotation_z(look_velocity.z);
|
||||
|
||||
let (mut y, mut x, _) = cam.transform.rotation.to_euler(EulerRot::YXZ);
|
||||
x += look_velocity.x;
|
||||
y += look_velocity.y;
|
||||
x = x.clamp(-1.54, 1.54);
|
||||
|
||||
// rotation is not commutative, keep this order to avoid unintended roll
|
||||
cam.transform.rotation = Quat::from_axis_angle(Vec3::Y, y)
|
||||
* Quat::from_axis_angle(Vec3::X, x);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue