# HG changeset patch # User Robert McIntyre # Date 1329201938 25200 # Node ID 96b746a0b39890def78b600c2d223215ec0ea27f # Parent e6e0bb3057b2e11a75d5c7c87083e9bb70da476e# Parent 63dafe7365dff77ade8e7bcbc1175b10a6832d37 bringing in dylan's changes diff -r 63dafe7365df -r 96b746a0b398 assets/Models/test-touch/touch-cube.blend Binary file assets/Models/test-touch/touch-cube.blend has changed diff -r 63dafe7365df -r 96b746a0b398 org/hearing.org --- a/org/hearing.org Mon Feb 13 06:13:07 2012 -0600 +++ b/org/hearing.org Mon Feb 13 23:45:38 2012 -0700 @@ -950,7 +950,6 @@ #+end_src * Testing Hearing - ** Advanced Java Example I wrote a test case in Java that demonstrates the use of the Java @@ -1083,7 +1082,6 @@ sound it hears beomes fainter. This shows the 3D localization of sound in this world.

- #+end_html *** Creating the Ear Video @@ -1169,7 +1167,6 @@ #+html: - [[http://hg.bortreb.com ][source-repository]] - * Next The worm can see and hear, but it can't feel the world or itself. Next post, I'll give the worm a [[./touch.org][sense of touch]]. diff -r 63dafe7365df -r 96b746a0b398 org/touch.org --- a/org/touch.org Mon Feb 13 06:13:07 2012 -0600 +++ b/org/touch.org Mon Feb 13 23:45:38 2012 -0700 @@ -122,7 +122,7 @@ #+end_src It is convienent to treat a =Triangle= as a vector of vectors, and a -=Vector2f= and =Vector3f= as vectors of floats. (->vector3f) and +=Vector2f= or =Vector3f= as vectors of floats. (->vector3f) and (->triangle) undo the operations of =(vector3f-seq)= and =(triangle-seq)=. If these classes implemented =Iterable= then =(seq)= would work on them automitacally. @@ -497,6 +497,7 @@ I'll use a new creature --- a simple cube which has touch sensors evenly distributed along each of its sides. +#+name: test-touch-0 #+begin_src clojure (in-ns 'cortex.test.touch) @@ -504,10 +505,7 @@ (load-blender-model "Models/test-touch/touch-cube.blend")) #+end_src -#+begin_html -
-#+end_html - +** The Touch Cube #+begin_html
@@ -527,12 +525,10 @@ #+caption: The distribution of feelers along the touch-cube. The colors of the faces are irrelevant; only the white pixels specify feelers. [[../images/touch-profile.png]] +#+name: test-touch-1 #+begin_src clojure (in-ns 'cortex.test.touch) -(import com.aurellem.capture.Capture) -(import java.io.File) - (defn test-basic-touch ([] (test-basic-touch false)) ([record?] @@ -576,6 +572,7 @@ #+end_html ** Generating the Basic Touch Video +#+name: magick4 #+begin_src clojure (ns cortex.video.magick4 (:import java.io.File) @@ -615,31 +612,88 @@ background main-view touch targets)))) #+end_src +#+begin_src sh :results silent +cd /home/r/proj/cortex/render/touch-cube/ +ffmpeg -r 60 -i out/%07d.png -b:v 9000k -c:v libtheora basic-touch.ogg +#+end_src * Adding Touch to the Worm -#+name: test-touch +#+name: test-touch-2 #+begin_src clojure -(ns cortex.test.touch - (:use (cortex world util sense body touch)) - (:use cortex.test.body)) +(in-ns 'cortex.test.touch) -(cortex.import/mega-import-jme3) +(defn test-touch + ([] (test-touch false)) + ([record?] + (let [the-worm (doto (worm) (body!)) + touch (touch! the-worm) + touch-display (view-touch)] + (world + (nodify [the-worm (floor)]) + standard-debug-controls + + (fn [world] + (if record? + (Capture/captureVideo + world + (File. "/home/r/proj/cortex/render/worm-touch/main-view/"))) + (speed-up world) + (light-up-everything world)) -(defn test-touch [] - (let [the-worm (doto (worm) (body!)) - touch (touch! the-worm) - touch-display (view-touch)] - (world (nodify [the-worm (floor)]) - standard-debug-controls - - (fn [world] - (speed-up world) - (light-up-everything world)) + (fn [world tpf] + (touch-display + (map #(% (.getRootNode world)) touch) + (if record? + (File. "/home/r/proj/cortex/render/worm-touch/touch/")))))))) +#+end_src - (fn [world tpf] - (touch-display - (map #(% (.getRootNode world)) touch)))))) +** Worm Touch Demonstration +#+begin_html +
+
+ +
+

The worm responds to touch.

+
+#+end_html + + +** Generating the Worm Touch Video +#+name: magick5 +#+begin_src clojure +(ns cortex.video.magick5 + (:import java.io.File) + (:use clojure.contrib.shell-out)) + +(defn images [path] + (sort (rest (file-seq (File. path))))) + +(def base "/home/r/proj/cortex/render/worm-touch/") + +(defn pics [file] + (images (str base file))) + +(defn combine-images [] + (let [main-view (pics "main-view") + touch (pics "touch/0") + targets (map + #(File. (str base "out/" (format "%07d.png" %))) + (range 0 (count main-view)))] + (dorun + (pmap + (comp + (fn [[ main-view touch target]] + (println target) + (sh "convert" + main-view + touch "-geometry" "+0+0" "-composite" + target)) + (fn [& args] (map #(.getCanonicalPath %) args))) + main-view touch targets)))) #+end_src * Headers @@ -661,9 +715,44 @@ (:import (com.jme3.math Triangle Vector3f Vector2f Ray Matrix4f))) #+end_src +#+name: test-touch-header +#+begin_src clojure +(ns cortex.test.touch + (:use (cortex world util sense body touch)) + (:use cortex.test.body) + (:import com.aurellem.capture.Capture) + (:import java.io.File) + (:import (com.jme3.math Vector3f ColorRGBA))) +#+end_src + * Source Listing + - [[../src/cortex/touch.clj][cortex.touch]] + - [[../src/cortex/test/touch.clj][cortex.test.touch]] + - [[../src/cortex/video/magick4.clj][cortex.video.magick4]] + - [[../src/cortex/video/magick5.clj][cortex.video.magick5]] +#+html: + - [[http://hg.bortreb.com ][source-repository]] + * Next +So far I've implemented simulated Vision, Hearing, and Touch, the most +obvious and promiment senses that humans have. Smell and Taste shall +remain unimplemented for now. This accounts for the "five senses" that +feature so prominently in our lives. But humans have far more than the +five main senses. There are internal chemical senses, pain (which is +*not* the same as touch), heat sensitivity, and our sense of balance, +among others. One extra sense is so important that I must implement it +to have a hope of making creatures that can gracefully control their +own bodies. It is Proprioception, which is the sense of the location +of each body part in relation to the other body parts. +Close your eyes, and touch your nose with your right index finger. How +did you do it? You could not see your hand, and neither your hand nor +your nose could use the sense of touch to guide the path of your hand. +There are no sound cues, and Taste and Smell certainly don't provide +any help. You know where your hand is without your other senses +because of Proprioception. + +Onward to [[./proprioception.org][proprioception]]! * COMMENT Code Generation #+begin_src clojure :tangle ../src/cortex/touch.clj @@ -678,11 +767,22 @@ <> #+end_src +#+begin_src clojure :tangle ../src/cortex/test/touch.clj +<> +<> +<> +<> +#+end_src -#+begin_src clojure :tangle ../src/cortex/test/touch.clj -<> +#+begin_src clojure :tangle ../src/cortex/video/magick4.clj +<> #+end_src +#+begin_src clojure :tangle ../src/cortex/video/magick5.clj +<> +#+end_src + +