diff options
author | HampusM <hampus@hampusmat.com> | 2023-10-27 21:44:49 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2023-10-27 21:44:49 +0200 |
commit | 4c9fe4e4cf8b9b2358bdbb08766fef46dc9ba82b (patch) | |
tree | 6b2d43d5c94660386ab5066e8ce8dafc090f640a | |
parent | b8f437e48777e32eaf4f518b9d1a37c507eb0aac (diff) |
feat(engine): add get cursor position
-rw-r--r-- | engine/src/lib.rs | 17 |
1 files changed, 17 insertions, 0 deletions
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<Vec2<f64>, 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<Instant>) { 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), } |