From ebe12a65c07bccfbc704667c88d8125be33067cf Mon Sep 17 00:00:00 2001 From: ubq323 Date: Sun, 29 Jan 2023 02:59:50 +0000 Subject: camera stuff + vastly optimise hex drawing --- client/camera.lua | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'client/camera.lua') diff --git a/client/camera.lua b/client/camera.lua index bc65044..6309e38 100644 --- a/client/camera.lua +++ b/client/camera.lua @@ -21,5 +21,19 @@ function Camera.apply_trans(self) 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 +end +function Camera.world_to_screen(self,pos) + return (pos-self.pos) * self.zoom + screen_offset +end + +function Camera.extents(self) + -- 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)) +end + return {Camera=Camera} -- cgit v1.2.3