# HG changeset patch # User Robert McIntyre # Date 1329350161 25200 # Node ID 23aadf376e9d46601df823d6490a6e7f1208981e # Parent 2ad29b68ff2202d025fc585d04ff3afb1ddb6d7b upgraded to latest jMonkeyEngine, streamlined tests diff -r 2ad29b68ff22 -r 23aadf376e9d assets/Models/test-creature/finger-tip.png Binary file assets/Models/test-creature/finger-tip.png has changed diff -r 2ad29b68ff22 -r 23aadf376e9d assets/Models/test-creature/finger-tip.xcf Binary file assets/Models/test-creature/finger-tip.xcf has changed diff -r 2ad29b68ff22 -r 23aadf376e9d assets/Models/test-creature/hand.blend Binary file assets/Models/test-creature/hand.blend has changed diff -r 2ad29b68ff22 -r 23aadf376e9d assets/Models/test-touch/touch-cube.blend Binary file assets/Models/test-touch/touch-cube.blend has changed diff -r 2ad29b68ff22 -r 23aadf376e9d org/body.org --- a/org/body.org Wed Feb 15 14:09:20 2012 -0700 +++ b/org/body.org Wed Feb 15 16:56:01 2012 -0700 @@ -80,14 +80,17 @@ (.setTimer world (RatchetTimer. 60)) world) -(defn test-one [] - (world (hand) - standard-debug-controls - (comp - #(Capture/captureVideo - % (File. "/home/r/proj/cortex/render/body/1")) - setup) - no-op)) +(defn test-hand-1 + ([] (test-hand-1 false)) + ([record?] + (world (hand) + standard-debug-controls + (fn [world] + (if record? + (Capture/captureVideo + world + (File. "/home/r/proj/cortex/render/body/1"))) + (setup world)) no-op))) #+end_src @@ -158,18 +161,22 @@ (box 10 3 10 :position (Vector3f. 0 -10 0) :color ColorRGBA/Gray :mass 0)) -(defn test-two [] - (world (nodify - [(doto (hand) - (physical!)) - (floor)]) - (merge standard-debug-controls gravity-control) - (comp - #(Capture/captureVideo - % (File. "/home/r/proj/cortex/render/body/2")) - #(do (set-gravity % Vector3f/ZERO) %) - setup) - no-op)) +(defn test-hand-2 + ([] (test-hand-2 false)) + ([record?] + (world + (nodify + [(doto (hand) + (physical!)) + (floor)]) + (merge standard-debug-controls gravity-control) + (fn [world] + (if record? + (Capture/captureVideo + world (File. "/home/r/proj/cortex/render/body/2"))) + (set-gravity world Vector3f/ZERO) + (setup world)) + no-op))) #+end_src #+begin_html @@ -428,20 +435,23 @@ {"key-h" (fn [world val] (if val (enable-debug world)))}) -(defn test-three [] - (world (nodify - [(doto (hand) - (physical!) - (joints!)) - (floor)]) - (merge standard-debug-controls debug-control - gravity-control) - (comp - #(Capture/captureVideo - % (File. "/home/r/proj/cortex/render/body/3")) - #(do (set-gravity % Vector3f/ZERO) %) - setup) - no-op)) +(defn test-hand-3 + ([] (test-hand-3 false)) + ([record?] + (world + (nodify + [(doto (hand) + (physical!) + (joints!)) + (floor)]) + (merge standard-debug-controls debug-control + gravity-control) + (comp + #(Capture/captureVideo + % (File. "/home/r/proj/cortex/render/body/3")) + #(do (set-gravity % Vector3f/ZERO) %) + setup) + no-op))) #+end_src =physical!= makes the hand solid, then =joints!= connects each @@ -494,22 +504,25 @@ (load-blender-model "Models/test-creature/worm.blend")) -(defn worm-1 [] - (let [timer (RatchetTimer. 60)] - (world - (nodify - [(doto (worm) - (body!)) - (floor)]) - (merge standard-debug-controls debug-control) - #(do - (speed-up %) - (light-up-everything %) - (.setTimer % timer) - (cortex.util/display-dialated-time % timer) - (Capture/captureVideo - % (File. "/home/r/proj/cortex/render/body/4"))) - no-op))) +(defn test-worm + ([] (test-worm false)) + ([record?] + (let [timer (RatchetTimer. 60)] + (world + (nodify + [(doto (worm) + (body!)) + (floor)]) + (merge standard-debug-controls debug-control) + #(do + (speed-up %) + (light-up-everything %) + (.setTimer % timer) + (cortex.util/display-dialated-time % timer) + (if record? + (Capture/captureVideo + % (File. "/home/r/proj/cortex/render/body/4")))) + no-op)))) #+end_src #+begin_html diff -r 2ad29b68ff22 -r 23aadf376e9d org/hearing.org --- a/org/hearing.org Wed Feb 15 14:09:20 2012 -0700 +++ b/org/hearing.org Wed Feb 15 16:56:01 2012 -0700 @@ -1018,43 +1018,43 @@ #+begin_src clojure (in-ns 'cortex.test.hearing) -(cortex.import/mega-import-jme3) -(import java.io.File) - -(use 'cortex.body) - -(defn test-worm-hearing [] - (let [the-worm (doto (worm) (body!)) - hearing (hearing! the-worm) - hearing-display (view-hearing) +(defn test-worm-hearing + ([] (test-worm-hearing false)) + ([record?] + (let [the-worm (doto (worm) (body!)) + hearing (hearing! the-worm) + hearing-display (view-hearing) + + tone (AudioNode. (asset-manager) + "Sounds/pure.wav" false) + + hymn (AudioNode. (asset-manager) + "Sounds/ear-and-eye.wav" false)] + (world + (nodify [the-worm (floor)]) + (merge standard-debug-controls + {"key-return" + (fn [_ value] + (if value (.play tone))) + "key-l" + (fn [_ value] + (if value (.play hymn)))}) + (fn [world] + (light-up-everything world) + (if record? + (do + (com.aurellem.capture.Capture/captureVideo + world + (File."/home/r/proj/cortex/render/worm-audio/frames")) + (com.aurellem.capture.Capture/captureAudio + world + (File."/home/r/proj/cortex/render/worm-audio/audio.wav"))))) - tone (AudioNode. (asset-manager) - "Sounds/pure.wav" false) - - hymn (AudioNode. (asset-manager) - "Sounds/ear-and-eye.wav" false)] - (world - (nodify [the-worm (floor)]) - (merge standard-debug-controls - {"key-return" - (fn [_ value] - (if value (.play tone))) - "key-l" - (fn [_ value] - (if value (.play hymn)))}) - (fn [world] - (light-up-everything world) - (com.aurellem.capture.Capture/captureVideo - world - (File."/home/r/proj/cortex/render/worm-audio/frames")) - (com.aurellem.capture.Capture/captureAudio - world - (File."/home/r/proj/cortex/render/worm-audio/audio.wav"))) - - (fn [world tpf] - (hearing-display - (map #(% world) hearing) - (File. "/home/r/proj/cortex/render/worm-audio/hearing-data")))))) + (fn [world tpf] + (hearing-display + (map #(% world) hearing) + (if record? + (File. "/home/r/proj/cortex/render/worm-audio/hearing-data")))))))) #+end_src In this test, I load the worm with its newly formed ear and let it @@ -1154,11 +1154,13 @@ #+name: test-header #+begin_src clojure (ns cortex.test.hearing - (:use (cortex world util hearing)) + (:use (cortex world util hearing body)) (:use cortex.test.body) (:import (com.jme3.audio AudioNode Listener)) + (:import java.io.File) (:import com.jme3.scene.Node - com.jme3.system.AppSettings)) + com.jme3.system.AppSettings + com.jme3.math.Vector3f)) #+end_src * Source Listing diff -r 2ad29b68ff22 -r 23aadf376e9d org/movement.org --- a/org/movement.org Wed Feb 15 14:09:20 2012 -0700 +++ b/org/movement.org Wed Feb 15 16:56:01 2012 -0700 @@ -183,9 +183,10 @@ #+caption: The node highlighted in orange is the parent node of all muscles in the worm. The arrow highlighted in yellow represents the creature's single muscle, which moves the top segment. The other nodes which are not highlighted are joints, eyes, and ears. [[../images/worm-with-muscle.png]] +#+name: test-movement #+begin_src clojure -(defn test-movement - ([] (test-movement false)) +(defn test-worm-movement + ([] (test-worm-movement false)) ([record?] (let [creature (doto (worm) (body!)) @@ -307,11 +308,9 @@ (:import java.io.File) (:import java.awt.image.BufferedImage) (:import com.jme3.scene.Node) - (:import com.jme3.math.Vector3f) + (:import (com.jme3.math Quaternion Vector3f)) (:import (com.aurellem.capture Capture RatchetTimer)) (:import com.jme3.bullet.control.RigidBodyControl)) - -(cortex.import/mega-import-jme3) #+end_src * Source Listing diff -r 2ad29b68ff22 -r 23aadf376e9d org/proprioception.org --- a/org/proprioception.org Wed Feb 15 14:09:20 2012 -0700 +++ b/org/proprioception.org Wed Feb 15 16:56:01 2012 -0700 @@ -351,10 +351,12 @@ #+name: test-proprioception-header #+begin_src clojure (ns cortex.test.proprioception -(:import (com.aurellem.capture Capture RatchetTimer)) -(:use (cortex util world proprioception body)) -(:import java.io.File)) -(cortex.import/mega-import-jme3) + (:import (com.aurellem.capture Capture RatchetTimer)) + (:use (cortex util world proprioception body)) + (:import java.io.File) + (:import com.jme3.bullet.control.RigidBodyControl) + (:import com.jme3.bullet.collision.PhysicsCollisionObject) + (:import (com.jme3.math Vector3f Quaternion ColorRGBA))) #+end_src * Source Listing diff -r 2ad29b68ff22 -r 23aadf376e9d org/sense.org --- a/org/sense.org Wed Feb 15 14:09:20 2012 -0700 +++ b/org/sense.org Wed Feb 15 16:56:01 2012 -0700 @@ -448,32 +448,35 @@ (defn test-bind-sense "Show a camera that stays in the same relative position to a blue cube." - [] - (let [eye-pos (Vector3f. 0 30 0) - rock (box 1 1 1 :color ColorRGBA/Blue - :position (Vector3f. 0 10 0) - :mass 30) - table (box 3 1 10 :color ColorRGBA/Gray :mass 0 - :position (Vector3f. 0 -3 0))] - (world - (nodify [rock table]) - standard-debug-controls - (fn init [world] - (let [cam (doto (.clone (.getCamera world)) - (.setLocation eye-pos) - (.lookAt Vector3f/ZERO - Vector3f/UNIT_X))] - (bind-sense rock cam) - (.setTimer world (RatchetTimer. 60)) - (Capture/captureVideo - world (File. "/home/r/proj/cortex/render/bind-sense0")) - (add-camera! - world cam - (comp (view-image - (File. "/home/r/proj/cortex/render/bind-sense1")) - BufferedImage!)) - (add-camera! world (.getCamera world) no-op))) - no-op))) + ([] (test-bind-sense false)) + ([record?] + (let [eye-pos (Vector3f. 0 30 0) + rock (box 1 1 1 :color ColorRGBA/Blue + :position (Vector3f. 0 10 0) + :mass 30) + table (box 3 1 10 :color ColorRGBA/Gray :mass 0 + :position (Vector3f. 0 -3 0))] + (world + (nodify [rock table]) + standard-debug-controls + (fn init [world] + (let [cam (doto (.clone (.getCamera world)) + (.setLocation eye-pos) + (.lookAt Vector3f/ZERO + Vector3f/UNIT_X))] + (bind-sense rock cam) + (.setTimer world (RatchetTimer. 60)) + (if record? + (Capture/captureVideo + 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"))) + BufferedImage!)) + (add-camera! world (.getCamera world) no-op))) + no-op)))) #+end_src #+begin_html diff -r 2ad29b68ff22 -r 23aadf376e9d org/touch.org --- a/org/touch.org Wed Feb 15 14:09:20 2012 -0700 +++ b/org/touch.org Wed Feb 15 16:56:01 2012 -0700 @@ -435,7 +435,7 @@ touch-objects))] (FastMath/clamp (float - (if (> response limit) 0.0 + (if (> response limit) (float 0.0) (+ response correction))) (float 0.0) limit))) @@ -485,7 +485,7 @@ (for [i (range (count coords))] (.setRGB image ((coords i) 0) ((coords i) 1) (apply touch->gray (sensor-data i))))) - image)))) + image)))) #+end_src #+results: visualization @@ -623,8 +623,8 @@ #+begin_src clojure (in-ns 'cortex.test.touch) -(defn test-touch - ([] (test-touch false)) +(defn test-worm-touch + ([] (test-worm-touch false)) ([record?] (let [the-worm (doto (worm) (body!)) touch (touch! the-worm) @@ -730,6 +730,7 @@ - [[../src/cortex/test/touch.clj][cortex.test.touch]] - [[../src/cortex/video/magick4.clj][cortex.video.magick4]] - [[../src/cortex/video/magick5.clj][cortex.video.magick5]] + - [[../assets/Models/test-touch/touch-cube.blend][touch-cube.blend]] #+html: - [[http://hg.bortreb.com ][source-repository]] @@ -781,11 +782,3 @@ #+begin_src clojure :tangle ../src/cortex/video/magick5.clj <> #+end_src - - - - - - - - diff -r 2ad29b68ff22 -r 23aadf376e9d org/vision.org --- a/org/vision.org Wed Feb 15 14:09:20 2012 -0700 +++ b/org/vision.org Wed Feb 15 16:56:01 2012 -0700 @@ -453,35 +453,38 @@ You should see a rotating cube, and two windows, each displaying a different view of the cube." - [] - (let [candy - (box 1 1 1 :physical? false :color ColorRGBA/Blue)] - (world - (doto (Node.) - (.attachChild candy)) - {} - (fn [world] - (let [cam (.clone (.getCamera world)) - width (.getWidth cam) - height (.getHeight cam)] - (add-camera! world cam - (comp - (view-image - (File. "/home/r/proj/cortex/render/vision/1")) - BufferedImage!)) - (add-camera! world - (doto (.clone cam) - (.setLocation (Vector3f. -10 0 0)) - (.lookAt Vector3f/ZERO Vector3f/UNIT_Y)) - (comp - (view-image - (File. "/home/r/proj/cortex/render/vision/2")) - BufferedImage!)) - ;; This is here to restore the main view + ([] (test-pipeline false)) + ([record?] + (let [candy + (box 1 1 1 :physical? false :color ColorRGBA/Blue)] + (world + (doto (Node.) + (.attachChild candy)) + {} + (fn [world] + (let [cam (.clone (.getCamera world)) + width (.getWidth cam) + height (.getHeight cam)] + (add-camera! world cam + (comp + (view-image + (if record? + (File. "/home/r/proj/cortex/render/vision/1"))) + BufferedImage!)) + (add-camera! world + (doto (.clone cam) + (.setLocation (Vector3f. -10 0 0)) + (.lookAt Vector3f/ZERO Vector3f/UNIT_Y)) + (comp + (view-image + (if record? + (File. "/home/r/proj/cortex/render/vision/2"))) + BufferedImage!)) + ;; This is here to restore the main view ;; after the other views have completed processing - (add-camera! world (.getCamera world) no-op))) - (fn [world tpf] - (.rotate candy (* tpf 0.2) 0 0))))) + (add-camera! world (.getCamera world) no-op))) + (fn [world tpf] + (.rotate candy (* tpf 0.2) 0 0)))))) #+end_src #+begin_html @@ -541,60 +544,62 @@ (comp #(change-color % color) (fire-cannon-ball))) -(defn test-worm-vision [record] - (let [the-worm (doto (worm)(body!)) - vision (vision! the-worm) - vision-display (view-vision) - 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 - :position (Vector3f. 0 -5 0)) - y-axis - (box 0.01 1 0.01 :physical? false :color ColorRGBA/Green - :position (Vector3f. 0 -5 0)) - z-axis - (box 0.01 0.01 1 :physical? false :color ColorRGBA/Blue - :position (Vector3f. 0 -5 0)) - timer (RatchetTimer. 60)] +(defn test-worm-vision + ([] (test-worm-vision false)) + ([record?] + (let [the-worm (doto (worm)(body!)) + vision (vision! the-worm) + vision-display (view-vision) + 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 + :position (Vector3f. 0 -5 0)) + y-axis + (box 0.01 1 0.01 :physical? false :color ColorRGBA/Green + :position (Vector3f. 0 -5 0)) + z-axis + (box 0.01 0.01 1 :physical? false :color ColorRGBA/Blue + :position (Vector3f. 0 -5 0)) + 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)) - (fn [world] - (light-up-everything world) - (speed-up world) - (.setTimer world timer) - (display-dialated-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"))) - - (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)) - - (fn [world _ ] - (.setLocalTranslation me (.getLocation (.getCamera world))) - (vision-display - (map #(% world) vision) - (if record (File. "/home/r/proj/cortex/render/worm-vision"))) - (fix-display world))))) + (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)) + (fn [world] + (light-up-everything world) + (speed-up world) + (.setTimer world timer) + (display-dialated-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"))) + + (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)) + + (fn [world _ ] + (.setLocalTranslation me (.getLocation (.getCamera world))) + (vision-display + (map #(% world) vision) + (if record? (File. "/home/r/proj/cortex/render/worm-vision"))) + (fix-display world)))))) #+end_src The world consists of the worm and a flat gray floor. I can shoot red,