Remove some unused stuff and and better handling for cursor visibility

master
Wynd 2024-11-07 12:46:13 +02:00
parent 9a03b4a36c
commit 6fe6604c35
4 changed files with 25 additions and 18 deletions

View File

@ -15,7 +15,6 @@ pub struct Camera {
pub eye: cgmath::Point3<f32>,
pub target: cgmath::Point3<f32>,
pub up: cgmath::Vector3<f32>,
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,

View File

@ -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<winit::window::Window>,
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<winit::window::Window>) -> (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;
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)]

View File

@ -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);

View File

@ -1,5 +1,3 @@
use image::GenericImageView;
pub struct Texture {
pub layout: wgpu::BindGroupLayout,
pub bind_group: wgpu::BindGroup,