Mercurial > cortex
comparison org/touch.org @ 266:bee5145ce463
Merged Robert's proprioception with Dylan's vision.
author | Dylan Holmes <ocsenave@gmail.com> |
---|---|
date | Mon, 13 Feb 2012 21:53:54 -0600 |
parents | e6e0bb3057b2 |
children | c39b8b29a79e |
comparison
equal
deleted
inserted
replaced
265:e57d8c52f12f | 266:bee5145ce463 |
---|---|
120 (defn ->triangle [points] | 120 (defn ->triangle [points] |
121 (apply #(Triangle. %1 %2 %3) (map ->vector3f points))) | 121 (apply #(Triangle. %1 %2 %3) (map ->vector3f points))) |
122 #+end_src | 122 #+end_src |
123 | 123 |
124 It is convienent to treat a =Triangle= as a vector of vectors, and a | 124 It is convienent to treat a =Triangle= as a vector of vectors, and a |
125 =Vector2f= and =Vector3f= as vectors of floats. (->vector3f) and | 125 =Vector2f= or =Vector3f= as vectors of floats. (->vector3f) and |
126 (->triangle) undo the operations of =(vector3f-seq)= and | 126 (->triangle) undo the operations of =(vector3f-seq)= and |
127 =(triangle-seq)=. If these classes implemented =Iterable= then =(seq)= | 127 =(triangle-seq)=. If these classes implemented =Iterable= then =(seq)= |
128 would work on them automitacally. | 128 would work on them automitacally. |
129 | 129 |
130 ** Decomposing a 3D shape into Triangles | 130 ** Decomposing a 3D shape into Triangles |
495 | 495 |
496 The worm's sense of touch is a bit complicated, so for this basic test | 496 The worm's sense of touch is a bit complicated, so for this basic test |
497 I'll use a new creature --- a simple cube which has touch sensors | 497 I'll use a new creature --- a simple cube which has touch sensors |
498 evenly distributed along each of its sides. | 498 evenly distributed along each of its sides. |
499 | 499 |
500 #+name: test-touch-0 | |
500 #+begin_src clojure | 501 #+begin_src clojure |
501 (in-ns 'cortex.test.touch) | 502 (in-ns 'cortex.test.touch) |
502 | 503 |
503 (defn touch-cube [] | 504 (defn touch-cube [] |
504 (load-blender-model "Models/test-touch/touch-cube.blend")) | 505 (load-blender-model "Models/test-touch/touch-cube.blend")) |
505 #+end_src | 506 #+end_src |
506 | 507 |
507 #+begin_html | 508 ** The Touch Cube |
508 <br> | |
509 #+end_html | |
510 | |
511 #+begin_html | 509 #+begin_html |
512 <div class="figure"> | 510 <div class="figure"> |
513 <center> | 511 <center> |
514 <video controls="controls" width="500"> | 512 <video controls="controls" width="500"> |
515 <source src="../video/touch-cube.ogg" type="video/ogg" | 513 <source src="../video/touch-cube.ogg" type="video/ogg" |
525 | 523 |
526 #+attr_html: width=500 | 524 #+attr_html: width=500 |
527 #+caption: The distribution of feelers along the touch-cube. The colors of the faces are irrelevant; only the white pixels specify feelers. | 525 #+caption: The distribution of feelers along the touch-cube. The colors of the faces are irrelevant; only the white pixels specify feelers. |
528 [[../images/touch-profile.png]] | 526 [[../images/touch-profile.png]] |
529 | 527 |
528 #+name: test-touch-1 | |
530 #+begin_src clojure | 529 #+begin_src clojure |
531 (in-ns 'cortex.test.touch) | 530 (in-ns 'cortex.test.touch) |
532 | |
533 (import com.aurellem.capture.Capture) | |
534 (import java.io.File) | |
535 | 531 |
536 (defn test-basic-touch | 532 (defn test-basic-touch |
537 ([] (test-basic-touch false)) | 533 ([] (test-basic-touch false)) |
538 ([record?] | 534 ([record?] |
539 (let [the-cube (doto (touch-cube) (body!)) | 535 (let [the-cube (doto (touch-cube) (body!)) |
574 <p>The simple creature responds to touch.</p> | 570 <p>The simple creature responds to touch.</p> |
575 </div> | 571 </div> |
576 #+end_html | 572 #+end_html |
577 | 573 |
578 ** Generating the Basic Touch Video | 574 ** Generating the Basic Touch Video |
575 #+name: magick4 | |
579 #+begin_src clojure | 576 #+begin_src clojure |
580 (ns cortex.video.magick4 | 577 (ns cortex.video.magick4 |
581 (:import java.io.File) | 578 (:import java.io.File) |
582 (:use clojure.contrib.shell-out)) | 579 (:use clojure.contrib.shell-out)) |
583 | 580 |
613 target)) | 610 target)) |
614 (fn [& args] (map #(.getCanonicalPath %) args))) | 611 (fn [& args] (map #(.getCanonicalPath %) args))) |
615 background main-view touch targets)))) | 612 background main-view touch targets)))) |
616 #+end_src | 613 #+end_src |
617 | 614 |
615 #+begin_src sh :results silent | |
616 cd /home/r/proj/cortex/render/touch-cube/ | |
617 ffmpeg -r 60 -i out/%07d.png -b:v 9000k -c:v libtheora basic-touch.ogg | |
618 #+end_src | |
618 | 619 |
619 * Adding Touch to the Worm | 620 * Adding Touch to the Worm |
620 | 621 |
621 #+name: test-touch | 622 #+name: test-touch-2 |
622 #+begin_src clojure | 623 #+begin_src clojure |
623 (ns cortex.test.touch | 624 (in-ns 'cortex.test.touch) |
624 (:use (cortex world util sense body touch)) | 625 |
625 (:use cortex.test.body)) | 626 (defn test-touch |
626 | 627 ([] (test-touch false)) |
627 (cortex.import/mega-import-jme3) | 628 ([record?] |
628 | 629 (let [the-worm (doto (worm) (body!)) |
629 (defn test-touch [] | 630 touch (touch! the-worm) |
630 (let [the-worm (doto (worm) (body!)) | 631 touch-display (view-touch)] |
631 touch (touch! the-worm) | 632 (world |
632 touch-display (view-touch)] | 633 (nodify [the-worm (floor)]) |
633 (world (nodify [the-worm (floor)]) | 634 standard-debug-controls |
634 standard-debug-controls | 635 |
635 | 636 (fn [world] |
636 (fn [world] | 637 (if record? |
637 (speed-up world) | 638 (Capture/captureVideo |
638 (light-up-everything world)) | 639 world |
639 | 640 (File. "/home/r/proj/cortex/render/worm-touch/main-view/"))) |
640 (fn [world tpf] | 641 (speed-up world) |
641 (touch-display | 642 (light-up-everything world)) |
642 (map #(% (.getRootNode world)) touch)))))) | 643 |
644 (fn [world tpf] | |
645 (touch-display | |
646 (map #(% (.getRootNode world)) touch) | |
647 (if record? | |
648 (File. "/home/r/proj/cortex/render/worm-touch/touch/")))))))) | |
649 #+end_src | |
650 | |
651 ** Worm Touch Demonstration | |
652 #+begin_html | |
653 <div class="figure"> | |
654 <center> | |
655 <video controls="controls" width="550"> | |
656 <source src="../video/worm-touch.ogg" type="video/ogg" | |
657 preload="none" poster="../images/aurellem-1280x480.png" /> | |
658 </video> | |
659 </center> | |
660 <p>The worm responds to touch.</p> | |
661 </div> | |
662 #+end_html | |
663 | |
664 | |
665 ** Generating the Worm Touch Video | |
666 #+name: magick5 | |
667 #+begin_src clojure | |
668 (ns cortex.video.magick5 | |
669 (:import java.io.File) | |
670 (:use clojure.contrib.shell-out)) | |
671 | |
672 (defn images [path] | |
673 (sort (rest (file-seq (File. path))))) | |
674 | |
675 (def base "/home/r/proj/cortex/render/worm-touch/") | |
676 | |
677 (defn pics [file] | |
678 (images (str base file))) | |
679 | |
680 (defn combine-images [] | |
681 (let [main-view (pics "main-view") | |
682 touch (pics "touch/0") | |
683 targets (map | |
684 #(File. (str base "out/" (format "%07d.png" %))) | |
685 (range 0 (count main-view)))] | |
686 (dorun | |
687 (pmap | |
688 (comp | |
689 (fn [[ main-view touch target]] | |
690 (println target) | |
691 (sh "convert" | |
692 main-view | |
693 touch "-geometry" "+0+0" "-composite" | |
694 target)) | |
695 (fn [& args] (map #(.getCanonicalPath %) args))) | |
696 main-view touch targets)))) | |
643 #+end_src | 697 #+end_src |
644 | 698 |
645 * Headers | 699 * Headers |
646 | 700 |
647 #+name: touch-header | 701 #+name: touch-header |
659 (:import com.jme3.collision.CollisionResults) | 713 (:import com.jme3.collision.CollisionResults) |
660 (:import com.jme3.scene.VertexBuffer$Type) | 714 (:import com.jme3.scene.VertexBuffer$Type) |
661 (:import (com.jme3.math Triangle Vector3f Vector2f Ray Matrix4f))) | 715 (:import (com.jme3.math Triangle Vector3f Vector2f Ray Matrix4f))) |
662 #+end_src | 716 #+end_src |
663 | 717 |
718 #+name: test-touch-header | |
719 #+begin_src clojure | |
720 (ns cortex.test.touch | |
721 (:use (cortex world util sense body touch)) | |
722 (:use cortex.test.body) | |
723 (:import com.aurellem.capture.Capture) | |
724 (:import java.io.File) | |
725 (:import (com.jme3.math Vector3f ColorRGBA))) | |
726 #+end_src | |
727 | |
664 * Source Listing | 728 * Source Listing |
729 - [[../src/cortex/touch.clj][cortex.touch]] | |
730 - [[../src/cortex/test/touch.clj][cortex.test.touch]] | |
731 - [[../src/cortex/video/magick4.clj][cortex.video.magick4]] | |
732 - [[../src/cortex/video/magick5.clj][cortex.video.magick5]] | |
733 #+html: <ul> <li> <a href="../org/touch.org">This org file</a> </li> </ul> | |
734 - [[http://hg.bortreb.com ][source-repository]] | |
735 | |
665 * Next | 736 * Next |
666 | 737 So far I've implemented simulated Vision, Hearing, and Touch, the most |
738 obvious and promiment senses that humans have. Smell and Taste shall | |
739 remain unimplemented for now. This accounts for the "five senses" that | |
740 feature so prominently in our lives. But humans have far more than the | |
741 five main senses. There are internal chemical senses, pain (which is | |
742 *not* the same as touch), heat sensitivity, and our sense of balance, | |
743 among others. One extra sense is so important that I must implement it | |
744 to have a hope of making creatures that can gracefully control their | |
745 own bodies. It is Proprioception, which is the sense of the location | |
746 of each body part in relation to the other body parts. | |
747 | |
748 Close your eyes, and touch your nose with your right index finger. How | |
749 did you do it? You could not see your hand, and neither your hand nor | |
750 your nose could use the sense of touch to guide the path of your hand. | |
751 There are no sound cues, and Taste and Smell certainly don't provide | |
752 any help. You know where your hand is without your other senses | |
753 because of Proprioception. | |
754 | |
755 Onward to [[./proprioception.org][proprioception]]! | |
667 | 756 |
668 * COMMENT Code Generation | 757 * COMMENT Code Generation |
669 #+begin_src clojure :tangle ../src/cortex/touch.clj | 758 #+begin_src clojure :tangle ../src/cortex/touch.clj |
670 <<touch-header>> | 759 <<touch-header>> |
671 <<meta-data>> | 760 <<meta-data>> |
676 <<sensors>> | 765 <<sensors>> |
677 <<kernel>> | 766 <<kernel>> |
678 <<visualization>> | 767 <<visualization>> |
679 #+end_src | 768 #+end_src |
680 | 769 |
681 | |
682 #+begin_src clojure :tangle ../src/cortex/test/touch.clj | 770 #+begin_src clojure :tangle ../src/cortex/test/touch.clj |
683 <<test-touch>> | 771 <<test-touch-header>> |
684 #+end_src | 772 <<test-touch-0>> |
773 <<test-touch-1>> | |
774 <<test-touch-2>> | |
775 #+end_src | |
776 | |
777 #+begin_src clojure :tangle ../src/cortex/video/magick4.clj | |
778 <<magick4>> | |
779 #+end_src | |
780 | |
781 #+begin_src clojure :tangle ../src/cortex/video/magick5.clj | |
782 <<magick5>> | |
783 #+end_src | |
784 | |
685 | 785 |
686 | 786 |
687 | 787 |
688 | 788 |
689 | 789 |