From 83530549ae1ddeb7dd9603c28ff46882b59c0ef0 Mon Sep 17 00:00:00 2001 From: aiden Date: Mon, 15 May 2023 14:45:55 +0100 Subject: [PATCH] aight --- src/camera.rs | 14 +++++++------- src/main.rs | 40 ++++++++++++++++++++++++++++++++++++++-- 2 files changed, 45 insertions(+), 9 deletions(-) diff --git a/src/camera.rs b/src/camera.rs index 9943dee..fb6d093 100644 --- a/src/camera.rs +++ b/src/camera.rs @@ -17,19 +17,17 @@ pub struct Camera { impl Camera { pub fn new< V: Into>, - Y: Into>, - P: Into>, >( dimensions: winit::dpi::PhysicalSize, position: V, - rot_x: Y, - rot_y: P + rot_x: Deg, + rot_y: Deg ) -> Self { Self { position: position.into(), - rot_x: rot_x.into(), - rot_y: rot_y.into(), + rot_x: rot_x, + rot_y: rot_y, aspect: dimensions.width as f32 / dimensions.height as f32, fovy: Deg(45.0), @@ -44,7 +42,7 @@ impl Camera { self.aspect = dimensions.width as f32 / dimensions.height as f32; } - pub fn update(&mut self, input: &mut Input, dt: f32) { + pub fn update_pos(&mut self, input: &mut Input, dt: f32) { let (yaw_sin, yaw_cos) = Rad::from(self.rot_x).0.sin_cos(); let forward = Vector3::new(yaw_cos, 0.0, yaw_sin).normalize(); let right = Vector3::new(-yaw_sin, 0.0, yaw_cos).normalize(); @@ -52,7 +50,9 @@ impl Camera { self.position += right * (input.amount_right - input.amount_left) * (input.speed * dt); self.position.y += (input.amount_up - input.amount_down) * (input.speed * dt); + } + pub fn update_rot(&mut self, input: &mut Input) { let (dx, dy) = input.mouse_moved; input.mouse_moved = (0.0, 0.0); diff --git a/src/main.rs b/src/main.rs index 62de0f8..9711efd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,35 @@ // based on https://sotrh.github.io/learn-wgpu/ +/* +quality aiden messages: + +i fucking hate everything +but i mean whatever +mouse input is not continuous so i don't think that delta time should be a factor in rotating the camera +(whereas keydown input is continuous) +rn i have two factors going into sensitivty: +- dots multiplier +- dots per degree +(dots are the unit of mouse input) +so like i have 8.8% dots multiplier +and dots per degree at 1920/360 +this is where the problem is +sens depends on resolution +im not sure what fortnite does about this +maybe they use a fixed amount of dots per degree? +also im accumulating winit mousemotion +i've seen a tutorial doing mouse_x = mouse_delta.x +but im doing mouse_x += mouse_delta.x +im not sure which one is correct +but mousemotion can be fired multiple times per frame +so it's not like they're doing the same thing +i think i'll actually have to read winit's code for this one +----- +also i want to add functionality to acmec to either (try to?) wait for dns updates, or actually add the dns txt record itself +i think it should hit the wait though +i think updating the dns shit should be done by a separate program/shell script +*/ + use {winit::{event as Event, event_loop::{ControlFlow, EventLoop}, window::WindowBuilder}, std::{cmp::Ordering, process::ExitCode}}; mod state; @@ -183,13 +213,19 @@ fn real_main() -> Result<(), &'static str> { total_elapsed += elapsed; prev_render = Instant::now(); + // doesn't need dt because + // the input is not continuous. + // FIXME: should this be done _after_ updating the camera's position? (updating the position depends on the camera's x rotation.) + state.camera.update_rot(&mut(input)); + const TIMESTEP: f32 = 1.0 / 60.0; + while elapsed >= TIMESTEP { - state.camera.update(&mut(input), TIMESTEP); + state.camera.update_pos(&mut(input), TIMESTEP); elapsed -= TIMESTEP; } - state.camera.update(&mut(input), elapsed); + state.camera.update_pos(&mut(input), elapsed); state.window().request_redraw(); }