Skip to content

Commit 7700738

Browse files
committed
Fixed issue with camera helper if window width and height is zero
1 parent 6d3a720 commit 7700738

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

orthographic/render/helper.lua

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ local camera = require "orthographic.camera"
22

33
if sys.get_config("script.shared_state") ~= "1" then
44
error("ERROR - camera - 'shared_state' setting in game.project must be enabled for camera to work.")
5-
end
5+
end
66

77
local M = {}
88

@@ -14,6 +14,7 @@ local SET_CAMERA_OFFSET = hash("set_camera_offset")
1414
local world_view = vmath.matrix4()
1515
local world_projection = vmath.matrix4()
1616
local screen_view = vmath.matrix4()
17+
local screen_projection = vmath.matrix4()
1718
local camera_offset = nil
1819

1920

@@ -41,19 +42,22 @@ end
4142
function M.screen_projection()
4243
local current_window_width = render.get_window_width()
4344
local current_window_height = render.get_window_height()
44-
local left, right, bottom, top
45-
if camera_offset then
46-
left = camera_offset.x
47-
right = left + current_window_width
48-
bottom = camera_offset.y
49-
top = bottom + current_window_height
50-
else
51-
left = 0
52-
right = current_window_width
53-
bottom = 0
54-
top = current_window_height
45+
if current_window_width ~= 0 and current_window_height ~= 0 then
46+
local left, right, bottom, top
47+
if camera_offset then
48+
left = camera_offset.x
49+
right = left + current_window_width
50+
bottom = camera_offset.y
51+
top = bottom + current_window_height
52+
else
53+
left = 0
54+
right = current_window_width
55+
bottom = 0
56+
top = current_window_height
57+
end
58+
screen_projection = vmath.matrix4_orthographic(left, right, bottom, top, -1, 1)
5559
end
56-
return vmath.matrix4_orthographic(left, right, bottom, top, -1, 1)
60+
return screen_projection
5761
end
5862

5963
function M.set_screen_view_projection()
@@ -71,4 +75,4 @@ function M.on_message(_, message_id, message)
7175
end
7276
end
7377

74-
return M
78+
return M

0 commit comments

Comments
 (0)