diff --git a/engine/src/main.rs b/engine/src/main.rs index 6bdaa04..6f03255 100644 --- a/engine/src/main.rs +++ b/engine/src/main.rs @@ -167,7 +167,7 @@ impl<'a> ecs::System <'a> for Main { type SystemData = MainData<'a>; fn run(&mut self, sd: Self::SystemData) { let position: f32 = match sd.input.get().mouse_cursor() { - Some(cursor) => cursor.x, + Some(cursor) => cursor.x * 3.14 * 2.0, _ => (sd.time.get().instant() / 10.0) * 3.14 * 2.0, }; diff --git a/engine/src/render/mod.rs b/engine/src/render/mod.rs index 149c665..efe6f34 100644 --- a/engine/src/render/mod.rs +++ b/engine/src/render/mod.rs @@ -64,6 +64,7 @@ pub struct Renderer { pub struct Status { pub closed: bool, pub input_device_id: u64, + pub resolution: [u32; 2], } impl ecs::Global for Status {} @@ -114,10 +115,16 @@ impl<'a> ecs::System<'a> for Renderer { let view = &scene.get().view; self.instance.flip(camera, view, &rd, &self.rm); + match self.instance.swapchain_dimensions() { + Some(res) => { + status.resolution = res.clone() + }, + None => (), + } + if status.input_device_id == 0 { status.input_device_id = input.allocate_device(); } - let (close, events) = self.poll_close(); if close { status.closed = true; @@ -129,8 +136,11 @@ impl<'a> ecs::System<'a> for Renderer { InternalEvent::MousePressed(button) => cursor.set_mouse_pressed(button), InternalEvent::MouseReleased(button) => cursor.set_mouse_released(button), InternalEvent::MouseMoved(x, y) => { - cursor.x = x as f32; - cursor.y = y as f32; + let (rx, ry) = (status.resolution[0], status.resolution[1]); + if rx != 0 && ry != 0 { + cursor.x = (x as f32) / (rx as f32); + cursor.y = (y as f32) / (ry as f32); + } }, } } @@ -155,6 +165,7 @@ impl Renderer { world.set_global(Status { closed: false, input_device_id: 0, + resolution: [0u32; 2], }); let mut instance = vulkan::Instance::new("abrasion".to_string()); diff --git a/engine/src/render/vulkan/mod.rs b/engine/src/render/vulkan/mod.rs index 8cf3df9..6be6974 100644 --- a/engine/src/render/vulkan/mod.rs +++ b/engine/src/render/vulkan/mod.rs @@ -168,6 +168,10 @@ impl Instance { self.armed = true; } + pub fn swapchain_dimensions(&self) -> Option<[u32; 2]> { + Some(self.swapchain_binding.as_ref()?.chain.dimensions()) + } + fn make_graphics_commands( &mut self, profiler: &mut Profiler,