From 4c9fe4e4cf8b9b2358bdbb08766fef46dc9ba82b Mon Sep 17 00:00:00 2001 From: HampusM Date: Fri, 27 Oct 2023 21:44:49 +0200 Subject: feat(engine): add get cursor position --- engine/src/lib.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'engine/src') diff --git a/engine/src/lib.rs b/engine/src/lib.rs index d848112..ec969f8 100644 --- a/engine/src/lib.rs +++ b/engine/src/lib.rs @@ -154,6 +154,20 @@ impl Engine .map_err(Error::GetKeyStateFailed) } + /// Returns the cursor position. + /// + /// # Errors + /// Will return `Err` if unable to get the cursor position from GLFW. + pub fn get_cursor_pos(&self) -> Result, Error> + { + let pos = self + .window + .get_cursor_position() + .map_err(Error::GetCursorPosFailed)?; + + Ok(Vec2 { x: pos.x, y: pos.y }) + } + fn update_delta_time(&mut self, prev_frame_start: &mut Option) { let frame_start_time = Instant::now(); @@ -187,4 +201,7 @@ pub enum Error #[error("Failed to get key state")] GetKeyStateFailed(#[source] glfw::Error), + + #[error("Failed to get cursor position")] + GetCursorPosFailed(#[source] glfw::Error), } -- cgit v1.2.3-18-g5258