Mercurial > cortex
comparison org/test-creature.org @ 110:f89f0b9ed2fe
changed touch image retrieval code to use meta-data in preparation for multiple sensor maps per object
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Thu, 19 Jan 2012 07:22:40 -0700 |
parents | c05d8d222166 |
children | 61d9c0e8d188 |
comparison
equal
deleted
inserted
replaced
109:c05d8d222166 | 110:f89f0b9ed2fe |
---|---|
421 | 421 |
422 ;; Every Mesh has many triangles, each with its own index. | 422 ;; Every Mesh has many triangles, each with its own index. |
423 ;; Every vertex has its own index as well. | 423 ;; Every vertex has its own index as well. |
424 | 424 |
425 (defn tactile-sensor-image | 425 (defn tactile-sensor-image |
426 "Return the touch-sensor distribution image in ImagePlus format, or | 426 "Return the touch-sensor distribution image in BufferedImage format, |
427 nil if it does not exist." | 427 or nil if it does not exist." |
428 [#^Geometry obj] | 428 [#^Geometry obj] |
429 (let [mat (.getMaterial obj)] | 429 (if-let [image-path (meta-data obj "touch")] |
430 (if-let [texture-param | 430 (ImageToAwt/convert |
431 (.getTextureParam | 431 (.getImage |
432 mat | 432 (.loadTexture |
433 MaterialHelper/TEXTURE_TYPE_DIFFUSE)] | 433 (asset-manager) |
434 (let | 434 image-path)) |
435 [texture | 435 false false 0))) |
436 (.getTextureValue texture-param) | 436 |
437 im (.getImage texture)] | |
438 (ImageToAwt/convert im false false 0))))) | |
439 | |
440 (import ij.process.ImageProcessor) | 437 (import ij.process.ImageProcessor) |
441 (import java.awt.image.BufferedImage) | 438 (import java.awt.image.BufferedImage) |
442 | 439 |
443 (def white -1) | 440 (def white -1) |
444 | 441 |
705 (fn [world] | 702 (fn [world] |
706 (light-up-everything world) | 703 (light-up-everything world) |
707 (enable-debug world) | 704 (enable-debug world) |
708 ;;(com.aurellem.capture.Capture/captureVideo | 705 ;;(com.aurellem.capture.Capture/captureVideo |
709 ;; world (file-str "/home/r/proj/ai-videos/hand")) | 706 ;; world (file-str "/home/r/proj/ai-videos/hand")) |
710 (.setTimer world (RatchetTimer. 60)) | 707 ;;(.setTimer world (RatchetTimer. 60)) |
711 (speed-up world) | 708 ;;(speed-up world) |
712 ;;(set-gravity world (Vector3f. 0 0 0)) | 709 ;;(set-gravity world (Vector3f. 0 0 0)) |
713 ) | 710 ) |
714 (fn [world tpf] | 711 (fn [world tpf] |
715 ;;(dorun | 712 ;;(dorun |
716 ;; (map #(%1 %2) touch-nerves (repeat (.getRootNode world)))) | 713 ;; (map #(%1 %2) touch-nerves (repeat (.getRootNode world)))) |
717 | 714 |
718 (dorun | 715 (dorun |
719 (map #(%1 (%2 (.getRootNode world))) | 716 (map #(%1 (%2 (.getRootNode world))) |
720 touch-debug-windows touch-nerves)) | 717 touch-debug-windows touch-nerves) |
721 | 718 ) |
722 | 719 |
723 ) | 720 ) |
724 ;;(let [timer (atom 0)] | 721 ;;(let [timer (atom 0)] |
725 ;; (fn [_ _] | 722 ;; (fn [_ _] |
726 ;; (swap! timer inc) | 723 ;; (swap! timer inc) |
739 ;;; experiments in collisions | 736 ;;; experiments in collisions |
740 | 737 |
741 | 738 |
742 | 739 |
743 (defn collision-test [] | 740 (defn collision-test [] |
744 (let [a-radius 1 | 741 (let [b-radius 1 |
745 a-position (Vector3f. -0.25 3 0) | 742 b-position (Vector3f. 0 0 0) |
746 b-radius 1 | |
747 b-position (Vector3f. 0.25 3 0) | |
748 | |
749 | |
750 obj-a (box 1 1 1 :color ColorRGBA/Red | |
751 :position a-position | |
752 :physical? false) | |
753 obj-b (box 1 1 1 :color ColorRGBA/Blue | 743 obj-b (box 1 1 1 :color ColorRGBA/Blue |
754 :position b-position | 744 :position b-position |
755 :physical? false) | 745 :mass 0) |
756 node (nodify [obj-a obj-b]) | 746 node (nodify [obj-b]) |
757 bounds-a (BoundingBox. a-position 1 1 1) | 747 bounds-b |
758 bounds-b (BoundingBox. b-position 1 1 1) | 748 (doto (Picture.) |
749 (.setHeight 50) | |
750 (.setWidth 50) | |
751 (.setImage (asset-manager) | |
752 "Models/creature1/hand.png" | |
753 false | |
754 )) | |
755 | |
756 ;;(Ray. (Vector3f. 0 -5 0) (.normalize (Vector3f. 0 1 0))) | |
757 | |
758 collisions | |
759 (let [cr (CollisionResults.)] | |
760 (.collideWith node bounds-b cr) | |
761 (println (map #(.getContactPoint %) cr)) | |
762 cr) | |
763 | |
764 ;;collision-points | |
765 ;;(map #(sphere 0.1 :position (.getContactPoint %)) | |
766 ;; collisions) | |
767 | |
768 ;;node (nodify (conj collision-points obj-b)) | |
769 | |
759 sim | 770 sim |
760 (world node | 771 (world node |
761 {} | 772 {"key-space" |
773 (fn [_ value] | |
774 (if value | |
775 (let [cr (CollisionResults.)] | |
776 (.collideWith node bounds-b cr) | |
777 (println-repl (map #(.getContactPoint %) cr)) | |
778 cr)))} | |
762 no-op | 779 no-op |
763 no-op) | 780 no-op) |
764 | 781 |
765 ] | 782 ] |
766 (.setBound (.getMesh obj-a) bounds-a) | 783 sim |
767 (.updateBound (.getMesh obj-a)) | |
768 | |
769 | |
770 (.setBound (.getMesh obj-b) bounds-b) | |
771 (.updateBound (.getMesh obj-b)) | |
772 | |
773 | |
774 | |
775 (let [cr (CollisionResults.)] | |
776 (.collideWith node bounds-a cr) | |
777 [cr sim]) | |
778 | 784 |
779 )) | 785 )) |
780 | 786 |
781 | 787 |
782 | 788 |