diff --git a/src/modules/camera/orbit_controller.rs b/src/modules/camera/orbit_controller.rs index 15cdff19..2f43b37a 100644 --- a/src/modules/camera/orbit_controller.rs +++ b/src/modules/camera/orbit_controller.rs @@ -1,4 +1,5 @@ use cgmath::{Point3, Rad}; +use winit::{dpi::PhysicalPosition, event::MouseScrollDelta}; use super::camera::Camera; const VERTICAL_OFFSET: f32 = 2.0; @@ -30,43 +31,40 @@ impl OrbitController { self.rotate_vertical = delta_y as f32; } + pub fn process_scroll(&mut self, delta: &MouseScrollDelta) { + let value = match delta { + MouseScrollDelta::LineDelta(_, scroll) => scroll * 100.0, + MouseScrollDelta::PixelDelta(PhysicalPosition { + y: scroll, + .. + }) => *scroll as f32, + }; + self.distance += value / 15.0; + self.distance = self.distance.clamp(2.0, 30.0); + dbg!(self.distance); + } + pub fn update_target(&mut self, mut target: [f32; 3]) { target[1] += VERTICAL_OFFSET; self.target = Point3::from(target); } pub fn update_camera(&mut self, camera: &mut Camera) { - // Mise à jour des angles yaw et pitch avec les rotations enregistrées - self.yaw += self.rotate_horizontal * 0.01; // Sensibilité de la rotation - self.pitch += self.rotate_vertical * 0.01; // Sensibilité de la rotation - - // Limiter l'angle de pitch pour éviter de passer sous ou au-dessus du personnage - const PITCH_LIMIT: f32 = std::f32::consts::FRAC_PI_2 - 0.1; // Limiter à presque 90° + self.yaw += self.rotate_horizontal * 0.01; + self.pitch += self.rotate_vertical * 0.01; + const PITCH_LIMIT: f32 = std::f32::consts::FRAC_PI_2 - 0.1; self.pitch = self.pitch.clamp(-PITCH_LIMIT, PITCH_LIMIT); - - // Calculer la position de la caméra en coordonnées sphériques - // let x = self.distance * self.yaw.cos() * self.pitch.cos(); - // let y = self.distance * self.pitch.sin(); - // let z = self.distance * self.yaw.sin() * self.pitch.cos(); - - let horizontal_distance = self.distance * self.pitch.cos(); // Distance projetée sur le plan XZ - let x = horizontal_distance * self.yaw.cos(); // Composante X du déplacement - let z = horizontal_distance * self.yaw.sin(); // Composante Z du déplacement - let y = self.distance * self.pitch.sin(); // Composante verticale du déplacement (rotation verticale) - - - // Mettre à jour la position de la caméra en fonction de la cible (personnage) + let horizontal_distance = self.distance * self.pitch.cos(); + let x = horizontal_distance * self.yaw.cos(); + let z = horizontal_distance * self.yaw.sin(); + let y = self.distance * self.pitch.sin(); camera.position = Point3::new( self.target.x + x, self.target.y + y, self.target.z + z, ); - - // Mettre à jour l'orientation de la caméra (yaw et pitch) camera.yaw = Rad(self.yaw + std::f32::consts::PI); camera.pitch = Rad(-self.pitch); - - // Réinitialiser les rotations après l'update self.rotate_horizontal = 0.0; self.rotate_vertical = 0.0; } diff --git a/src/modules/character/character.rs b/src/modules/character/character.rs index c38f12d3..685833ee 100644 --- a/src/modules/character/character.rs +++ b/src/modules/character/character.rs @@ -246,13 +246,6 @@ impl Character { scene ); self.has_moved = true; - // // Mettre à jour la rotation du personnage pour qu'il fasse face à la direction du mouvement - // if movement.magnitude() > 0.001 { - // let new_rotation = movement.y.atan2(movement.x); - // let rotation = Quaternion::from_arc(Vector3::new(0.0, 0.0, 1.0), normalized_direction, None); - // self.rotate_quaternion(rotation, scene); - // self.rotate(new_rotation, scene); - // } } } diff --git a/src/modules/state.rs b/src/modules/state.rs index 5173dc2d..675c4104 100644 --- a/src/modules/state.rs +++ b/src/modules/state.rs @@ -377,7 +377,13 @@ impl<'a> State<'a> { } }, WindowEvent::MouseWheel { delta, .. } => { - self.camera_controller.process_scroll(delta); + if self.camera_controller.enabled { + self.camera_controller.process_scroll(delta); + } else { + if let Some(actor) = &mut self.actor { + actor.orbit_controller.process_scroll(delta); + } + } true } WindowEvent::MouseInput {