From c50a4e09ca4fc047daadcde721b6c9e1a68ef781 Mon Sep 17 00:00:00 2001
From: Matthias Richter
Because a camera has a point it looks at, a rotation and a zoom factor, it defines a coordinate system. A point now has two sets of coordinates: One defines where the point is to be found in the game world, and the other describes the position on the computer screen. The first set of coordinates is called world coordinates, the second one camera coordinates. Sometimes it is needed to convert between the two coordinate systems, for example to get the position of a mouse click in the game world in a strategy game, or to see if an object is visible on the screen.
These two functions convert a point between these two coordinate systems.
x, y
x,y = camera:worldCoords(love.mouse.getPosition())
selectedUnit:plotPath(x,y)
-
x,y = cam:toCameraCoords(player.pos)
+
x,y = cam:cameraCoords(player.pos)
love.graphics.line(x, y, love.mouse.getPosition())
Shortcut to camera:worldCoords(love.mouse.getPosition())
.
x,y = camera:mousepos()
selectedUnit:plotPath(x,y)