changeset 170:1a00b4918529

removed vision-init-fns requirement; changed names
author Robert McIntyre <rlm@mit.edu>
date Sat, 04 Feb 2012 05:00:10 -0700
parents 94b79c191fc7
children 15bde60217aa
files org/test-creature.org org/vision.org
diffstat 2 files changed, 30 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
     1.1 --- a/org/test-creature.org	Sat Feb 04 04:23:32 2012 -0700
     1.2 +++ b/org/test-creature.org	Sat Feb 04 05:00:10 2012 -0700
     1.3 @@ -181,7 +181,7 @@
     1.4          creature (blender-creature thing)
     1.5          touch-nerves (touch creature)
     1.6          touch-debug-windows (map (fn [_] (debug-touch-window)) touch-nerves)
     1.7 -        [init-vision-fns vision-data] (vision creature)
     1.8 +        vision-data (vision! creature)
     1.9          vision-debug (map (fn [_] (debug-vision-window)) vision-data)
    1.10          me (sphere 0.5 :color ColorRGBA/Blue :physical? false)
    1.11          hearing-senses (hearing! creature)
    1.12 @@ -194,7 +194,8 @@
    1.13  
    1.14          muscle-fns (enable-muscles creature)
    1.15          ;; dream
    1.16 -
    1.17 +        fix-display (runonce
    1.18 +                     (fn [world] (add-camera! world (.getCamera world) no-op)))
    1.19          ]
    1.20      
    1.21      
    1.22 @@ -230,14 +231,14 @@
    1.23          (fn [world]
    1.24            (light-up-everything world)
    1.25            (enable-debug world)
    1.26 -          (dorun (map #(% world) init-vision-fns))
    1.27 +          ;;(dorun (map #(% world) init-vision-fns))
    1.28            ;;(dorun (map #(% world) init-hearing-fns))
    1.29            
    1.30            (add-camera! world
    1.31                     (add-eye! creature (test-eye))
    1.32                     (comp (view-image) BufferedImage!))
    1.33            
    1.34 -          (add-camera! world (.getCamera world) no-op)
    1.35 +          
    1.36            ;;(set-gravity world (Vector3f. 0 0 0))
    1.37            ;;(com.aurellem.capture.Capture/captureVideo
    1.38            ;; world (file-str "/home/r/proj/ai-videos/hand"))
    1.39 @@ -256,7 +257,7 @@
    1.40                  touch-debug-windows touch-nerves))
    1.41            
    1.42            (dorun
    1.43 -           (map #(%1 (%2))
    1.44 +           (map #(%1 (%2 world))
    1.45                  vision-debug vision-data))
    1.46            (dorun
    1.47             (map #(%1 (%2 world)) hearing-windows hearing-senses))
    1.48 @@ -264,7 +265,7 @@
    1.49            
    1.50            ;;(println-repl (vision-data))
    1.51            (.setLocalTranslation me (.getLocation (.getCamera world)))
    1.52 -          
    1.53 +          (fix-display world)
    1.54            
    1.55            )]
    1.56     ;;(let [timer (atom 0)]
     2.1 --- a/org/vision.org	Sat Feb 04 04:23:32 2012 -0700
     2.2 +++ b/org/vision.org	Sat Feb 04 05:00:10 2012 -0700
     2.3 @@ -7,7 +7,7 @@
     2.4  #+INCLUDE: ../../aurellem/org/level-0.org
     2.5  #+babel: :mkdirp yes :noweb yes :exports both
     2.6  
     2.7 -* Vision
     2.8 +* COMMENT Vision
     2.9  
    2.10  I want to make creatures with eyes. Each eye can be independely moved
    2.11  and should see its own version of the world depending on where it is.
    2.12 @@ -193,37 +193,43 @@
    2.13          (atom
    2.14           (BufferedImage. (.getWidth camera)
    2.15                           (.getHeight camera)
    2.16 -                         BufferedImage/TYPE_BYTE_BINARY))]
    2.17 -    [(fn [world]
    2.18 -       (add-camera!
    2.19 -        world camera
    2.20 -        (let [counter  (atom 0)]
    2.21 -          (fn [r fb bb bi]
    2.22 -            (if (zero? (rem (swap! counter inc) (inc skip)))
    2.23 -              (reset! vision-image (BufferedImage! r fb bb bi)))))))
    2.24 +                         BufferedImage/TYPE_BYTE_BINARY))
    2.25 +        register-eye!
    2.26 +        (runonce
    2.27 +         (fn [world]
    2.28 +           (add-camera!
    2.29 +            world camera
    2.30 +            (let [counter  (atom 0)]
    2.31 +              (fn [r fb bb bi]
    2.32 +                (if (zero? (rem (swap! counter inc) (inc skip)))
    2.33 +                  (reset! vision-image
    2.34 +                          (BufferedImage! r fb bb bi))))))))]
    2.35       (vec
    2.36        (map
    2.37         (fn [[key image]]
    2.38           (let [whites (white-coordinates image)
    2.39                 topology (vec (collapse whites))
    2.40                 mask (presets key)]
    2.41 -           (fn []
    2.42 +           (fn [world]
    2.43 +             (register-eye! world)
    2.44               (vector
    2.45                topology
    2.46                (vec 
    2.47                 (for [[x y] whites]
    2.48                   (bit-and
    2.49                    mask (.getRGB @vision-image x y))))))))
    2.50 -       retinal-map))]))
    2.51 +       retinal-map))))
    2.52  
    2.53 -(defn vision
    2.54 +
    2.55 +;; TODO maybe should add a viewport-manipulation function to
    2.56 +;; automatically change viewport settings, attach shadow filters, etc.
    2.57 +
    2.58 +(defn vision!
    2.59 +  "Returns a function which returns visual sensory data when called
    2.60 +   inside a running simulation"
    2.61    [#^Node creature & {skip :skip :or {skip 0}}]
    2.62    (reduce
    2.63 -   (fn [[init-a senses-a]
    2.64 -        [init-b senses-b]]
    2.65 -     [(conj init-a init-b)
    2.66 -      (into senses-a senses-b)])
    2.67 -   [[][]]      
    2.68 +   concat 
    2.69     (for [eye (eyes creature)]
    2.70       (vision-fn creature eye))))
    2.71