Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix world_to_window #65

Merged
merged 2 commits into from
Jan 22, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions orthographic/camera.lua
Original file line number Diff line number Diff line change
Expand Up @@ -792,12 +792,16 @@ end
-- @param world World coordinates as a vector3
-- @return window coordinates
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)
camera_id = camera_id or camera_ids[1]
assert(camera_id, "You must provide a camera id")
assert(world, "You must provide world coordinates to convert")
local camera = cameras[camera_id]
local view = camera.view or MATRIX4
local projection = camera.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

--- Translate world coordinates to screen coordinates given a
Expand Down