Allow input->screen and screen->input to work without a camera

This commit is contained in:
oakes
2014-04-22 14:06:55 -04:00
parent b1df0d0ee7
commit f0f33fe2d9

View File

@@ -258,13 +258,17 @@ coordinates.
(screen->input screen 10 10) (screen->input screen 10 10)
(screen->input screen 10 10 0)" (screen->input screen 10 10 0)"
([screen {:keys [x y z] :or {x 0 y 0 z 0} :as entity}] ([screen {:keys [x y z] :or {x 0 y 0 z 0} :as entity}]
(let [^Camera camera (u/get-obj screen :camera) (try
coords (m/vector-3 x y z)] (let [^Camera camera (u/get-obj screen :camera)
(.project camera coords) coords (m/vector-3 x y z)]
(assoc entity (.project camera coords)
:x (. coords x) (assoc entity
:y (. coords y) :x (. coords x)
:z (. coords z)))) :y (. coords y)
:z (. coords z)))
; if there's no camera, just flip the y axis
(catch Exception _
(assoc entity :y (- (game :height) y)))))
([screen x y] ([screen x y]
(screen->input screen {:x x :y y})) (screen->input screen {:x x :y y}))
([screen x y z] ([screen x y z]
@@ -278,13 +282,17 @@ coordinates.
(input->screen screen 10 10) (input->screen screen 10 10)
(input->screen screen 10 10 0)" (input->screen screen 10 10 0)"
([screen {:keys [x y z] :or {x 0 y 0 z 0} :as entity}] ([screen {:keys [x y z] :or {x 0 y 0 z 0} :as entity}]
(let [^Camera camera (u/get-obj screen :camera) (try
coords (m/vector-3 x y z)] (let [^Camera camera (u/get-obj screen :camera)
(.unproject camera coords) coords (m/vector-3 x y z)]
(assoc entity (.unproject camera coords)
:x (. coords x) (assoc entity
:y (. coords y) :x (. coords x)
:z (. coords z)))) :y (. coords y)
:z (. coords z)))
; if there's no camera, just flip the y axis
(catch Exception _
(assoc entity :y (- (game :height) y)))))
([screen x y] ([screen x y]
(input->screen screen {:x x :y y})) (input->screen screen {:x x :y y}))
([screen x y z] ([screen x y z]