diff options
author | ubq323 <ubq323@ubq323.website> | 2023-01-29 02:59:50 +0000 |
---|---|---|
committer | ubq323 <ubq323@ubq323.website> | 2023-01-29 02:59:50 +0000 |
commit | ebe12a65c07bccfbc704667c88d8125be33067cf (patch) | |
tree | 9c1ef457ce0da96b4d5dbe77cd56625f53b4ba89 /client/camera.lua | |
parent | 9b659149c7273a57a82c9be988a8a78c62bb23f4 (diff) |
camera stuff + vastly optimise hex drawing
Diffstat (limited to 'client/camera.lua')
-rw-r--r-- | client/camera.lua | 14 |
1 files changed, 14 insertions, 0 deletions
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} |