diff --git a/src/camera.rs b/src/camera.rs index 41528f6..ae8acf3 100644 --- a/src/camera.rs +++ b/src/camera.rs @@ -15,7 +15,6 @@ pub struct Camera { pub eye: cgmath::Point3, pub target: cgmath::Point3, pub up: cgmath::Vector3, - aspect: f32, fovy: f32, znear: f32, zfar: f32, @@ -29,12 +28,11 @@ pub struct CameraInfo { } impl Camera { - pub fn new(config: &wgpu::SurfaceConfiguration, device: &wgpu::Device) -> (Self, CameraInfo) { + pub fn new(device: &wgpu::Device) -> (Self, CameraInfo) { let camera = Self { eye: (0.0, 0.0, DEFAULT_CAMERA_ZOOM).into(), target: (0.0, 0.0, 0.0).into(), up: cgmath::Vector3::unit_y(), - aspect: config.width as f32 / config.height as f32, fovy: 45.0, znear: 0.1, zfar: 100.0, diff --git a/src/spotlight.rs b/src/spotlight.rs index f521a72..a05895f 100644 --- a/src/spotlight.rs +++ b/src/spotlight.rs @@ -1,3 +1,5 @@ +use std::sync::Arc; + use wgpu::util::DeviceExt; use winit::{ event::{ElementState, MouseScrollDelta, WindowEvent}, @@ -7,6 +9,8 @@ use winit::{ use crate::controller::CameraController; pub struct Spotlight { + window: Arc, + cursor_position: (f32, f32), size: f32, @@ -21,8 +25,10 @@ pub struct SpotlightInfo { } impl Spotlight { - pub fn new(device: &wgpu::Device) -> (Self, SpotlightInfo) { + pub fn new(device: &wgpu::Device, window: Arc) -> (Self, SpotlightInfo) { let spotlight = Self { + window, + cursor_position: (960.0, 540.0), size: 50.0, @@ -83,10 +89,19 @@ impl Spotlight { } WindowEvent::KeyboardInput { event, .. } => { self.is_ctrl_pressed = false; - if event.state == ElementState::Pressed { - let key = &event.logical_key; - if let Key::Named(NamedKey::Control) = key { - self.is_ctrl_pressed = true; + let key = &event.logical_key; + match event.state { + ElementState::Pressed => { + if let Key::Named(NamedKey::Control) = key { + self.is_ctrl_pressed = true; + self.window.set_cursor_visible(false); + } + } + ElementState::Released => { + if let Key::Named(NamedKey::Control) = key { + self.is_ctrl_pressed = false; + self.window.set_cursor_visible(true); + } } } } @@ -101,9 +116,7 @@ impl Spotlight { } } - pub fn update(&mut self, window: &winit::window::Window) { - window.set_cursor_visible(!self.is_ctrl_pressed); - } + pub fn update(&mut self) {} } #[repr(C)] diff --git a/src/state.rs b/src/state.rs index 7feabb3..553c669 100644 --- a/src/state.rs +++ b/src/state.rs @@ -62,7 +62,6 @@ pub struct State<'a> { pub spotlight_info: SpotlightInfo, pub zoom: f32, pub camera_controller: CameraController, - hide_cursor: bool, } impl<'a> State<'a> { @@ -118,10 +117,10 @@ impl<'a> State<'a> { desired_maximum_frame_latency: 2, }; - let (camera, camera_info) = Camera::new(&config, &device); + let (camera, camera_info) = Camera::new(&device); let camera_controller = CameraController::new(ZOOM_SPEED, MOVE_SPEED); - let (spotlight, spotlight_info) = Spotlight::new(&device); + let (spotlight, spotlight_info) = Spotlight::new(&device, window.clone()); let shader = device.create_shader_module(wgpu::include_wgsl!("shader.wgsl")); @@ -205,7 +204,6 @@ impl<'a> State<'a> { spotlight_info, camera_controller, zoom: 1.0, - hide_cursor: false, } } @@ -252,7 +250,7 @@ impl<'a> State<'a> { bytemuck::cast_slice(&[self.camera_info.uniform]), ); - self.spotlight.update(&self.window); + self.spotlight.update(); self.spotlight_info .uniform .update(&self.spotlight, &self.camera_controller); diff --git a/src/texture.rs b/src/texture.rs index e0192ea..25674bd 100644 --- a/src/texture.rs +++ b/src/texture.rs @@ -1,5 +1,3 @@ -use image::GenericImageView; - pub struct Texture { pub layout: wgpu::BindGroupLayout, pub bind_group: wgpu::BindGroup,