changeset 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
files assets/Models/creature1/try-again.blend org/test-creature.org
diffstat 2 files changed, 59 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
     1.1 Binary file assets/Models/creature1/try-again.blend has changed
     2.1 --- a/org/test-creature.org	Thu Jan 19 07:22:40 2012 -0700
     2.2 +++ b/org/test-creature.org	Thu Jan 19 08:09:15 2012 -0700
     2.3 @@ -410,8 +410,6 @@
     2.4      (-> (.getAdditionalRenderState)
     2.5          (.setDepthTest false))))
     2.6  
     2.7 -
     2.8 -
     2.9  (defn colorful []
    2.10    (.getChild (worm-model) "worm-21"))
    2.11  
    2.12 @@ -628,40 +626,69 @@
    2.13          limit 0.1
    2.14          ;;results (CollisionResults.)
    2.15          ]
    2.16 -    (fn [node]
    2.17 -      (let [sensor-origins 
    2.18 -            (map
    2.19 -             #(map (partial local-to-world geo) %)
    2.20 -             feeler-coords)
    2.21 -            triangle-normals 
    2.22 -            (map (partial get-ray-direction geo)
    2.23 -                 tris)
    2.24 -            rays
    2.25 -             (flatten
    2.26 -              (map (fn [origins norm]
    2.27 -                     (map #(doto (Ray. % norm)
    2.28 +    (if (empty? (touch-topology geo))
    2.29 +      nil
    2.30 +      (fn [node]
    2.31 +        (let [sensor-origins 
    2.32 +              (map
    2.33 +               #(map (partial local-to-world geo) %)
    2.34 +               feeler-coords)
    2.35 +              triangle-normals 
    2.36 +              (map (partial get-ray-direction geo)
    2.37 +                   tris)
    2.38 +              rays
    2.39 +              (flatten
    2.40 +               (map (fn [origins norm]
    2.41 +                      (map #(doto (Ray. % norm)
    2.42                                (.setLimit limit)) origins))
    2.43 -                   sensor-origins triangle-normals))]
    2.44 -        (vector
    2.45 -         (touch-topology geo)
    2.46 -         (vec
    2.47 -          (for [ray rays]
    2.48 -            (do
    2.49 -              (let [results (CollisionResults.)]
    2.50 -                (.collideWith node ray results)
    2.51 -                (let [touch-objects
    2.52 -                      (set
    2.53 -                       (filter #(not (= geo %))
    2.54 -                               (map #(.getGeometry %) results)))]
    2.55 -                  (if (> (count touch-objects) 0)
    2.56 -                    1 0)))))))))))
    2.57 +                    sensor-origins triangle-normals))]
    2.58 +          (vector
    2.59 +           (touch-topology geo)
    2.60 +           (vec
    2.61 +            (for [ray rays]
    2.62 +              (do
    2.63 +                (let [results (CollisionResults.)]
    2.64 +                  (.collideWith node ray results)
    2.65 +                  (let [touch-objects
    2.66 +                        (set
    2.67 +                         (filter #(not (= geo %))
    2.68 +                                 (map #(.getGeometry %) results)))]
    2.69 +                    (if (> (count touch-objects) 0)
    2.70 +                      1 0))))))))))))
    2.71 +  
    2.72 +(defn touch [#^Node pieces]
    2.73 +  (filter (comp not nil?)
    2.74 +          (map enable-touch
    2.75 +               (filter #(isa? (class %) Geometry)
    2.76 +                       (node-seq pieces)))))
    2.77  
    2.78  
    2.79 +;; human eye transmits 62kb/s to brain Bandwidth is 8.75 Mb/s
    2.80 +;; http://en.wikipedia.org/wiki/Retina
    2.81  
    2.82 -(defn touch [#^Node pieces]
    2.83 -  (map enable-touch
    2.84 -       (filter #(isa? (class %) Geometry)
    2.85 -               (node-seq pieces))))
    2.86 +(defn test-eye  []
    2.87 +  (.getChild (worm-model) "worm-11"))
    2.88 +
    2.89 +
    2.90 +(defn retina-sensor-image
    2.91 +  "Return a map of pixel selection functions to BufferedImages
    2.92 +   describing the distribution of light-sensitive components on this
    2.93 +   geometry's surface. Each function creates an integer from the rgb
    2.94 +   values found in the pixel. :red, :green, :blue, :gray are already
    2.95 +   defined as extracting the red green blue and average components
    2.96 +   respectively."
    2.97 +   [#^Geometry eye]
    2.98 +   (if-let [eye-map (meta-data eye "eye")]
    2.99 +     (map-vals
   2.100 +      #(ImageToAwt/convert
   2.101 +        (.getImage (.loadTexture (asset-manager) %))
   2.102 +        false false 0)
   2.103 +      (read-string
   2.104 +       eye-map))))
   2.105 +
   2.106 +
   2.107 +
   2.108 +
   2.109  
   2.110  (defn debug-window
   2.111    "creates function that offers a debug view of sensor data"