Skip to content

Commit 227b712

Browse files
committed
Update bee.script
1 parent 7293f76 commit 227b712

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

render/screen_to_world/example/bee.script

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
local DISPLAY_WIDTH = sys.get_config_int("display.width")
2-
local DISPLAY_HEIGHT = sys.get_config_int("display.height")
3-
41
-- function to convert screen (mouse/touch) coordinates to
52
-- world coordinates given a camera component
63
-- this function will use the camera view and projection to
@@ -9,11 +6,13 @@ local function screen_to_world(x, y, z, camera_id)
96
local projection = camera.get_projection(camera_id)
107
local view = camera.get_view(camera_id)
118
local w, h = window.get_size()
9+
1210
-- The window.get_size() function will return the scaled window size,
1311
-- ie taking into account display scaling (Retina screens on macOS for
1412
-- instance). We need to adjust for display scaling in our calculation.
15-
w = w / (w / DISPLAY_WIDTH)
16-
h = h / (h / DISPLAY_HEIGHT)
13+
local scale = window.get_display_scale()
14+
w = w / scale
15+
h = h / scale
1716

1817
-- https://defold.com/manuals/camera/#converting-mouse-to-world-coordinates
1918
local inv = vmath.inv(projection * view)

0 commit comments

Comments
 (0)