comparison org/touch.org @ 253:e23717fefc7f

added video and source listing to touch
author Robert McIntyre <rlm@mit.edu>
date Mon, 13 Feb 2012 22:52:00 -0700
parents f1a74d23e7e4
children 91654978c8e0
comparison
equal deleted inserted replaced
252:f1a74d23e7e4 253:e23717fefc7f
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
620 ffmpeg -r 60 -i out/%07d.png -b:v 9000k -c:v libtheora basic-touch.ogg 617 ffmpeg -r 60 -i out/%07d.png -b:v 9000k -c:v libtheora basic-touch.ogg
621 #+end_src 618 #+end_src
622 619
623 * Adding Touch to the Worm 620 * Adding Touch to the Worm
624 621
625 #+name: test-touch 622 #+name: test-touch-2
626 #+begin_src clojure 623 #+begin_src clojure
627 (ns cortex.test.touch 624 (in-ns 'cortex.test.touch)
628 (:use (cortex world util sense body touch))
629 (:use cortex.test.body))
630
631 (cortex.import/mega-import-jme3)
632 625
633 (defn test-touch 626 (defn test-touch
634 ([] (test-touch false)) 627 ([] (test-touch false))
635 ([record?] 628 ([record?]
636 (let [the-worm (doto (worm) (body!)) 629 (let [the-worm (doto (worm) (body!))
637 touch (touch! the-worm) 630 touch (touch! the-worm)
638 touch-display (view-touch)] 631 touch-display (view-touch)]
639 (world (nodify [the-worm (floor)]) 632 (world
640 standard-debug-controls 633 (nodify [the-worm (floor)])
641 634 standard-debug-controls
642 (fn [world] 635
643 (if record? 636 (fn [world]
644 (Capture/captureVideo 637 (if record?
645 world 638 (Capture/captureVideo
646 (File. "/home/r/proj/cortex/render/worm-touch/main-view/"))) 639 world
647 (speed-up world) 640 (File. "/home/r/proj/cortex/render/worm-touch/main-view/")))
648 (light-up-everything world)) 641 (speed-up world)
649 642 (light-up-everything world))
650 (fn [world tpf] 643
651 (touch-display 644 (fn [world tpf]
652 (map #(% (.getRootNode world)) touch) 645 (touch-display
653 (if record? 646 (map #(% (.getRootNode world)) touch)
654 (File. "/home/r/proj/cortex/render/worm-touch/touch/")) 647 (if record?
655 648 (File. "/home/r/proj/cortex/render/worm-touch/touch/"))))))))
656 ))))) 649 #+end_src
657 #+end_src 650
658 651 ** Worm Touch Demonstration
659 652 #+begin_html
660 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))))
697 #+end_src
661 698
662 * Headers 699 * Headers
663 700
664 #+name: touch-header 701 #+name: touch-header
665 #+begin_src clojure 702 #+begin_src clojure
676 (:import com.jme3.collision.CollisionResults) 713 (:import com.jme3.collision.CollisionResults)
677 (:import com.jme3.scene.VertexBuffer$Type) 714 (:import com.jme3.scene.VertexBuffer$Type)
678 (:import (com.jme3.math Triangle Vector3f Vector2f Ray Matrix4f))) 715 (:import (com.jme3.math Triangle Vector3f Vector2f Ray Matrix4f)))
679 #+end_src 716 #+end_src
680 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
681 * 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
736
682 * Next 737 * Next
683 738
684 739
685 * COMMENT Code Generation 740 * COMMENT Code Generation
686 #+begin_src clojure :tangle ../src/cortex/touch.clj 741 #+begin_src clojure :tangle ../src/cortex/touch.clj
693 <<sensors>> 748 <<sensors>>
694 <<kernel>> 749 <<kernel>>
695 <<visualization>> 750 <<visualization>>
696 #+end_src 751 #+end_src
697 752
698
699 #+begin_src clojure :tangle ../src/cortex/test/touch.clj 753 #+begin_src clojure :tangle ../src/cortex/test/touch.clj
700 <<test-touch>> 754 <<test-touch-header>>
701 #+end_src 755 <<test-touch-0>>
756 <<test-touch-1>>
757 <<test-touch-2>>
758 #+end_src
759
760 #+begin_src clojure :tangle ../src/cortex/video/magick4.clj
761 <<magick4>>
762 #+end_src
763
764 #+begin_src clojure :tangle ../src/cortex/video/magick5.clj
765 <<magick5>>
766 #+end_src
767
702 768
703 769
704 770
705 771
706 772