                  #(v-plus % (v-mult dir step-size)))
       state)))
 
-(defn- setup-3d-nav [user-setup user-settings]
+(defn- setup-3d-nav
+  "Custom 'setup' function which creates initial position
+  configuration and puts it to the state map."
+  [user-setup user-settings]
   (let [initial-state (-> user-settings
                           (select-keys [:straight :up :position])
                           (->> (merge (default-camera)))


(def ^:private space (keyword " "))

(defn- move [state event step-size]
  (let [{:keys [up straight]} (:navigation-3d state)]
    (if-let [dir (condp = (:key event)
                   :w straight

(ns quil.middlewares.navigation-3d
  (:require [quil.core :as q]))

(defn- default-position
  "Default position configuration. Check default configuration in
  'camera' function."
  []
  {:position [(/ (q/width) 2.0)
              (/ (q/height) 2.0)
              (/ (q/height) 2.0 (q/tan (/ (* q/PI 60.0) 360.0)))]
   :straight [0 0 -1]
   :up [0 1 0]})

(defn- rotate-by-axis-and-angle
  "Rotates vector v by angle with axis.
  Formula is taken from wiki:
  http://en.wikipedia.org/wiki/Rotation_matrix#Rotation_matrix_from_axis_and_angle"
  [v axis angle]
  (let [[a-x a-y a-z] axis
        [x y z] v
        cs (q/cos angle)
