defold-orthographic
defold-orthographic copied to clipboard
No world_to_window function
We were using world_to_screen() to convert world coordinates to gui position to spawn some gui particles, but it wasn't working correctly after window resize, even if we used the adust mode.
I noticed that there were window_to_world() and screen_to_world() functions, and screen_to_world() exists but not world_to_window()
I wrote something below which works perfectly for our purpose, but before I open a PR - am I misunderstanding something, and this could have been achieved with existing functionality?
function M.world_to_window(camera_id, world)
local view = cameras[camera_id].view or MATRIX4
local projection = cameras[camera_id].projection or MATRIX4
local screen = M.project(view, projection, vmath.vector3(world))
local scale_x = screen.x / (dpi_ratio * DISPLAY_WIDTH / WINDOW_WIDTH)
local scale_y = screen.y / (dpi_ratio * DISPLAY_HEIGHT / WINDOW_HEIGHT)
return vmath.vector3(scale_x, scale_y, 0)
end
I wrote something below which works perfectly for our purpose, but before I open a PR - am I misunderstanding something, and this could have been achieved with existing functionality?
No., I think you are correct. There is no equivalent of world_to_window(). Please open a PR!