We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 6d72a37 commit 9ce2f73Copy full SHA for 9ce2f73
src/camera.rs
@@ -135,9 +135,24 @@ impl Camera2D {
135
///
136
/// Point is a screen space position, often mouse x and y.
137
pub fn screen_to_world(&self, point: Vec2) -> Vec2 {
138
+ let dims = self
139
+ .viewport()
140
+ .map(|(vx, vy, vw, vh)| Rect {
141
+ x: vx as f32,
142
+ y: screen_height() - (vy + vh) as f32,
143
+ w: vw as f32,
144
+ h: vh as f32,
145
+ })
146
+ .unwrap_or(Rect {
147
+ x: 0.0,
148
+ y: 0.0,
149
+ w: screen_width(),
150
+ h: screen_height(),
151
+ });
152
+
153
let point = vec2(
- point.x / screen_width() * 2. - 1.,
- 1. - point.y / screen_height() * 2.,
154
+ (point.x - dims.x) / dims.w * 2. - 1.,
155
+ 1. - (point.y - dims.y) / dims.h * 2.,
156
);
157
let inv_mat = self.matrix().inverse();
158
let transform = inv_mat.transform_point3(vec3(point.x, point.y, 0.));
0 commit comments