diff --git a/.gitignore b/.gitignore index 114e85a..93af298 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,17 @@ -/pom.xml -*jar -/lib -/classes -/native -/.lein-failures -/checkouts -/.lein-deps-sum +# Taken from Github recommended gitignore file for Leiningen. +# https://raw.githubusercontent.com/github/gitignore/master/Leiningen.gitignore +# https://github.com/github/gitignore/blob/master/Leiningen.gitignore + +pom.xml +pom.xml.asc +*.jar +*.class +/lib/ +/classes/ +/target/ +/checkouts/ +.lein-deps-sum +.lein-repl-history +.lein-plugins/ +.lein-failures +.nrepl-port diff --git a/project.clj b/project.clj index 2d59ee1..ee17bb8 100644 --- a/project.clj +++ b/project.clj @@ -5,4 +5,9 @@ :main quilltest.balls - :warn-on-reflection true) + ;; :warn-on-reflection true + ;; DEPRECATED: https://github.com/technomancy/leiningen/blob/master/sample.project.clj + + :global-vars {*warn-on-reflection* true} + + ) diff --git a/src/quilltest/physics.clj b/src/quilltest/physics.clj index 8dddce7..d2af8dc 100644 --- a/src/quilltest/physics.clj +++ b/src/quilltest/physics.clj @@ -50,20 +50,27 @@ (defrecord RigidBody [mass position velocity]) + (defn approaching [r1 r2] (let [v1 (:velocity r1) - v2 (:velocity r2)] - (with-math (neg? (* v1 v2))))) + v2 (:velocity r2) + x1 (:position r1) + x2 (:position r2)] + (with-math (neg? (* (- x1 x2) (- v1 v2)))))) -(defn colliding? [r1 r2] - (and (approaching r1 r2) + +(defn distance [r1 r2] (let [x1 (:position r1) x2 (:position r2) [x1 y1] [(:x x1) (:y x1)] [x2 y2] [(:x x2) (:y x2)] - [dx dy] [(- x1 x2) (- y1 y2)] - distance (Math/sqrt (+ (* dy dy) (* dx dx)))] - (< distance 20)))) + [dx dy] [(- x1 x2) (- y1 y2)]] + (Math/sqrt (+ (* dy dy) (* dx dx))))) + + +(defn colliding? [r1 r2] + (and (approaching r1 r2) + (< (distance r1 r2) 20))) (defn collide "Elastically collides two rigid bodies, returning