Skip to content
25 changes: 17 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
7 changes: 6 additions & 1 deletion project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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}

)
21 changes: 14 additions & 7 deletions src/quilltest/physics.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down