From 61c1986c92c98503d4a442b373600e0ae302c0e6 Mon Sep 17 00:00:00 2001 From: Alberto Torres Date: Sat, 21 Sep 2024 02:13:26 +0200 Subject: [PATCH] Screen: add `get_pixels_at_depth`. --- src/screen.nim | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/screen.nim b/src/screen.nim index f3a6159..ca41916 100644 --- a/src/screen.nim +++ b/src/screen.nim @@ -116,6 +116,15 @@ proc get_ray_direction_local*(viewport: Viewport, position: Vec2): Vec3 = let y = (position.y - viewport.rect_pix[1].float32) / viewport.rect_pix[3].float32 return viewport.camera.get_ray_direction_local(x,y) +proc get_pixels_at_depth*(viewport: Viewport, depth: float32): float32 = + ## Returns the length of one world unit (usually one meter) in screen pixels, + ## at a given depth. + + # TODO: shift_x + let p = vec4(1.0, 0.0, -depth, 1.0) + let s = viewport.camera.projection_matrix * p + return viewport.rect_pix[2].float32 * 0.5 * s.x/s.w + proc clear_all_callbacks*(self: Screen) = self.key_callbacks.setLen 0 self.mouse_button_callbacks.setLen 0