Only require view access
This commit is contained in:
parent
69c2353730
commit
8f01064b88
1 changed files with 10 additions and 13 deletions
|
@ -21,7 +21,7 @@ impl CameraControl {
|
||||||
const MIN_PITCH: i32 = 10;
|
const MIN_PITCH: i32 = 10;
|
||||||
const MAX_PITCH: i32 = 80;
|
const MAX_PITCH: i32 = 80;
|
||||||
|
|
||||||
pub fn new(scene: &mut Scene) -> Result<Self> {
|
pub fn new(view: &mut View) -> Result<Self> {
|
||||||
let me = Self {
|
let me = Self {
|
||||||
zoom_levels: vec![
|
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,
|
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,
|
mouse_position_start: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
me.set_camera_offset(scene)?;
|
me.set_camera_offset(view)?;
|
||||||
|
|
||||||
Ok(me)
|
Ok(me)
|
||||||
}
|
}
|
||||||
|
@ -47,21 +47,18 @@ impl CameraControl {
|
||||||
&mut self,
|
&mut self,
|
||||||
zoom_levels: Vec<f32>,
|
zoom_levels: Vec<f32>,
|
||||||
current_zoom_level: usize,
|
current_zoom_level: usize,
|
||||||
scene: &mut Scene,
|
view: &mut View,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.current_zoom_level = current_zoom_level.min(zoom_levels.len() - 1);
|
self.current_zoom_level = current_zoom_level.min(zoom_levels.len() - 1);
|
||||||
self.zoom_levels = zoom_levels;
|
self.zoom_levels = zoom_levels;
|
||||||
|
|
||||||
self.set_camera_offset(scene)
|
self.set_camera_offset(view)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_camera_offset(&self, scene: &mut Scene) -> Result<()> {
|
fn set_camera_offset(&self, view: &mut View) -> Result<()> {
|
||||||
let view = scene.view_mut();
|
|
||||||
view.camera_mut()
|
view.camera_mut()
|
||||||
.set_eye_offset(self.calculate_camera_offset());
|
.set_eye_offset(self.calculate_camera_offset());
|
||||||
view.update_buffer()?;
|
view.update_buffer()
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn calculate_camera_offset(&self) -> Vector3<f32> {
|
fn calculate_camera_offset(&self) -> Vector3<f32> {
|
||||||
|
@ -84,7 +81,7 @@ impl CameraControl {
|
||||||
self.mouse_position_start = None;
|
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);
|
self.mouse_position = (x, y);
|
||||||
|
|
||||||
if let Some((start_x, start_y)) = self.mouse_position_start {
|
if let Some((start_x, start_y)) = self.mouse_position_start {
|
||||||
|
@ -96,7 +93,7 @@ impl CameraControl {
|
||||||
.min(CameraControl::MAX_PITCH)
|
.min(CameraControl::MAX_PITCH)
|
||||||
.max(CameraControl::MIN_PITCH) as f32);
|
.max(CameraControl::MIN_PITCH) as f32);
|
||||||
|
|
||||||
self.set_camera_offset(scene)?;
|
self.set_camera_offset(view)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -106,7 +103,7 @@ impl CameraControl {
|
||||||
&mut self,
|
&mut self,
|
||||||
y: i32,
|
y: i32,
|
||||||
direction: MouseWheelDirection,
|
direction: MouseWheelDirection,
|
||||||
scene: &mut Scene,
|
view: &mut View,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
match direction {
|
match direction {
|
||||||
MouseWheelDirection::Flipped => {
|
MouseWheelDirection::Flipped => {
|
||||||
|
@ -132,6 +129,6 @@ impl CameraControl {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.set_camera_offset(scene)
|
self.set_camera_offset(view)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue