 (defn render
   []
   (motion-tick!)
-  ;(handle-collisions!)
+  (handle-collisions!)
 
   (doseq [i (range (count @particles))]
     (let [p (nth @particles i)
           m (nth @particle-meshes i)]
+      ;; static rotation for blinginess
+      (rotate-angles! m [0 2 0])
       (set-position! m (:pos p))))
 
   (render-scene))

  (let [a (calc-accel p all)
        v (map + v a)
        magv (magnitude v)
        v (if (> magv velocity-limit)
            (map #(* (/ % magv) vel-limit) v)
            v)
        p (map + p v)]
    [p v a]))

(ns physim.core
  (:require [THREE :as THREE]))

(def particle-count 10)
(def gravity-multiplier 100)
(def speed-limit 5)
(def initial-speed 0)

(def scene-width window/innerWidth)
(def scene-height window/innerHeight)

(def particles (atom []))
(def particle-meshes (atom []))
(def collided-particles (atom {}))

(defn rand-x
  []
  (- (rand-int scene-width)
     (/ scene-width 2)))

(defn rand-y
  []
  (- (rand-int scene-height)
     (/ scene-height 2)))

(defn generate-particles
  [n]
  (for [i (range n)]
    { :pos [(rand-x) (rand-y) (rand-y)]
      :vel [(/ (* initial-speed (rand-x)) scene-width)
            (/ (* initial-speed (rand-y)) scene-width)
            (/ (* initial-speed (rand-y)) scene-width)] }))

(defn set-position!
  [mesh [x y z]]
  (set! (.-x (.-position mesh)) x)
  (set! (.-y (.-position mesh)) y)
  (set! (.-z (.-position mesh)) z))

(defn rotate-angles!
  [mesh [x y z]]
  (set! (.-x (.-rotation mesh)) (+ (.-x (.-rotation mesh)) x))
  (set! (.-y (.-rotation mesh)) (+ (.-y (.-rotation mesh)) y))
  (set! (.-z (.-rotation mesh)) (+ (.-z (.-rotation mesh)) z)))

(defn mesh-from-particle
  [p]
