diff org/test-creature.org @ 111:61d9c0e8d188

don't create useless touch-maps, add some eye stuf
author Robert McIntyre <rlm@mit.edu>
date Thu, 19 Jan 2012 08:09:15 -0700
parents f89f0b9ed2fe
children 128fa71ee188
line wrap: on
line diff
     1.1 --- a/org/test-creature.org	Thu Jan 19 07:22:40 2012 -0700
     1.2 +++ b/org/test-creature.org	Thu Jan 19 08:09:15 2012 -0700
     1.3 @@ -410,8 +410,6 @@
     1.4      (-> (.getAdditionalRenderState)
     1.5          (.setDepthTest false))))
     1.6  
     1.7 -
     1.8 -
     1.9  (defn colorful []
    1.10    (.getChild (worm-model) "worm-21"))
    1.11  
    1.12 @@ -628,40 +626,69 @@
    1.13          limit 0.1
    1.14          ;;results (CollisionResults.)
    1.15          ]
    1.16 -    (fn [node]
    1.17 -      (let [sensor-origins 
    1.18 -            (map
    1.19 -             #(map (partial local-to-world geo) %)
    1.20 -             feeler-coords)
    1.21 -            triangle-normals 
    1.22 -            (map (partial get-ray-direction geo)
    1.23 -                 tris)
    1.24 -            rays
    1.25 -             (flatten
    1.26 -              (map (fn [origins norm]
    1.27 -                     (map #(doto (Ray. % norm)
    1.28 +    (if (empty? (touch-topology geo))
    1.29 +      nil
    1.30 +      (fn [node]
    1.31 +        (let [sensor-origins 
    1.32 +              (map
    1.33 +               #(map (partial local-to-world geo) %)
    1.34 +               feeler-coords)
    1.35 +              triangle-normals 
    1.36 +              (map (partial get-ray-direction geo)
    1.37 +                   tris)
    1.38 +              rays
    1.39 +              (flatten
    1.40 +               (map (fn [origins norm]
    1.41 +                      (map #(doto (Ray. % norm)
    1.42                                (.setLimit limit)) origins))
    1.43 -                   sensor-origins triangle-normals))]
    1.44 -        (vector
    1.45 -         (touch-topology geo)
    1.46 -         (vec
    1.47 -          (for [ray rays]
    1.48 -            (do
    1.49 -              (let [results (CollisionResults.)]
    1.50 -                (.collideWith node ray results)
    1.51 -                (let [touch-objects
    1.52 -                      (set
    1.53 -                       (filter #(not (= geo %))
    1.54 -                               (map #(.getGeometry %) results)))]
    1.55 -                  (if (> (count touch-objects) 0)
    1.56 -                    1 0)))))))))))
    1.57 +                    sensor-origins triangle-normals))]
    1.58 +          (vector
    1.59 +           (touch-topology geo)
    1.60 +           (vec
    1.61 +            (for [ray rays]
    1.62 +              (do
    1.63 +                (let [results (CollisionResults.)]
    1.64 +                  (.collideWith node ray results)
    1.65 +                  (let [touch-objects
    1.66 +                        (set
    1.67 +                         (filter #(not (= geo %))
    1.68 +                                 (map #(.getGeometry %) results)))]
    1.69 +                    (if (> (count touch-objects) 0)
    1.70 +                      1 0))))))))))))
    1.71 +  
    1.72 +(defn touch [#^Node pieces]
    1.73 +  (filter (comp not nil?)
    1.74 +          (map enable-touch
    1.75 +               (filter #(isa? (class %) Geometry)
    1.76 +                       (node-seq pieces)))))
    1.77  
    1.78  
    1.79 +;; human eye transmits 62kb/s to brain Bandwidth is 8.75 Mb/s
    1.80 +;; http://en.wikipedia.org/wiki/Retina
    1.81  
    1.82 -(defn touch [#^Node pieces]
    1.83 -  (map enable-touch
    1.84 -       (filter #(isa? (class %) Geometry)
    1.85 -               (node-seq pieces))))
    1.86 +(defn test-eye  []
    1.87 +  (.getChild (worm-model) "worm-11"))
    1.88 +
    1.89 +
    1.90 +(defn retina-sensor-image
    1.91 +  "Return a map of pixel selection functions to BufferedImages
    1.92 +   describing the distribution of light-sensitive components on this
    1.93 +   geometry's surface. Each function creates an integer from the rgb
    1.94 +   values found in the pixel. :red, :green, :blue, :gray are already
    1.95 +   defined as extracting the red green blue and average components
    1.96 +   respectively."
    1.97 +   [#^Geometry eye]
    1.98 +   (if-let [eye-map (meta-data eye "eye")]
    1.99 +     (map-vals
   1.100 +      #(ImageToAwt/convert
   1.101 +        (.getImage (.loadTexture (asset-manager) %))
   1.102 +        false false 0)
   1.103 +      (read-string
   1.104 +       eye-map))))
   1.105 +
   1.106 +
   1.107 +
   1.108 +
   1.109  
   1.110  (defn debug-window
   1.111    "creates function that offers a debug view of sensor data"