Skip to content

Commit

Permalink
[physics] add :timestep & :iter listener support to VerletPhysics
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Mar 29, 2015
1 parent 363dddf commit 4772c08
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions geom-physics/src/core.org
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@

#+BEGIN_SRC clojure :noweb-ref impl
(defrecord VerletPhysics
[particles springs behaviors constraints drag]
[particles springs behaviors constraints listeners drag]
PBehavioral
(add-behaviors
[_ bmap] (update-in _ [:behaviors] merge bmap))
Expand Down Expand Up @@ -236,8 +236,10 @@
(timestep
[_ iter]
(let [delta (/ 1.0 iter)]
(if-let [l (:timestep listeners)] (l _))
(loop [i iter]
(when (pos? i)
(if-let [l (:iter listeners)] (l _ i))
(-> (apply-behaviors _ delta)
(update-springs delta)
(update-particles delta)
Expand Down Expand Up @@ -306,10 +308,11 @@

#+BEGIN_SRC clojure :noweb-ref ctors
(defn physics
[{:keys [particles springs behaviors constraints drag]
:or {particles #{}, springs #{}, behaviors {}, constraints {}, drag 0.0}}]
[{:keys [particles springs behaviors constraints drag listeners]
:or {particles #{}, springs #{}, behaviors {}, constraints {}
listeners {}, drag 0.0}}]
(VerletPhysics.
(set particles) (set springs) behaviors constraints drag))
(set particles) (set springs) behaviors constraints listeners drag))

(defn particle
[pos & [weight lock?]]
Expand Down

0 comments on commit 4772c08

Please sign in to comment.