# HG changeset patch # User Robert McIntyre # Date 1328356810 25200 # Node ID 1a00b4918529e158bd4628dce39e8f44365e818e # Parent 94b79c191fc7f001386c25ac40422d939c4b3a00 removed vision-init-fns requirement; changed names diff -r 94b79c191fc7 -r 1a00b4918529 org/test-creature.org --- a/org/test-creature.org Sat Feb 04 04:23:32 2012 -0700 +++ b/org/test-creature.org Sat Feb 04 05:00:10 2012 -0700 @@ -181,7 +181,7 @@ creature (blender-creature thing) touch-nerves (touch creature) touch-debug-windows (map (fn [_] (debug-touch-window)) touch-nerves) - [init-vision-fns vision-data] (vision creature) + vision-data (vision! creature) vision-debug (map (fn [_] (debug-vision-window)) vision-data) me (sphere 0.5 :color ColorRGBA/Blue :physical? false) hearing-senses (hearing! creature) @@ -194,7 +194,8 @@ muscle-fns (enable-muscles creature) ;; dream - + fix-display (runonce + (fn [world] (add-camera! world (.getCamera world) no-op))) ] @@ -230,14 +231,14 @@ (fn [world] (light-up-everything world) (enable-debug world) - (dorun (map #(% world) init-vision-fns)) + ;;(dorun (map #(% world) init-vision-fns)) ;;(dorun (map #(% world) init-hearing-fns)) (add-camera! world (add-eye! creature (test-eye)) (comp (view-image) BufferedImage!)) - (add-camera! world (.getCamera world) no-op) + ;;(set-gravity world (Vector3f. 0 0 0)) ;;(com.aurellem.capture.Capture/captureVideo ;; world (file-str "/home/r/proj/ai-videos/hand")) @@ -256,7 +257,7 @@ touch-debug-windows touch-nerves)) (dorun - (map #(%1 (%2)) + (map #(%1 (%2 world)) vision-debug vision-data)) (dorun (map #(%1 (%2 world)) hearing-windows hearing-senses)) @@ -264,7 +265,7 @@ ;;(println-repl (vision-data)) (.setLocalTranslation me (.getLocation (.getCamera world))) - + (fix-display world) )] ;;(let [timer (atom 0)] diff -r 94b79c191fc7 -r 1a00b4918529 org/vision.org --- a/org/vision.org Sat Feb 04 04:23:32 2012 -0700 +++ b/org/vision.org Sat Feb 04 05:00:10 2012 -0700 @@ -7,7 +7,7 @@ #+INCLUDE: ../../aurellem/org/level-0.org #+babel: :mkdirp yes :noweb yes :exports both -* Vision +* COMMENT Vision I want to make creatures with eyes. Each eye can be independely moved and should see its own version of the world depending on where it is. @@ -193,37 +193,43 @@ (atom (BufferedImage. (.getWidth camera) (.getHeight camera) - BufferedImage/TYPE_BYTE_BINARY))] - [(fn [world] - (add-camera! - world camera - (let [counter (atom 0)] - (fn [r fb bb bi] - (if (zero? (rem (swap! counter inc) (inc skip))) - (reset! vision-image (BufferedImage! r fb bb bi))))))) + BufferedImage/TYPE_BYTE_BINARY)) + register-eye! + (runonce + (fn [world] + (add-camera! + world camera + (let [counter (atom 0)] + (fn [r fb bb bi] + (if (zero? (rem (swap! counter inc) (inc skip))) + (reset! vision-image + (BufferedImage! r fb bb bi))))))))] (vec (map (fn [[key image]] (let [whites (white-coordinates image) topology (vec (collapse whites)) mask (presets key)] - (fn [] + (fn [world] + (register-eye! world) (vector topology (vec (for [[x y] whites] (bit-and mask (.getRGB @vision-image x y)))))))) - retinal-map))])) + retinal-map)))) -(defn vision + +;; TODO maybe should add a viewport-manipulation function to +;; automatically change viewport settings, attach shadow filters, etc. + +(defn vision! + "Returns a function which returns visual sensory data when called + inside a running simulation" [#^Node creature & {skip :skip :or {skip 0}}] (reduce - (fn [[init-a senses-a] - [init-b senses-b]] - [(conj init-a init-b) - (into senses-a senses-b)]) - [[][]] + concat (for [eye (eyes creature)] (vision-fn creature eye))))