Convert screen coordinates to world coordinates
(&self, screen_pos: DVec2, screen_size: DVec2)
| 91 | |
| 92 | // Convert screen coordinates to world coordinates |
| 93 | pub fn screen_to_world(&self, screen_pos: DVec2, screen_size: DVec2) -> DVec2 { |
| 94 | let ndc_x = (screen_pos.x / screen_size.x) * 2.0 - 1.0; |
| 95 | let ndc_y = -((screen_pos.y / screen_size.y) * 2.0 - 1.0); // Flip Y |
| 96 | // Calculate position in render space first, then convert to world space |
| 97 | let render_pos = DVec2::new( |
| 98 | self.effective_position().x + ndc_x * self.half_extents.x, |
| 99 | self.effective_position().y + ndc_y * self.half_extents.y, |
| 100 | ); |
| 101 | render_pos + self.render_offset |
| 102 | } |
| 103 | |
| 104 | /// Get the effective camera position relative to the render offset |
| 105 | pub fn effective_position(&self) -> DVec2 { |
no test coverage detected