better camera zoom

This commit is contained in:
Ivan Yuriev 2025-08-03 20:48:39 +03:00
parent 8762ba3d85
commit 59bac8bb23

View File

@ -7,19 +7,29 @@ local EPSILON = 0.001
--- @field velocity Vec3
--- @field speed number
--- @field pixelsPerMeter integer
--- @field scale number
local camera = {
position = Vec3 {},
velocity = Vec3 {},
acceleration = 0.2,
speed = 5,
pixelsPerMeter = 24,
scale = 2
}
function camera:getDefaultScale()
return love.window.getDesktopDimensions() /
(self.pixelsPerMeter * 30) -- 30 meters wide regardless of the actual screen size
end
camera.__index = camera
camera.scale = camera:getDefaultScale()
---------------------------------------------------
love.wheelmoved = function(x, y)
if camera.scale > 50 and y > 0 then return end;
if camera.scale < 0.005 and y < 0 then return end;
camera.scale = camera.scale + 0.1 * y
if camera.scale > camera:getDefaultScale() * 5 and y > 0 then return end;
if camera.scale < camera:getDefaultScale() / 5 and y < 0 then return end;
camera.scale = camera.scale + (camera.scale * 0.1 * y)
end
---@todo Отрефакторить и вынести кнопки управления в controls, не должно быть таких ужасных проверок
@ -61,9 +71,8 @@ end
--- @return Camera
local function new()
return setmetatable({}, {
__index = camera
})
return setmetatable({
}, camera)
end
return { new = new }