Hi! I’m using a standard orthographic camera. I have code that adjusts the zoom based on the window size, and everything works perfectly when High DPI is disabled in the project settings. However, when I enable it, the zoom is calculated incorrectly on devices with high DPI. I’ve tried many different approaches, but I still haven’t found a solution
local CAMERA_URL = "/operator"
local DISP_W, DISP_H = 1080, 1920
local VIS_W, VIS_H = 0, 0
local CAM_X, CAM_Y = 540, 960
local camera = { near = -1, far = 1, zoom = 1 }
local state = { width = DISP_W, height = DISP_H, window_width = DISP_W, window_height = DISP_H }
local function get_fixed_fit_projection(cam, st)
cam.zoom = math.min(st.window_width / st.width, st.window_height / st.height)
go.set(CAMERA_URL.."#camera", "orthographic_zoom", cam.zoom)
local pw, ph = st.window_width / cam.zoom, st.window_height / cam.zoom
local left, bottom = -(pw - st.width) / 2, -(ph - st.height) / 2
return vmath.matrix4_orthographic(left, left + pw, bottom, bottom + ph, cam.near, cam.far)
end
local function update_projection()
state.window_width, state.window_height = window.get_size()
local inv = vmath.inv(get_fixed_fit_projection(camera, state))
local btm = inv * vmath.vector4(-1, -1, 0, 1)
local top = inv * vmath.vector4(1, 1, 0, 1)
btm, top = btm / btm.w, top / top.w
VIS_W, VIS_H = top.x - btm.x - CAM_X, top.y - btm.y - CAM_Y
print("Visible width:", VIS_W, "Visible height:", VIS_H)
end
local function window_event_listener(self, event)
if event == window.WINDOW_EVENT_RESIZED then update_projection() end
end
function init(self)
window.set_listener(window_event_listener)
update_projection()
end