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

No world_to_window function #63

Open
dri-richard opened this issue Nov 30, 2023 · 1 comment
Open

No world_to_window function #63

dri-richard opened this issue Nov 30, 2023 · 1 comment

Comments

@dri-richard
Copy link
Contributor

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
@britzl
Copy link
Owner

britzl commented Dec 1, 2023

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants