changeset 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 0efa36180e8a
files org/sense.org org/vision.org
diffstat 2 files changed, 143 insertions(+), 46 deletions(-) [+]
line wrap: on
line diff
     1.1 --- a/org/sense.org	Fri Jul 20 13:14:22 2012 -0500
     1.2 +++ b/org/sense.org	Fri Jul 20 16:40:25 2012 -0500
     1.3 @@ -14,13 +14,21 @@
     1.4  
     1.5  #+name: blender-1
     1.6  #+begin_src clojure
     1.7 +(in-ns 'cortex.sense)
     1.8  (defn meta-data
     1.9    "Get the meta-data for a node created with blender."
    1.10    [blender-node key]
    1.11    (if-let [data (.getUserData blender-node "properties")]
    1.12 -    (.findValue data key) nil))
    1.13 +    ;; this part is to accomodate weird blender properties
    1.14 +    ;; as well as sensible clojure maps.
    1.15 +    (.findValue data key)
    1.16 +    (.getUserData blender-node key)))
    1.17 +
    1.18  #+end_src
    1.19  
    1.20 +#+results: blender-1
    1.21 +: #'cortex.sense/meta-data
    1.22 +
    1.23  Blender uses a different coordinate system than jMonkeyEngine so it
    1.24  is useful to be able to convert between the two. These only come into
    1.25  play when the meta-data of a node refers to a vector in the blender
    1.26 @@ -446,6 +454,8 @@
    1.27  
    1.28  #+name: test
    1.29  #+begin_src clojure 
    1.30 +(in-ns 'cortex.test.sense)
    1.31 +
    1.32  (defn test-bind-sense
    1.33    "Show a camera that stays in the same relative position to a blue
    1.34    cube."
    1.35 @@ -469,12 +479,14 @@
    1.36              (.setTimer world (RatchetTimer. 60))
    1.37              (if record?
    1.38                (Capture/captureVideo
    1.39 -               world (File. "/home/r/proj/cortex/render/bind-sense0")))
    1.40 +               world 
    1.41 +               (File. "/home/r/proj/cortex/render/bind-sense0")))
    1.42              (add-camera!
    1.43               world cam
    1.44 -             (comp (view-image
    1.45 -                    (if record?
    1.46 -                    (File. "/home/r/proj/cortex/render/bind-sense1")))
    1.47 +             (comp
    1.48 +              (view-image
    1.49 +               (if record?
    1.50 +                 (File. "/home/r/proj/cortex/render/bind-sense1")))
    1.51                     BufferedImage!))
    1.52              (add-camera! world (.getCamera world) no-op)))
    1.53          no-op))))
     2.1 --- a/org/vision.org	Fri Jul 20 13:14:22 2012 -0500
     2.2 +++ b/org/vision.org	Fri Jul 20 16:40:25 2012 -0500
     2.3 @@ -149,26 +149,34 @@
     2.4  
     2.5  (defn add-eye!
     2.6    "Create a Camera centered on the current position of 'eye which
     2.7 -   follows the closest physical node in 'creature and sends visual
     2.8 -   data to 'continuation. The camera will point in the X direction and
     2.9 -   use the Z vector as up as determined by the rotation of these
    2.10 -   vectors in blender coordinate space. Use XZY rotation for the node
    2.11 -   in blender."
    2.12 +   follows the closest physical node in 'creature. The camera will
    2.13 +   point in the X direction and use the Z vector as up as determined
    2.14 +   by the rotation of these vectors in blender coordinate space. Use
    2.15 +   XZY rotation for the node in blender."
    2.16    [#^Node creature #^Spatial eye]
    2.17    (let [target (closest-node creature eye)
    2.18 -        [cam-width cam-height] (eye-dimensions eye)
    2.19 +        [cam-width cam-height] 
    2.20 +        ;;[640 480] ;; graphics card on laptop doesn't support
    2.21 +                    ;; arbitray dimensions.
    2.22 +        (eye-dimensions eye)
    2.23          cam (Camera. cam-width cam-height)
    2.24          rot (.getWorldRotation eye)]
    2.25      (.setLocation cam (.getWorldTranslation eye))
    2.26      (.lookAtDirection
    2.27 -     cam                                ; this part is not a mistake and
    2.28 -     (.mult rot Vector3f/UNIT_X)        ; is consistent with using Z in
    2.29 -     (.mult rot Vector3f/UNIT_Y))       ; blender as the UP vector.
    2.30 +     cam                           ; this part is not a mistake and
    2.31 +     (.mult rot Vector3f/UNIT_X)   ; is consistent with using Z in
    2.32 +     (.mult rot Vector3f/UNIT_Y))  ; blender as the UP vector.
    2.33      (.setFrustumPerspective
    2.34 -     cam 45 (/ (.getWidth cam) (.getHeight cam)) 1 1000)
    2.35 +     cam (float 45)
    2.36 +     (float (/ (.getWidth cam) (.getHeight cam)))
    2.37 +     (float 1)
    2.38 +     (float 1000))
    2.39      (bind-sense target cam) cam))
    2.40  #+end_src
    2.41  
    2.42 +#+results: add-eye
    2.43 +: #'cortex.vision/add-eye!
    2.44 +
    2.45  Here, the camera is created based on metadata on the eye-node and
    2.46  attached to the nearest physical object with =bind-sense=
    2.47  ** The Retina
    2.48 @@ -280,6 +288,7 @@
    2.49  
    2.50  #+name: add-camera
    2.51  #+begin_src clojure
    2.52 +(in-ns 'cortex.vision)
    2.53  (defn add-camera!
    2.54    "Add a camera to the world, calling continuation on every frame
    2.55    produced." 
    2.56 @@ -295,6 +304,9 @@
    2.57        (.attachScene (.getRootNode world)))))
    2.58  #+end_src
    2.59  
    2.60 +#+results: add-camera
    2.61 +: #'cortex.vision/add-camera!
    2.62 +
    2.63  
    2.64  The eye's continuation function should register the viewport with the
    2.65  simulation the first time it is called, use the CPU to extract the
    2.66 @@ -545,6 +557,32 @@
    2.67    (comp #(change-color % color)
    2.68           (fire-cannon-ball)))
    2.69  
    2.70 +(defn gen-worm
    2.71 +  "create a creature acceptable for testing as a replacement for the
    2.72 +   worm."
    2.73 +  []
    2.74 +  (nodify
    2.75 +   "worm"
    2.76 +   [(nodify
    2.77 +     "eyes"
    2.78 +     [(doto
    2.79 +          (Node. "eye1")
    2.80 +        (.setLocalTranslation (Vector3f. 0 -1.1 0))
    2.81 +        (.setUserData
    2.82 +         
    2.83 +         "eye" 
    2.84 +         "(let [retina
    2.85 +                \"Models/test-creature/retina-small.png\"]
    2.86 +                {:all retina :red retina
    2.87 +                 :green retina :blue retina})"))])
    2.88 +    (box
    2.89 +     0.2 0.2 0.2
    2.90 +     :name "worm-segment"
    2.91 +     :position (Vector3f. 0 0 0)
    2.92 +     :color ColorRGBA/Orange)]))
    2.93 +
    2.94 +
    2.95 +
    2.96  (defn test-worm-vision 
    2.97    "Testing vision:
    2.98     You should see the worm suspended in mid-air, looking down at a
    2.99 @@ -557,13 +595,14 @@
   2.100       b  : fire blue-ball
   2.101       g  : fire green-ball
   2.102       <space> : fire white ball"
   2.103 -   
   2.104 +  
   2.105    ([] (test-worm-vision false))
   2.106    ([record?] 
   2.107       (let [the-worm (doto (worm)(body!))
   2.108 -           vision (vision! the-worm)
   2.109 +           ;;the-worm (gen-worm)
   2.110 +           ;;vision (vision! the-worm)
   2.111             ;;vision-display (view-vision)
   2.112 -           fix-display (gen-fix-display)
   2.113 +           ;;fix-display (gen-fix-display)
   2.114             me (sphere 0.5 :color ColorRGBA/Blue :physical? false)
   2.115             x-axis
   2.116             (box 1 0.01 0.01 :physical? false :color ColorRGBA/Red
   2.117 @@ -574,38 +613,84 @@
   2.118             z-axis
   2.119             (box 0.01 0.01 1 :physical? false :color ColorRGBA/Blue
   2.120                  :position (Vector3f. 0 -5 0))
   2.121 -           timer (RatchetTimer. 60)]
   2.122 +           timer (RatchetTimer. 60)
   2.123 +           ]
   2.124  
   2.125         (world
   2.126          (nodify [(floor) the-worm x-axis y-axis z-axis me])
   2.127 -        (assoc standard-debug-controls
   2.128 -          "key-r" (colored-cannon-ball ColorRGBA/Red)
   2.129 -          "key-b" (colored-cannon-ball ColorRGBA/Blue)
   2.130 -          "key-g" (colored-cannon-ball ColorRGBA/Green))
   2.131 +        standard-debug-controls
   2.132 +        ;;"key-r" (colored-cannon-ball ColorRGBA/Red)
   2.133 +        ;;"key-b" (colored-cannon-ball ColorRGBA/Blue)
   2.134 +        ;;"key-g" (colored-cannon-ball ColorRGBA/Green))
   2.135 +        
   2.136          (fn [world]
   2.137 -          (light-up-everything world)
   2.138 -          ;;(speed-up world)
   2.139 -          (.setTimer world timer)
   2.140 -          ;;(display-dilated-time world timer)
   2.141 -          ;; add a view from the worm's perspective
   2.142 -          (if record?
   2.143 -            (Capture/captureVideo
   2.144 +          (let  
   2.145 +              [eye-pos (Vector3f. 0 30 0)
   2.146 +               cam (doto
   2.147 +                       (.clone (.getCamera world))
   2.148 +                     (.setLocation eye-pos)
   2.149 +                     (.lookAt Vector3f/ZERO
   2.150 +                              Vector3f/UNIT_X))
   2.151 +               
   2.152 +               bad-cam (doto
   2.153 +                         ;;saved-cam
   2.154 +                         ;;(.clone (.getCamera world))
   2.155 +
   2.156 +                         (com.jme3.renderer.Camera. 640 480)
   2.157 +                         (.setFrustumPerspective
   2.158 +                          (float 45)
   2.159 +                          (float (/ 640 480))
   2.160 +                          (float 1)
   2.161 +                          (float 1000))
   2.162 +
   2.163 +                         (.setLocation eye-pos)
   2.164 +                         (.lookAt Vector3f/ZERO
   2.165 +                                  Vector3f/UNIT_X))
   2.166 +              
   2.167 +               bad-cam (add-eye! the-worm (first (eyes the-worm)))
   2.168 +               ]
   2.169 +
   2.170 +
   2.171 +            (light-up-everything world)
   2.172 +            ;;(speed-up world)
   2.173 +            (.setTimer world timer)
   2.174 +            ;;(display-dilated-time world timer)
   2.175 +            ;; add a view from the worm's perspective
   2.176 +            (if record?
   2.177 +              (Capture/captureVideo
   2.178 +               world
   2.179 +               (File.
   2.180 +                "/home/r/proj/cortex/render/worm-vision/main-view")))
   2.181 +            
   2.182 +            (bind-sense (last (node-seq the-worm)) cam)
   2.183 +            (bind-sense (last (node-seq the-worm)) bad-cam)
   2.184 +            
   2.185 +            (add-camera!
   2.186               world
   2.187 -             (File.
   2.188 -              "/home/r/proj/cortex/render/worm-vision/main-view")))
   2.189 -          
   2.190 -          (add-camera!
   2.191 -           world
   2.192 -           (add-eye! the-worm
   2.193 -                     (.getChild 
   2.194 -                      (.getChild the-worm "eyes") "eye"))
   2.195 -           (comp
   2.196 -            (view-image
   2.197 -             (if record?
   2.198 -               (File.
   2.199 -                "/home/r/proj/cortex/render/worm-vision/worm-view")))
   2.200 -            BufferedImage!))
   2.201 -          (set-gravity world Vector3f/ZERO))
   2.202 +             bad-cam
   2.203 +             (comp
   2.204 +              (view-image
   2.205 +               (if record?
   2.206 +                 (File.
   2.207 +                  "/home/r/proj/cortex/render/worm-vision/worm-view")))
   2.208 +              BufferedImage!))
   2.209 +            
   2.210 +            
   2.211 +
   2.212 +            (add-camera!
   2.213 +             world cam
   2.214 +             (comp
   2.215 +              (view-image
   2.216 +               (if record?
   2.217 +                 (File.
   2.218 +                  "/home/r/proj/cortex/render/worm-vision/worm-view")))
   2.219 +              BufferedImage!))
   2.220 +            (set-gravity world Vector3f/ZERO)
   2.221 +            (add-camera! world (.getCamera world) no-op)
   2.222 +
   2.223 +            (println-repl cam "\n" bad-cam)
   2.224 +            
   2.225 +            ))
   2.226          
   2.227          (fn [world _ ]
   2.228            (.setLocalTranslation me (.getLocation (.getCamera world)))
   2.229 @@ -613,7 +698,7 @@
   2.230            ;;  (map #(% world) vision)
   2.231            ;;  (if record?
   2.232            ;;    (File. "/home/r/proj/cortex/render/worm-vision")))
   2.233 -          (fix-display world)
   2.234 +          ;;(fix-display world)
   2.235            )))))
   2.236  #+end_src
   2.237