comparison org/test-creature.org @ 121:05e60a0ed043

preliminary eyes are fully implemented
author Robert McIntyre <rlm@mit.edu>
date Sat, 21 Jan 2012 09:55:59 -0700
parents 83e638955e89
children b591da250afc
comparison
equal deleted inserted replaced
120:83e638955e89 121:05e60a0ed043
755 (bind-camera target cam) 755 (bind-camera target cam)
756 cam)) 756 cam))
757 757
758 758
759 (def presets 759 (def presets
760 {:all 0x000000 760 {:all 0xFFFFFF
761 :red 0xFF0000 761 :red 0xFF0000
762 :blue 0x0000FF 762 :blue 0x0000FF
763 :green 0x00FF00}) 763 :green 0x00FF00})
764 764
765 765
793 mask (.getRGB @vision-image x y)))))))) 793 mask (.getRGB @vision-image x y))))))))
794 retinal-map)) 794 retinal-map))
795 ])) 795 ]))
796 796
797 (defn vision 797 (defn vision
798 798 [#^Node creature & {skip :skip :or {skip 0}}]
799 ;; need to create a camera based on UV image, 799
800 ;; update this camera every frame based on the position of this 800 (reduce
801 ;; geometry. (maybe can get cam to follow the object) 801 (fn [[init-a senses-a]
802 802 [init-b senses-b]]
803 ;; use a stack for the continuation to grab the image. 803 [(conj init-a init-b)
804 804 (into senses-a senses-b)])
805 805 [[][]]
806 [#^Geometry eye] 806 (for [eye (creature-eyes creature)]
807 807 (enable-vision creature eye))))
808 808
809
810
811 )
812
813 809
814 (defn blender-creature 810 (defn blender-creature
815 "Return a creature with all joints in place." 811 "Return a creature with all joints in place."
816 [blender-path] 812 [blender-path]
817 (let [model (load-blender-model blender-path) 813 (let [model (load-blender-model blender-path)
818 joints 814 joints
819 (if-let [joint-node (.getChild model "joints")] 815 (if-let [joint-node (.getChild model "joints")]
820 (seq (.getChildren joint-node)) 816 (seq (.getChildren joint-node))
821 (do (println-repl "could not find joints node") []))] 817 (do (println-repl "could not find joints node") []))]
822 (assemble-creature model joints))) 818 (assemble-creature model joints)))
823
824
825
826
827
828 819
829 (defn debug-window 820 (defn debug-window
830 "creates function that offers a debug view of sensor data" 821 "creates function that offers a debug view of sensor data"
831 [] 822 []
832 (let [vi (view-image)] 823 (let [vi (view-image)]
851 (for [i (range (count coords))] 842 (for [i (range (count coords))]
852 (.setRGB image ((coords i) 0) ((coords i) 1) 843 (.setRGB image ((coords i) 0) ((coords i) 1)
853 (sensor-data i)))) 844 (sensor-data i))))
854 (vi image))))) 845 (vi image)))))
855 846
856
857
858 ;;(defn test-touch [world creature] 847 ;;(defn test-touch [world creature]
859 848
860 849
861 (defn test-creature [thing] 850 (defn test-creature [thing]
862 (let [x-axis 851 (let [x-axis
866 z-axis 855 z-axis
867 (box 0.01 0.01 1 :physical? false :color ColorRGBA/Blue) 856 (box 0.01 0.01 1 :physical? false :color ColorRGBA/Blue)
868 creature (blender-creature thing) 857 creature (blender-creature thing)
869 touch-nerves (touch creature) 858 touch-nerves (touch creature)
870 touch-debug-windows (map (fn [_] (debug-window)) touch-nerves) 859 touch-debug-windows (map (fn [_] (debug-window)) touch-nerves)
871 [init-vision [vision-data]] 860 [init-vision-fns vision-data] (vision creature)
872 (enable-vision creature (test-eye)) 861 vision-debug (map (fn [_] (debug-vision-window)) vision-data)
873 vision-debug (debug-vision-window)
874 me (sphere 0.5 :color ColorRGBA/Blue :physical? false) 862 me (sphere 0.5 :color ColorRGBA/Blue :physical? false)
875 ] 863 ]
876 (world 864 (world
877 (nodify [creature 865 (nodify [creature
878 (box 10 2 10 :position (Vector3f. 0 -9 0) 866 (box 10 2 10 :position (Vector3f. 0 -9 0)
882 ]) 870 ])
883 standard-debug-controls 871 standard-debug-controls
884 (fn [world] 872 (fn [world]
885 (light-up-everything world) 873 (light-up-everything world)
886 (enable-debug world) 874 (enable-debug world)
887 (init-vision world) 875 (map #(% world) init-vision-fns)
888 876
889 (add-eye world 877 (add-eye world
890 (attach-eye creature (test-eye)) 878 (attach-eye creature (test-eye))
891 (comp (view-image) BufferedImage!)) 879 (comp (view-image) BufferedImage!))
892 880
902 ;;(dorun 890 ;;(dorun
903 ;; (map #(%1 %2) touch-nerves (repeat (.getRootNode world)))) 891 ;; (map #(%1 %2) touch-nerves (repeat (.getRootNode world))))
904 892
905 (dorun 893 (dorun
906 (map #(%1 (%2 (.getRootNode world))) 894 (map #(%1 (%2 (.getRootNode world)))
907 touch-debug-windows touch-nerves) 895 touch-debug-windows touch-nerves))
908 ) 896 (dorun
897 (map #(%1 (%2))
898 vision-debug vision-data))
899
909 ;;(println-repl (vision-data)) 900 ;;(println-repl (vision-data))
910 (.setLocalTranslation me (.getLocation (.getCamera world))) 901 (.setLocalTranslation me (.getLocation (.getCamera world)))
911 902
912 (vision-debug (vision-data)) 903
913 ) 904 )
914 ;;(let [timer (atom 0)] 905 ;;(let [timer (atom 0)]
915 ;; (fn [_ _] 906 ;; (fn [_ _]
916 ;; (swap! timer inc) 907 ;; (swap! timer inc)
917 ;; (if (= (rem @timer 60) 0) 908 ;; (if (= (rem @timer 60) 0)