diff --git a/src/voxelburst/core.clj b/src/voxelburst/core.clj index 82ad0cf..d137659 100644 --- a/src/voxelburst/core.clj +++ b/src/voxelburst/core.clj @@ -2,6 +2,7 @@ (:require [clojure.java.io :as io] [clojure.string :as string] + [clojure.tools.trace :refer :all] ;;[thi.ng.geom.aabb :as a] [thi.ng.geom.core :as g] [thi.ng.geom.core.vector :refer [vec3]] @@ -64,8 +65,53 @@ (vec3 (+ x border) (+ y border) (+ z border)))] (svo/apply-voxels svo/set-at tree coll))) -(defn make-tree [] - (let [tree (svo/voxeltree 8 (double 1/2))] +;; {:pos v :vel v :rad r} + +(def gravity [1 1 1.2]) + +(defn next-pos + "Position at t+1" + [pos vel] + (mapv + pos vel)) + +(defn next-vel + "Velocity at t+1" + [vel] + (mapv * vel gravity)) + +(defn single-in-bounds? + "Is a single value in bounds?" + [v [lo hi]] + (and (>= v lo) (<= v hi))) + +(defn in-bounds? + "Is point inside the domain bounds?" + [p bounds] + (every? true? (map #(single-in-bounds? %1 %2) p bounds))) + +(deftrace next-point + "Return the next position and velocity, or nil if it falls outside + the domain bounds." + [pos vel bounds] + (let [next-pos (next-pos pos vel) + next-vel (next-vel vel)] + (when (in-bounds? next-pos bounds) + [next-pos next-vel]))) + +(defn trajectory + "Return the points of the trajectory from the initial point until + the point exits the domain." + [pos vel bounds] + (loop [pts [] + p pos + v vel] + (let [[next-pos next-vel] (next-point p v bounds)] + (if (not next-pos) + pts + (recur (conj pts next-pos) next-pos next-vel))))) + +(defn make-tree [size count] + (let [tree (svo/voxeltree size (double 1/2))] (svo/set-at tree (vec3 4 4 4)))) (defn write-ply @@ -77,5 +123,4 @@ (defn -main [& [name count grid-size resolution]] - (let [tree (make-tree)] - (write-ply name tree resolution))) + (write-ply name (make-tree) resolution))