 #_"This file is part of brevis.                                                                                                                                                 
                                                                                                                                                                                      
-    Ekman's Garden is free software: you can redistribute it and/or modify                                                                                                           
+    brevis is free software: you can redistribute it and/or modify                                                                                                           
     it under the terms of the GNU General Public License as published by                                                                                                             
     the Free Software Foundation, either version 3 of the License, or                                                                                                                
     (at your option) any later version.                                                                                                                                              
                                                                                                                                                                                      
-    Ekman's Garden is distributed in the hope that it will be useful,                                                                                                                
+    brevis is distributed in the hope that it will be useful,                                                                                                                
     but WITHOUT ANY WARRANTY; without even the implied warranty of                                                                                                                   
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                                                                                                    
     GNU General Public License for more details.                                                                                                                                     
                                                                                                                                                                                      
     You should have received a copy of the GNU General Public License                                                                                                                
-    along with Ekman's Garden.  If not, see <http://www.gnu.org/licenses/>.                                                                                                          
+    along with brevis.  If not, see <http://www.gnu.org/licenses/>.                                                                                                          
                                                                                                                                                                                      
 Copyright 2012, 2013 Kyle Harrington"     
 

(defn mouse-drag
  "Rotate the world."
  [[dx dy] _ button state]
  (def rads (/ (Math/PI) 180))
  (def thetaY (*(:rot-y state) rads))
  (def sY (sin thetaY))
  (def cY (cos thetaY))
  (def thetaX (* (:rot-x state) rads))
  (def sX (sin thetaX))
  (def cX (cos thetaX))
  
  (if @shift-key-down
    (cond 
      ; Rotate
      (= :left button)
      (assoc state
             :rot-x (+ (:rot-x state) dy)
             :rot-y (+ (:rot-y state) dx))
      (= :center button)
      (assoc state
             :shift-x (+ (:shift-x state) (* dx cY))
             :shift-y (- (:shift-y state) (* dy cX))
             :shift-z (+ (:shift-z state) (* dx sY))
             )
      ; Zoom
      (= :right button)
      (assoc state
             :shift-x (+ (:shift-x state) (* (/ dy 6) (* sY -1)))
             :shift-y (+ (:shift-y state) (* (/ dy 6) sX))
             :shift-z (+ (:shift-z state) (* (/ dy 6) cY))           
             ))))

(defn mouse-wheel
  "Respond to a mousewheel movement. dw is +/- depending on scroll-up or down."
  [dw state]
  (def rads (/ (Math/PI) 180))
  (def thetaY (*(:rot-y state) rads))
  (def sY (sin thetaY))
  (def cY (cos thetaY))
  (def thetaX (* (:rot-x state) rads))
  (def sX (sin thetaX))
  (def cX (cos thetaX))
  
  (assoc state
         :shift-z (+ (:shift-z state) (* (/ dw 6) cY))
         :shift-x (+ (:shift-x state) (* (/ dw 6) (* sY -1)))
         :shift-y (+ (:shift-y state) (* (/ dw 6) sX))
         ))

(defn mouse-move
  "Respond to a change in x,y position of the mouse."

  #_(reset! *update-handlers* {})
  (reset! *physics* nil)
  (reset! *objects* {}))

(defn disable-collisions "Disable collision detection." [] (reset! collisions-enabled false))
(defn enable-collisions "Enable collision detection." [] (reset! collisions-enabled true))

(defn disable-neighborhoods "Disable neighborhood detection." [] (reset! neighborhoods-enabled false))
(defn enable-neighborhoods "Enable neighborhood detection." [] (reset! neighborhoods-enabled true))

(defn start-gui 
  "Start the simulation with a GUI."
