MCPcopy Create free account
hub / github.com/donkeyteethUX/iced_plot / screen_to_world

Method screen_to_world

src/camera.rs:93–102  ·  view source on GitHub ↗

Convert screen coordinates to world coordinates

(&self, screen_pos: DVec2, screen_size: DVec2)

Source from the content-addressed store, hash-verified

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 {

Callers 3

handle_mouse_eventMethod · 0.80
cursor_world_dataMethod · 0.80

Calls 2

effective_positionMethod · 0.80
newFunction · 0.50

Tested by

no test coverage detected