diff org/vision.org @ 338:d37ccb6c888f

determined that the laptop cannot support arbitray dimensions when creating cameras. will need to use desktop from here on out when doing actual simulations.
author Robert McIntyre <rlm@mit.edu>
date Fri, 20 Jul 2012 16:40:25 -0500
parents fdc98824d69b
children 4f5a5d5f1613
line wrap: on
line diff
     1.1 --- a/org/vision.org	Fri Jul 20 13:14:22 2012 -0500
     1.2 +++ b/org/vision.org	Fri Jul 20 16:40:25 2012 -0500
     1.3 @@ -149,26 +149,34 @@
     1.4  
     1.5  (defn add-eye!
     1.6    "Create a Camera centered on the current position of 'eye which
     1.7 -   follows the closest physical node in 'creature and sends visual
     1.8 -   data to 'continuation. The camera will point in the X direction and
     1.9 -   use the Z vector as up as determined by the rotation of these
    1.10 -   vectors in blender coordinate space. Use XZY rotation for the node
    1.11 -   in blender."
    1.12 +   follows the closest physical node in 'creature. The camera will
    1.13 +   point in the X direction and use the Z vector as up as determined
    1.14 +   by the rotation of these vectors in blender coordinate space. Use
    1.15 +   XZY rotation for the node in blender."
    1.16    [#^Node creature #^Spatial eye]
    1.17    (let [target (closest-node creature eye)
    1.18 -        [cam-width cam-height] (eye-dimensions eye)
    1.19 +        [cam-width cam-height] 
    1.20 +        ;;[640 480] ;; graphics card on laptop doesn't support
    1.21 +                    ;; arbitray dimensions.
    1.22 +        (eye-dimensions eye)
    1.23          cam (Camera. cam-width cam-height)
    1.24          rot (.getWorldRotation eye)]
    1.25      (.setLocation cam (.getWorldTranslation eye))
    1.26      (.lookAtDirection
    1.27 -     cam                                ; this part is not a mistake and
    1.28 -     (.mult rot Vector3f/UNIT_X)        ; is consistent with using Z in
    1.29 -     (.mult rot Vector3f/UNIT_Y))       ; blender as the UP vector.
    1.30 +     cam                           ; this part is not a mistake and
    1.31 +     (.mult rot Vector3f/UNIT_X)   ; is consistent with using Z in
    1.32 +     (.mult rot Vector3f/UNIT_Y))  ; blender as the UP vector.
    1.33      (.setFrustumPerspective
    1.34 -     cam 45 (/ (.getWidth cam) (.getHeight cam)) 1 1000)
    1.35 +     cam (float 45)
    1.36 +     (float (/ (.getWidth cam) (.getHeight cam)))
    1.37 +     (float 1)
    1.38 +     (float 1000))
    1.39      (bind-sense target cam) cam))
    1.40  #+end_src
    1.41  
    1.42 +#+results: add-eye
    1.43 +: #'cortex.vision/add-eye!
    1.44 +
    1.45  Here, the camera is created based on metadata on the eye-node and
    1.46  attached to the nearest physical object with =bind-sense=
    1.47  ** The Retina
    1.48 @@ -280,6 +288,7 @@
    1.49  
    1.50  #+name: add-camera
    1.51  #+begin_src clojure
    1.52 +(in-ns 'cortex.vision)
    1.53  (defn add-camera!
    1.54    "Add a camera to the world, calling continuation on every frame
    1.55    produced." 
    1.56 @@ -295,6 +304,9 @@
    1.57        (.attachScene (.getRootNode world)))))
    1.58  #+end_src
    1.59  
    1.60 +#+results: add-camera
    1.61 +: #'cortex.vision/add-camera!
    1.62 +
    1.63  
    1.64  The eye's continuation function should register the viewport with the
    1.65  simulation the first time it is called, use the CPU to extract the
    1.66 @@ -545,6 +557,32 @@
    1.67    (comp #(change-color % color)
    1.68           (fire-cannon-ball)))
    1.69  
    1.70 +(defn gen-worm
    1.71 +  "create a creature acceptable for testing as a replacement for the
    1.72 +   worm."
    1.73 +  []
    1.74 +  (nodify
    1.75 +   "worm"
    1.76 +   [(nodify
    1.77 +     "eyes"
    1.78 +     [(doto
    1.79 +          (Node. "eye1")
    1.80 +        (.setLocalTranslation (Vector3f. 0 -1.1 0))
    1.81 +        (.setUserData
    1.82 +         
    1.83 +         "eye" 
    1.84 +         "(let [retina
    1.85 +                \"Models/test-creature/retina-small.png\"]
    1.86 +                {:all retina :red retina
    1.87 +                 :green retina :blue retina})"))])
    1.88 +    (box
    1.89 +     0.2 0.2 0.2
    1.90 +     :name "worm-segment"
    1.91 +     :position (Vector3f. 0 0 0)
    1.92 +     :color ColorRGBA/Orange)]))
    1.93 +
    1.94 +
    1.95 +
    1.96  (defn test-worm-vision 
    1.97    "Testing vision:
    1.98     You should see the worm suspended in mid-air, looking down at a
    1.99 @@ -557,13 +595,14 @@
   1.100       b  : fire blue-ball
   1.101       g  : fire green-ball
   1.102       <space> : fire white ball"
   1.103 -   
   1.104 +  
   1.105    ([] (test-worm-vision false))
   1.106    ([record?] 
   1.107       (let [the-worm (doto (worm)(body!))
   1.108 -           vision (vision! the-worm)
   1.109 +           ;;the-worm (gen-worm)
   1.110 +           ;;vision (vision! the-worm)
   1.111             ;;vision-display (view-vision)
   1.112 -           fix-display (gen-fix-display)
   1.113 +           ;;fix-display (gen-fix-display)
   1.114             me (sphere 0.5 :color ColorRGBA/Blue :physical? false)
   1.115             x-axis
   1.116             (box 1 0.01 0.01 :physical? false :color ColorRGBA/Red
   1.117 @@ -574,38 +613,84 @@
   1.118             z-axis
   1.119             (box 0.01 0.01 1 :physical? false :color ColorRGBA/Blue
   1.120                  :position (Vector3f. 0 -5 0))
   1.121 -           timer (RatchetTimer. 60)]
   1.122 +           timer (RatchetTimer. 60)
   1.123 +           ]
   1.124  
   1.125         (world
   1.126          (nodify [(floor) the-worm x-axis y-axis z-axis me])
   1.127 -        (assoc standard-debug-controls
   1.128 -          "key-r" (colored-cannon-ball ColorRGBA/Red)
   1.129 -          "key-b" (colored-cannon-ball ColorRGBA/Blue)
   1.130 -          "key-g" (colored-cannon-ball ColorRGBA/Green))
   1.131 +        standard-debug-controls
   1.132 +        ;;"key-r" (colored-cannon-ball ColorRGBA/Red)
   1.133 +        ;;"key-b" (colored-cannon-ball ColorRGBA/Blue)
   1.134 +        ;;"key-g" (colored-cannon-ball ColorRGBA/Green))
   1.135 +        
   1.136          (fn [world]
   1.137 -          (light-up-everything world)
   1.138 -          ;;(speed-up world)
   1.139 -          (.setTimer world timer)
   1.140 -          ;;(display-dilated-time world timer)
   1.141 -          ;; add a view from the worm's perspective
   1.142 -          (if record?
   1.143 -            (Capture/captureVideo
   1.144 +          (let  
   1.145 +              [eye-pos (Vector3f. 0 30 0)
   1.146 +               cam (doto
   1.147 +                       (.clone (.getCamera world))
   1.148 +                     (.setLocation eye-pos)
   1.149 +                     (.lookAt Vector3f/ZERO
   1.150 +                              Vector3f/UNIT_X))
   1.151 +               
   1.152 +               bad-cam (doto
   1.153 +                         ;;saved-cam
   1.154 +                         ;;(.clone (.getCamera world))
   1.155 +
   1.156 +                         (com.jme3.renderer.Camera. 640 480)
   1.157 +                         (.setFrustumPerspective
   1.158 +                          (float 45)
   1.159 +                          (float (/ 640 480))
   1.160 +                          (float 1)
   1.161 +                          (float 1000))
   1.162 +
   1.163 +                         (.setLocation eye-pos)
   1.164 +                         (.lookAt Vector3f/ZERO
   1.165 +                                  Vector3f/UNIT_X))
   1.166 +              
   1.167 +               bad-cam (add-eye! the-worm (first (eyes the-worm)))
   1.168 +               ]
   1.169 +
   1.170 +
   1.171 +            (light-up-everything world)
   1.172 +            ;;(speed-up world)
   1.173 +            (.setTimer world timer)
   1.174 +            ;;(display-dilated-time world timer)
   1.175 +            ;; add a view from the worm's perspective
   1.176 +            (if record?
   1.177 +              (Capture/captureVideo
   1.178 +               world
   1.179 +               (File.
   1.180 +                "/home/r/proj/cortex/render/worm-vision/main-view")))
   1.181 +            
   1.182 +            (bind-sense (last (node-seq the-worm)) cam)
   1.183 +            (bind-sense (last (node-seq the-worm)) bad-cam)
   1.184 +            
   1.185 +            (add-camera!
   1.186               world
   1.187 -             (File.
   1.188 -              "/home/r/proj/cortex/render/worm-vision/main-view")))
   1.189 -          
   1.190 -          (add-camera!
   1.191 -           world
   1.192 -           (add-eye! the-worm
   1.193 -                     (.getChild 
   1.194 -                      (.getChild the-worm "eyes") "eye"))
   1.195 -           (comp
   1.196 -            (view-image
   1.197 -             (if record?
   1.198 -               (File.
   1.199 -                "/home/r/proj/cortex/render/worm-vision/worm-view")))
   1.200 -            BufferedImage!))
   1.201 -          (set-gravity world Vector3f/ZERO))
   1.202 +             bad-cam
   1.203 +             (comp
   1.204 +              (view-image
   1.205 +               (if record?
   1.206 +                 (File.
   1.207 +                  "/home/r/proj/cortex/render/worm-vision/worm-view")))
   1.208 +              BufferedImage!))
   1.209 +            
   1.210 +            
   1.211 +
   1.212 +            (add-camera!
   1.213 +             world cam
   1.214 +             (comp
   1.215 +              (view-image
   1.216 +               (if record?
   1.217 +                 (File.
   1.218 +                  "/home/r/proj/cortex/render/worm-vision/worm-view")))
   1.219 +              BufferedImage!))
   1.220 +            (set-gravity world Vector3f/ZERO)
   1.221 +            (add-camera! world (.getCamera world) no-op)
   1.222 +
   1.223 +            (println-repl cam "\n" bad-cam)
   1.224 +            
   1.225 +            ))
   1.226          
   1.227          (fn [world _ ]
   1.228            (.setLocalTranslation me (.getLocation (.getCamera world)))
   1.229 @@ -613,7 +698,7 @@
   1.230            ;;  (map #(% world) vision)
   1.231            ;;  (if record?
   1.232            ;;    (File. "/home/r/proj/cortex/render/worm-vision")))
   1.233 -          (fix-display world)
   1.234 +          ;;(fix-display world)
   1.235            )))))
   1.236  #+end_src
   1.237