Only require view access

This commit is contained in:
hodasemi 2024-08-27 08:04:27 +02:00
parent 69c2353730
commit 8f01064b88

View file

@ -21,7 +21,7 @@ impl CameraControl {
const MIN_PITCH: i32 = 10;
const MAX_PITCH: i32 = 80;
pub fn new(scene: &mut Scene) -> Result<Self> {
pub fn new(view: &mut View) -> Result<Self> {
let me = Self {
zoom_levels: vec![
15.0, 14.0, 13.0, 12.0, 11.0, 10.0, 9.0, 8.0, 7.0, 6.0, 5.0, 4.0, 3.0, 2.0,
@ -38,7 +38,7 @@ impl CameraControl {
mouse_position_start: None,
};
me.set_camera_offset(scene)?;
me.set_camera_offset(view)?;
Ok(me)
}
@ -47,21 +47,18 @@ impl CameraControl {
&mut self,
zoom_levels: Vec<f32>,
current_zoom_level: usize,
scene: &mut Scene,
view: &mut View,
) -> Result<()> {
self.current_zoom_level = current_zoom_level.min(zoom_levels.len() - 1);
self.zoom_levels = zoom_levels;
self.set_camera_offset(scene)
self.set_camera_offset(view)
}
fn set_camera_offset(&self, scene: &mut Scene) -> Result<()> {
let view = scene.view_mut();
fn set_camera_offset(&self, view: &mut View) -> Result<()> {
view.camera_mut()
.set_eye_offset(self.calculate_camera_offset());
view.update_buffer()?;
Ok(())
view.update_buffer()
}
fn calculate_camera_offset(&self) -> Vector3<f32> {
@ -84,7 +81,7 @@ impl CameraControl {
self.mouse_position_start = None;
}
pub fn mouse_move(&mut self, x: u32, y: u32, scene: &mut Scene) -> Result<()> {
pub fn mouse_move(&mut self, x: u32, y: u32, view: &mut View) -> Result<()> {
self.mouse_position = (x, y);
if let Some((start_x, start_y)) = self.mouse_position_start {
@ -96,7 +93,7 @@ impl CameraControl {
.min(CameraControl::MAX_PITCH)
.max(CameraControl::MIN_PITCH) as f32);
self.set_camera_offset(scene)?;
self.set_camera_offset(view)?;
}
Ok(())
@ -106,7 +103,7 @@ impl CameraControl {
&mut self,
y: i32,
direction: MouseWheelDirection,
scene: &mut Scene,
view: &mut View,
) -> Result<()> {
match direction {
MouseWheelDirection::Flipped => {
@ -132,6 +129,6 @@ impl CameraControl {
}
}
self.set_camera_offset(scene)
self.set_camera_offset(view)
}
}