summaryrefslogtreecommitdiff
path: root/client/camera.lua
diff options
context:
space:
mode:
Diffstat (limited to 'client/camera.lua')
-rw-r--r--client/camera.lua14
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}