comparison org/test-creature.org @ 117:94c005f7f9dd

saving progress
author Robert McIntyre <rlm@mit.edu>
date Fri, 20 Jan 2012 05:47:56 -0700
parents 947bef5d6670
children 1261444da2c7
comparison
equal deleted inserted replaced
116:947bef5d6670 117:94c005f7f9dd
620 620
621 ;; human eye transmits 62kb/s to brain Bandwidth is 8.75 Mb/s 621 ;; human eye transmits 62kb/s to brain Bandwidth is 8.75 Mb/s
622 ;; http://en.wikipedia.org/wiki/Retina 622 ;; http://en.wikipedia.org/wiki/Retina
623 623
624 (defn test-eye [] 624 (defn test-eye []
625 (.getChild (worm-model) "worm-11")) 625 (.getChild
626 (.getChild (worm-model) "eyes")
627 "eye"))
626 628
627 629
628 (defn retina-sensor-image 630 (defn retina-sensor-image
629 "Return a map of pixel selection functions to BufferedImages 631 "Return a map of pixel selection functions to BufferedImages
630 describing the distribution of light-sensitive components on this 632 describing the distribution of light-sensitive components on this
631 geometry's surface. Each function creates an integer from the rgb 633 geometry's surface. Each function creates an integer from the rgb
632 values found in the pixel. :red, :green, :blue, :gray are already 634 values found in the pixel. :red, :green, :blue, :gray are already
633 defined as extracting the red green blue and average components 635 defined as extracting the red green blue and average components
634 respectively." 636 respectively."
635 [#^Geometry eye] 637 [#^Spatial eye]
636 (if-let [eye-map (meta-data eye "eye")] 638 (if-let [eye-map (meta-data eye "eye")]
637 (map-vals 639 (map-vals
638 #(ImageToAwt/convert 640 #(ImageToAwt/convert
639 (.getImage (.loadTexture (asset-manager) %)) 641 (.getImage (.loadTexture (asset-manager) %))
640 false false 0) 642 false false 0)
641 (read-string 643 (read-string
642 eye-map)))) 644 eye-map))))
645
646 (defn eye-dimensions
647 "returns the width and height specified in the metadata of the eye"
648 [#^Spatial eye]
649 (let [dimensions
650 (map #(vector (.getWidth %) (.getHeight %))
651 (vals (retina-sensor-image eye)))]
652 [(apply max (map first dimensions))
653 (apply max (map second dimensions))]))
654
643 655
644 (defn creature-eyes 656 (defn creature-eyes
645 "The eye nodes which are children of the \"eyes\" node in the 657 "The eye nodes which are children of the \"eyes\" node in the
646 creature." 658 creature."
647 [#^Node creature] 659 [#^Node creature]
698 results) 710 results)
699 (if-let [target (first results)] 711 (if-let [target (first results)]
700 (.getGeometry target) 712 (.getGeometry target)
701 (recur (float (* 2 radius))))))) 713 (recur (float (* 2 radius)))))))
702 714
715 (defn bind-camera
716 "Bind the camera to the Spatial such that it will maintain its
717 current position relative to the Spatial no matter how the spatial
718 moves."
719 [#^Spatial obj #^Camera cam]
720 (let [cam-offset (.subtract (.getLocation cam)
721 (.getWorldTranslation obj))
722 initial-cam-rotation (Quaternion. (.getRotation cam))
723 base-anti-rotation (.inverse (.getWorldRotation obj))]
724 (.addControl
725 obj
726 (proxy [AbstractControl] []
727 (controlUpdate [tpf]
728 (let [total-rotation
729 (.mult base-anti-rotation (.getWorldRotation obj))]
730 (.setLocation cam
731 (.add
732 (.mult total-rotation cam-offset)
733 (.getWorldTranslation obj)))
734 (.setRotation cam
735 (.mult total-rotation initial-cam-rotation))))
736 (controlRender [_ _])))))
737
738
703 (defn attach-eyes 739 (defn attach-eyes
704 "For each eye in the creature, attach a CameraNode to the appropiate 740 "For each eye in the creature, attach a Camera to the appropiate
705 area and return the Camera." 741 area and return the Camera."
706 [#^Node creature] 742 [#^Node creature]
707 (for [eye (creature-eyes creature)] 743 (for [eye (creature-eyes creature)]
708 (let [target (eye-target creature eye)] 744 (let [target (eye-target creature eye)
709 (CameraNode 745 [cam-width cam-height] (eye-dimensions eye)
710 ) 746 cam (Camera. cam-width cam-height)]
747 (.setLocation cam (.getWorldTranslation eye))
748 (.setRotation cam (.getWorldRotation eye))
749
750 )
751
752
753 ))
711 754
712 (defn vision 755 (defn vision
713 756
714 ;; need to create a camera based on uv image, 757 ;; need to create a camera based on uv image,
715 ;; update this camera every frame based on the position of this 758 ;; update this camera every frame based on the position of this
864 907
865 908
866 ;; the camera will stay in its initial position/rotation with relation 909 ;; the camera will stay in its initial position/rotation with relation
867 ;; to the spatial. 910 ;; to the spatial.
868 911
869 (defn bind-camera [#^Spatial obj #^Camera cam] 912
870 (let [cam-offset (.subtract (.getLocation cam) 913 (defn follow-test
871 (.getWorldTranslation obj)) 914 "show a camera that stays in the same relative position to a blue cube."
872 initial-cam-rotation (.getRotation cam) 915 []
873 base-anti-rotation (.inverse (.getWorldRotation obj))]
874 (.addControl
875 obj
876 (proxy [AbstractControl] []
877 (controlUpdate [tpf]
878 (let [total-rotation
879 (.mult base-anti-rotation (.getWorldRotation obj))]
880
881 (.setLocation cam
882 (.add
883 (.mult total-rotation cam-offset)
884 (.getWorldTranslation obj)))
885 (.setRotation cam
886 initial-cam-rotation)
887 ;;(.mult total-rotation initial-cam-rotation)
888
889 ))
890
891 (controlRender [_ _])))))
892
893
894
895 (defn follow-test []
896 (let [camera-pos (Vector3f. 0 30 0) 916 (let [camera-pos (Vector3f. 0 30 0)
897 rock (box 1 1 1 :color ColorRGBA/Blue 917 rock (box 1 1 1 :color ColorRGBA/Blue
898 :position (Vector3f. 0 10 0) 918 :position (Vector3f. 0 10 0)
899 :mass 30 919 :mass 30
900 ) 920 )