# HG changeset patch # User Robert McIntyre # Date 1342820425 18000 # Node ID d37ccb6c888fb787bcb6e75aec031475c7c06314 # Parent fdc98824d69bab85c57ae3fc862cbb8d9351057c determined that the laptop cannot support arbitray dimensions when creating cameras. will need to use desktop from here on out when doing actual simulations. diff -r fdc98824d69b -r d37ccb6c888f org/sense.org --- a/org/sense.org Fri Jul 20 13:14:22 2012 -0500 +++ b/org/sense.org Fri Jul 20 16:40:25 2012 -0500 @@ -14,13 +14,21 @@ #+name: blender-1 #+begin_src clojure +(in-ns 'cortex.sense) (defn meta-data "Get the meta-data for a node created with blender." [blender-node key] (if-let [data (.getUserData blender-node "properties")] - (.findValue data key) nil)) + ;; this part is to accomodate weird blender properties + ;; as well as sensible clojure maps. + (.findValue data key) + (.getUserData blender-node key))) + #+end_src +#+results: blender-1 +: #'cortex.sense/meta-data + Blender uses a different coordinate system than jMonkeyEngine so it is useful to be able to convert between the two. These only come into play when the meta-data of a node refers to a vector in the blender @@ -446,6 +454,8 @@ #+name: test #+begin_src clojure +(in-ns 'cortex.test.sense) + (defn test-bind-sense "Show a camera that stays in the same relative position to a blue cube." @@ -469,12 +479,14 @@ (.setTimer world (RatchetTimer. 60)) (if record? (Capture/captureVideo - world (File. "/home/r/proj/cortex/render/bind-sense0"))) + world + (File. "/home/r/proj/cortex/render/bind-sense0"))) (add-camera! world cam - (comp (view-image - (if record? - (File. "/home/r/proj/cortex/render/bind-sense1"))) + (comp + (view-image + (if record? + (File. "/home/r/proj/cortex/render/bind-sense1"))) BufferedImage!)) (add-camera! world (.getCamera world) no-op))) no-op)))) diff -r fdc98824d69b -r d37ccb6c888f org/vision.org --- a/org/vision.org Fri Jul 20 13:14:22 2012 -0500 +++ b/org/vision.org Fri Jul 20 16:40:25 2012 -0500 @@ -149,26 +149,34 @@ (defn add-eye! "Create a Camera centered on the current position of 'eye which - follows the closest physical node in 'creature and sends visual - data to 'continuation. The camera will point in the X direction and - use the Z vector as up as determined by the rotation of these - vectors in blender coordinate space. Use XZY rotation for the node - in blender." + follows the closest physical node in 'creature. The camera will + point in the X direction and use the Z vector as up as determined + by the rotation of these vectors in blender coordinate space. Use + XZY rotation for the node in blender." [#^Node creature #^Spatial eye] (let [target (closest-node creature eye) - [cam-width cam-height] (eye-dimensions eye) + [cam-width cam-height] + ;;[640 480] ;; graphics card on laptop doesn't support + ;; arbitray dimensions. + (eye-dimensions eye) cam (Camera. cam-width cam-height) rot (.getWorldRotation eye)] (.setLocation cam (.getWorldTranslation eye)) (.lookAtDirection - cam ; this part is not a mistake and - (.mult rot Vector3f/UNIT_X) ; is consistent with using Z in - (.mult rot Vector3f/UNIT_Y)) ; blender as the UP vector. + cam ; this part is not a mistake and + (.mult rot Vector3f/UNIT_X) ; is consistent with using Z in + (.mult rot Vector3f/UNIT_Y)) ; blender as the UP vector. (.setFrustumPerspective - cam 45 (/ (.getWidth cam) (.getHeight cam)) 1 1000) + cam (float 45) + (float (/ (.getWidth cam) (.getHeight cam))) + (float 1) + (float 1000)) (bind-sense target cam) cam)) #+end_src +#+results: add-eye +: #'cortex.vision/add-eye! + Here, the camera is created based on metadata on the eye-node and attached to the nearest physical object with =bind-sense= ** The Retina @@ -280,6 +288,7 @@ #+name: add-camera #+begin_src clojure +(in-ns 'cortex.vision) (defn add-camera! "Add a camera to the world, calling continuation on every frame produced." @@ -295,6 +304,9 @@ (.attachScene (.getRootNode world))))) #+end_src +#+results: add-camera +: #'cortex.vision/add-camera! + The eye's continuation function should register the viewport with the simulation the first time it is called, use the CPU to extract the @@ -545,6 +557,32 @@ (comp #(change-color % color) (fire-cannon-ball))) +(defn gen-worm + "create a creature acceptable for testing as a replacement for the + worm." + [] + (nodify + "worm" + [(nodify + "eyes" + [(doto + (Node. "eye1") + (.setLocalTranslation (Vector3f. 0 -1.1 0)) + (.setUserData + + "eye" + "(let [retina + \"Models/test-creature/retina-small.png\"] + {:all retina :red retina + :green retina :blue retina})"))]) + (box + 0.2 0.2 0.2 + :name "worm-segment" + :position (Vector3f. 0 0 0) + :color ColorRGBA/Orange)])) + + + (defn test-worm-vision "Testing vision: You should see the worm suspended in mid-air, looking down at a @@ -557,13 +595,14 @@ b : fire blue-ball g : fire green-ball : fire white ball" - + ([] (test-worm-vision false)) ([record?] (let [the-worm (doto (worm)(body!)) - vision (vision! the-worm) + ;;the-worm (gen-worm) + ;;vision (vision! the-worm) ;;vision-display (view-vision) - fix-display (gen-fix-display) + ;;fix-display (gen-fix-display) me (sphere 0.5 :color ColorRGBA/Blue :physical? false) x-axis (box 1 0.01 0.01 :physical? false :color ColorRGBA/Red @@ -574,38 +613,84 @@ z-axis (box 0.01 0.01 1 :physical? false :color ColorRGBA/Blue :position (Vector3f. 0 -5 0)) - timer (RatchetTimer. 60)] + timer (RatchetTimer. 60) + ] (world (nodify [(floor) the-worm x-axis y-axis z-axis me]) - (assoc standard-debug-controls - "key-r" (colored-cannon-ball ColorRGBA/Red) - "key-b" (colored-cannon-ball ColorRGBA/Blue) - "key-g" (colored-cannon-ball ColorRGBA/Green)) + standard-debug-controls + ;;"key-r" (colored-cannon-ball ColorRGBA/Red) + ;;"key-b" (colored-cannon-ball ColorRGBA/Blue) + ;;"key-g" (colored-cannon-ball ColorRGBA/Green)) + (fn [world] - (light-up-everything world) - ;;(speed-up world) - (.setTimer world timer) - ;;(display-dilated-time world timer) - ;; add a view from the worm's perspective - (if record? - (Capture/captureVideo + (let + [eye-pos (Vector3f. 0 30 0) + cam (doto + (.clone (.getCamera world)) + (.setLocation eye-pos) + (.lookAt Vector3f/ZERO + Vector3f/UNIT_X)) + + bad-cam (doto + ;;saved-cam + ;;(.clone (.getCamera world)) + + (com.jme3.renderer.Camera. 640 480) + (.setFrustumPerspective + (float 45) + (float (/ 640 480)) + (float 1) + (float 1000)) + + (.setLocation eye-pos) + (.lookAt Vector3f/ZERO + Vector3f/UNIT_X)) + + bad-cam (add-eye! the-worm (first (eyes the-worm))) + ] + + + (light-up-everything world) + ;;(speed-up world) + (.setTimer world timer) + ;;(display-dilated-time world timer) + ;; add a view from the worm's perspective + (if record? + (Capture/captureVideo + world + (File. + "/home/r/proj/cortex/render/worm-vision/main-view"))) + + (bind-sense (last (node-seq the-worm)) cam) + (bind-sense (last (node-seq the-worm)) bad-cam) + + (add-camera! world - (File. - "/home/r/proj/cortex/render/worm-vision/main-view"))) - - (add-camera! - world - (add-eye! the-worm - (.getChild - (.getChild the-worm "eyes") "eye")) - (comp - (view-image - (if record? - (File. - "/home/r/proj/cortex/render/worm-vision/worm-view"))) - BufferedImage!)) - (set-gravity world Vector3f/ZERO)) + bad-cam + (comp + (view-image + (if record? + (File. + "/home/r/proj/cortex/render/worm-vision/worm-view"))) + BufferedImage!)) + + + + (add-camera! + world cam + (comp + (view-image + (if record? + (File. + "/home/r/proj/cortex/render/worm-vision/worm-view"))) + BufferedImage!)) + (set-gravity world Vector3f/ZERO) + (add-camera! world (.getCamera world) no-op) + + (println-repl cam "\n" bad-cam) + + )) (fn [world _ ] (.setLocalTranslation me (.getLocation (.getCamera world))) @@ -613,7 +698,7 @@ ;; (map #(% world) vision) ;; (if record? ;; (File. "/home/r/proj/cortex/render/worm-vision"))) - (fix-display world) + ;;(fix-display world) ))))) #+end_src