diff org/test-creature.org @ 110:f89f0b9ed2fe

changed touch image retrieval code to use meta-data in preparation for multiple sensor maps per object
author Robert McIntyre <rlm@mit.edu>
date Thu, 19 Jan 2012 07:22:40 -0700
parents c05d8d222166
children 61d9c0e8d188
line wrap: on
line diff
     1.1 --- a/org/test-creature.org	Mon Jan 16 03:19:15 2012 -0700
     1.2 +++ b/org/test-creature.org	Thu Jan 19 07:22:40 2012 -0700
     1.3 @@ -423,20 +423,17 @@
     1.4  ;; Every vertex has its own index as well.
     1.5  
     1.6  (defn tactile-sensor-image
     1.7 -  "Return the touch-sensor distribution image in ImagePlus format, or
     1.8 -   nil if it does not exist."
     1.9 +  "Return the touch-sensor distribution image in BufferedImage format,
    1.10 +   or nil if it does not exist."
    1.11    [#^Geometry obj]
    1.12 -  (let [mat (.getMaterial obj)]
    1.13 -    (if-let [texture-param
    1.14 -             (.getTextureParam
    1.15 -              mat
    1.16 -              MaterialHelper/TEXTURE_TYPE_DIFFUSE)]
    1.17 -      (let
    1.18 -          [texture
    1.19 -           (.getTextureValue texture-param)
    1.20 -           im (.getImage texture)]
    1.21 -        (ImageToAwt/convert im false false 0)))))
    1.22 -
    1.23 +  (if-let [image-path (meta-data obj "touch")]
    1.24 +    (ImageToAwt/convert
    1.25 +     (.getImage
    1.26 +      (.loadTexture
    1.27 +       (asset-manager)
    1.28 +       image-path))
    1.29 +    false false 0)))
    1.30 +     
    1.31  (import ij.process.ImageProcessor)
    1.32  (import java.awt.image.BufferedImage)
    1.33  
    1.34 @@ -707,18 +704,18 @@
    1.35       (enable-debug world)
    1.36       ;;(com.aurellem.capture.Capture/captureVideo
    1.37       ;; world (file-str "/home/r/proj/ai-videos/hand"))
    1.38 -     (.setTimer world (RatchetTimer. 60))
    1.39 -     (speed-up world)
    1.40 +     ;;(.setTimer world (RatchetTimer. 60))
    1.41 +     ;;(speed-up world)
    1.42       ;;(set-gravity world (Vector3f. 0 0 0))
    1.43       )
    1.44     (fn [world tpf]
    1.45       ;;(dorun 
    1.46       ;; (map #(%1 %2) touch-nerves (repeat (.getRootNode world))))
    1.47 -     
    1.48 +    
    1.49       (dorun
    1.50        (map #(%1 (%2 (.getRootNode world)))
    1.51 -           touch-debug-windows touch-nerves))
    1.52 -     
    1.53 +           touch-debug-windows touch-nerves)
    1.54 +     )
    1.55  
    1.56       )
    1.57     ;;(let [timer (atom 0)]
    1.58 @@ -741,40 +738,49 @@
    1.59  
    1.60  
    1.61  (defn collision-test []
    1.62 -  (let [a-radius 1 
    1.63 -        a-position (Vector3f. -0.25 3 0)
    1.64 -        b-radius 1
    1.65 -        b-position (Vector3f. 0.25 3 0)
    1.66 -
    1.67 -
    1.68 -        obj-a (box 1 1 1 :color ColorRGBA/Red
    1.69 -                      :position a-position
    1.70 -                      :physical? false)
    1.71 +  (let [b-radius 1
    1.72 +        b-position (Vector3f. 0 0 0)
    1.73          obj-b (box 1 1 1 :color ColorRGBA/Blue
    1.74                        :position b-position
    1.75 -                      :physical? false)
    1.76 -        node (nodify [obj-a obj-b])
    1.77 -        bounds-a (BoundingBox. a-position 1 1 1)
    1.78 -        bounds-b (BoundingBox. b-position 1 1 1)
    1.79 +                      :mass 0)
    1.80 +        node (nodify [obj-b])
    1.81 +        bounds-b
    1.82 +        (doto (Picture.)
    1.83 +          (.setHeight 50)
    1.84 +          (.setWidth 50)
    1.85 +          (.setImage (asset-manager)
    1.86 +                     "Models/creature1/hand.png"
    1.87 +                     false
    1.88 +          ))
    1.89 +        
    1.90 +        ;;(Ray. (Vector3f. 0 -5 0) (.normalize (Vector3f. 0 1 0)))
    1.91 +
    1.92 +        collisions
    1.93 +        (let [cr (CollisionResults.)]
    1.94 +          (.collideWith node bounds-b cr)
    1.95 +          (println (map #(.getContactPoint %) cr))
    1.96 +          cr)
    1.97 +
    1.98 +        ;;collision-points
    1.99 +        ;;(map #(sphere 0.1 :position (.getContactPoint %))
   1.100 +        ;;     collisions)
   1.101 +
   1.102 +        ;;node (nodify (conj collision-points obj-b))
   1.103 +        
   1.104          sim
   1.105          (world node
   1.106 -               {}
   1.107 +               {"key-space"
   1.108 +                (fn [_ value]
   1.109 +                  (if value
   1.110 +                    (let [cr (CollisionResults.)]
   1.111 +                      (.collideWith node bounds-b cr)
   1.112 +                      (println-repl (map #(.getContactPoint %) cr))
   1.113 +                      cr)))}
   1.114                 no-op
   1.115                 no-op)
   1.116  
   1.117          ]
   1.118 -    (.setBound (.getMesh obj-a) bounds-a)
   1.119 -    (.updateBound (.getMesh obj-a))
   1.120 -
   1.121 -    
   1.122 -    (.setBound (.getMesh obj-b) bounds-b)
   1.123 -    (.updateBound (.getMesh obj-b))
   1.124 -
   1.125 -
   1.126 -
   1.127 -    (let [cr (CollisionResults.)]
   1.128 -      (.collideWith node bounds-a cr)
   1.129 -      [cr sim])
   1.130 +    sim
   1.131      
   1.132  ))
   1.133