summaryrefslogtreecommitdiff
path: root/client/camera.lua
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2023-02-20 15:29:00 +0000
committerubq323 <ubq323@ubq323.website>2023-02-20 15:29:00 +0000
commit415ec81e72bbf85cc81a6d2ce0f8c19335c844ec (patch)
tree95f2841026fda04431748440727321e438f52f00 /client/camera.lua
parenta3af144dec34adf9e8ac047dd368bb102de40821 (diff)
make window resizeable, remove big mode
Diffstat (limited to 'client/camera.lua')
-rw-r--r--client/camera.lua23
1 files changed, 15 insertions, 8 deletions
diff --git a/client/camera.lua b/client/camera.lua
index bb1d8a6..d4d7901 100644
--- a/client/camera.lua
+++ b/client/camera.lua
@@ -2,7 +2,6 @@ local coords = require"common.coords"
local class = require"common.class"
-- in screen units
-local screen_width, screen_height = love.graphics.getDimensions()
-- zoom is screen pixels per world unit
local Camera = class()
@@ -11,28 +10,36 @@ function Camera.make(cls,pos,zoom)
zoom = zoom or 30
return setmetatable({pos=pos,zoom=zoom},cls)
end
+local function screen_offset()
+ -- in screen units, not in world units !
+ local W,H = love.graphics.getDimensions()
+ return coords.Pos:make(W/2,H/2)
+end
function Camera.apply_trans(self)
- -- love.graphics.origin()
+ local so = screen_offset()
+
-- centre (0,0) in the middle of the screen
- love.graphics.translate(screen_width/2,screen_height/2)
- -- apply camera transformations
+ love.graphics.translate(so.x,so.y)
+ -- apply camera transformations
love.graphics.scale(self.zoom)
love.graphics.translate(-self.pos.x,-self.pos.y)
end
-local screen_offset = coords.Pos:make(screen_width/2,screen_height/2)
function Camera.screen_to_world(self,pos)
- return (pos-screen_offset)/self.zoom + self.pos
+ local so = screen_offset()
+ return (pos-so)/self.zoom + self.pos
end
function Camera.world_to_screen(self,pos)
- return (pos-self.pos) * self.zoom + screen_offset
+ local so = screen_offset()
+ return (pos-self.pos) * self.zoom + so
end
function Camera.extents(self)
+ local W,H = love.graphics.getDimensions()
-- returns top left and bottom right pos's in world coords
return self:screen_to_world(coords.Pos:make(0,0)),
- self:screen_to_world(coords.Pos:make(screen_width,screen_height))
+ self:screen_to_world(coords.Pos:make(W,H))
end