   (println "Mode:" m)
   (swap! mode (fn [_] identity m)))
 
-(defn move [axis amount]
-  (swap! player-position (fn [pos]
-                           (let [old-val (pos axis)
-                                 new-val (+ old-val (* amount 1.0))]
-                             (assoc pos axis new-val)))))
+(defn move [direction amount]
+  (swap! player-position (fn [pp] (translate-with-direction pp direction amount)))
+  (player-moved)
+  @player-position)
 
 (defn move-sideways [amount]
-  (move 0 amount))
+  (move (rotate-direction @player-direction 1 (* -0.5 Math/PI)) amount))
 
 (defn move-forward [amount]
-  (move 2 (* -1.0 amount)))
+  (move @player-direction amount))
 
 (def listeners
   [{:key :left, :down? true, :repeat? false :callback key-left-down}

   ;; Debugging keys
   {:key :up, :down? true, :repeat? false :callback key-up}
   {:key :down, :down? true, :repeat? false :callback key-down}
   {:key :1, :down? true, :repeat? false :callback (fn [] (set-mode :angle-speed))}
   {:key :2, :down? true, :repeat? false :callback (fn [] (set-mode :eye-z))}])

(defn register-listeners []

(defn rotate-direction [direction axis angle]
  (assoc direction axis (+ (direction axis) angle)))

(defn translate-with-direction
  ([position direction] (translate-with-direction position direction (float 1.0)))
  ([position direction distance]
     ;; Direction, measured in 3 angles.
     ;; (0, 0, 0) is origin, upright, facing -z
     (let [[angle-x angle-y angle-z] direction
           [px py pz] position
           dx (* -1.0 distance (Math/sin angle-y))
           dy 0.0
           dz (* -1.0 distance (Math/cos angle-y))
           new-x (+ px dx)
           new-y (+ py dy)
           new-z (+ pz dz)]
       [new-x new-y new-z])))

(defn print-player []
  (when @show-player?
    (println "player-position:" @player-position
             ", player-direction:" @player-direction
             ", direction point:" (translate-with-direction @player-position @player-direction))))

(defn player-moved []
  (print-player))

(defn key-left-down []
  (swap! player-direction #(rotate-direction % 1 0.1))
  (player-moved)
  @player-direction)

(defn key-right-down []
  (swap! player-direction #(rotate-direction % 1 -0.1))
  (player-moved)
  @player-direction)

(def up-down-callbacks
  {:angle-speed {:atom angle-speed, :amount 0.1}})
