Skip to content

No world_to_window function #63

@dri-richard

Description

@dri-richard

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions