Screen: add get_pixels_at_depth.

This commit is contained in:
Alberto Torres 2024-09-21 02:13:26 +02:00
parent 55d0c859ab
commit 61c1986c92

View file

@ -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