diff --git a/src/voxelburst/core.clj b/src/voxelburst/core.clj index bbb1a4d..b3db4fb 100644 --- a/src/voxelburst/core.clj +++ b/src/voxelburst/core.clj @@ -46,8 +46,9 @@ ;;; trace ;;; -(def start-radius 2) -(def start-lifespan 20) +(def start-radius 3.0) +(def start-lifespan 100) +(def radius-step (/ start-radius start-lifespan)) (defrecord Trace [position velocity radius lifespan]) @@ -57,25 +58,27 @@ (defn update-trace [trace bounds] (let [t (Trace. (next-pos (:position trace) (:velocity trace)) (next-vel (:velocity trace)) - start-radius - (dec start-lifespan))] - (when (and (in-bounds? (:position t) bounds) + (- (:radius trace) radius-step) + (dec (:lifespan trace)))] + (if (and (in-bounds? (:position t) bounds) (> (:radius t) 0) (> (:lifespan t) 0)) - t))) + t + (do #_(println "died at " (:lifespan t)) + nil)))) ;;; ;;; physics ;;; -(def gravity [0 0 -0.2]) +(def gravity [0 0 -0.1]) (defn random-vel [] #_(mapv #(* 2 (- % 0.5)) (repeatedly 3 rand)) - (vector (* 2 (- (rand) 0.5)) - (* 2 (- (rand) 0.5)) - (* 4 (rand)))) + (vector (* 8 (- (rand) 0.5)) + (* 8 (- (rand) 0.5)) + (* 12 (rand)))) (defn next-pos "Position at t+1" @@ -99,19 +102,19 @@ (defn trace-trajectory [trace bounds] - (loop [pts [] + (loop [traces [] trace trace] (let [new-trace (update-trace trace bounds)] (if (not new-trace) - pts - (recur (conj pts (:position trace)) new-trace))))) + traces + (recur (conj traces trace) new-trace))))) -(defn trajectory-voxels [trajectory] - (reduce set/union (map #(sphere (round-point %) 3) trajectory))) +(defn trajectory-voxels [traces] + (reduce set/union (map #(sphere (round-point (:position %)) (:radius %)) traces))) (defn sample-trace [] - (let [bounds [[10 490][10 490][10 490]] - origin [250 250 250]] + (let [bounds [[10 990][10 990][10 990]] + origin [500 500 500]] (trajectory-voxels (trace-trajectory (new-trace origin) bounds)))) (defn sample-traces [count] @@ -127,7 +130,7 @@ ;;; (defn sample-tree [count] - (let [tree (svo/voxeltree 500 1.0) + (let [tree (svo/voxeltree 1000 1.0) trace (sample-traces count)] (svo/apply-voxels svo/set-at tree trace)))