comparison org/test-creature.org @ 128:4b38355ad6e3

modifications to docstrings by dylan
author Robert McIntyre <rlm@mit.edu>
date Sun, 29 Jan 2012 23:34:12 -0700
parents bc49d452c42a
children bab47091534e
comparison
equal deleted inserted replaced
127:bc49d452c42a 128:4b38355ad6e3
551 (get point 1 0) 551 (get point 1 0)
552 (get point 2 0)))) 552 (get point 2 0))))
553 (take 3 points)))) 553 (take 3 points))))
554 554
555 (defn convex-bounds 555 (defn convex-bounds
556 "Dimensions of the smallest integer bounding square of the list of 556 ;;dylan
557 2D verticies in the form: [x y width height]." 557 "Returns the smallest square containing the given
558 vertices, as a vector of integers [left top width height]."
559 ;; "Dimensions of the smallest integer bounding square of the list of
560 ;; 2D verticies in the form: [x y width height]."
558 [uv-verts] 561 [uv-verts]
559 (let [xs (map first uv-verts) 562 (let [xs (map first uv-verts)
560 ys (map second uv-verts) 563 ys (map second uv-verts)
561 x0 (Math/floor (apply min xs)) 564 x0 (Math/floor (apply min xs))
562 y0 (Math/floor (apply min ys)) 565 y0 (Math/floor (apply min ys))
563 x1 (Math/ceil (apply max xs)) 566 x1 (Math/ceil (apply max xs))
564 y1 (Math/ceil (apply max ys))] 567 y1 (Math/ceil (apply max ys))]
565 [x0 y0 (- x1 x0) (- y1 y0)])) 568 [x0 y0 (- x1 x0) (- y1 y0)]))
566 569
567 (defn sensors-in-triangle 570 (defn sensors-in-triangle
568 "Find the locations of the touch sensors within a triangle in both 571 ;;dylan
569 UV and gemoetry relative coordinates." 572 "Locate the touch sensors in the triangle, returning a map of their UV and geometry-relative coordinates."
573 ;;"Find the locations of the touch sensors within a triangle in both
574 ;; UV and gemoetry relative coordinates."
570 [image mesh tri-index] 575 [image mesh tri-index]
571 (let [width (.getWidth image) 576 (let [width (.getWidth image)
572 height (.getHeight image) 577 height (.getHeight image)
573 UV-vertex-coords (triangle-UV-coord mesh width height tri-index) 578 UV-vertex-coords (triangle-UV-coord mesh width height tri-index)
574 bounds (convex-bounds UV-vertex-coords) 579 bounds (convex-bounds UV-vertex-coords)
686 (vals (retina-sensor-image eye)))] 691 (vals (retina-sensor-image eye)))]
687 [(apply max (map first dimensions)) 692 [(apply max (map first dimensions))
688 (apply max (map second dimensions))])) 693 (apply max (map second dimensions))]))
689 694
690 (defn creature-eyes 695 (defn creature-eyes
691 "The eye nodes which are children of the \"eyes\" node in the 696 ;;dylan
692 creature." 697 "Return the children of the creature's \"eyes\" node."
698 ;;"The eye nodes which are children of the \"eyes\" node in the
699 ;;creature."
693 [#^Node creature] 700 [#^Node creature]
694 (if-let [eye-node (.getChild creature "eyes")] 701 (if-let [eye-node (.getChild creature "eyes")]
695 (seq (.getChildren eye-node)) 702 (seq (.getChildren eye-node))
696 (do (println-repl "could not find eyes node") []))) 703 (do (println-repl "could not find eyes node") [])))
697 704
740 ;; sensor-functions]. The init functions each take the world and 747 ;; sensor-functions]. The init functions each take the world and
741 ;; register a SoundProcessor that does foureier transforms on the 748 ;; register a SoundProcessor that does foureier transforms on the
742 ;; incommong sound data, making it available to each sensor function. 749 ;; incommong sound data, making it available to each sensor function.
743 750
744 (defn creature-ears 751 (defn creature-ears
745 "The ear nodes which are children of the \"ears\" node in the 752 "Return the children of the creature's \"ears\" node."
746 creature." 753 ;;dylan
754 ;;"The ear nodes which are children of the \"ears\" node in the
755 ;;creature."
747 [#^Node creature] 756 [#^Node creature]
748 (if-let [ear-node (.getChild creature "ears")] 757 (if-let [ear-node (.getChild creature "ears")]
749 (seq (.getChildren ear-node)) 758 (seq (.getChildren ear-node))
750 (do (println-repl "could not find ears node") []))) 759 (do (println-repl "could not find ears node") [])))
751 760
752 (defn closest-node 761 (defn closest-node
753 "The closest object in creature to the given node." 762 "Return the object in creature which is closest to the given node."
763 ;;dylan"The closest object in creature to the given node."
754 [#^Node creature #^Node eye] 764 [#^Node creature #^Node eye]
755 (loop [radius (float 0.01)] 765 (loop [radius (float 0.01)]
756 (let [results (CollisionResults.)] 766 (let [results (CollisionResults.)]
757 (.collideWith 767 (.collideWith
758 creature 768 creature
761 results) 771 results)
762 (if-let [target (first results)] 772 (if-let [target (first results)]
763 (.getGeometry target) 773 (.getGeometry target)
764 (recur (float (* 2 radius))))))) 774 (recur (float (* 2 radius)))))))
765 775
776 ;;dylan (defn follow-sense, adjoin-sense, attach-stimuli,
777 ;;anchor-qualia, augment-organ, with-organ
766 (defn bind-sense 778 (defn bind-sense
767 "Bind the sense to the Spatial such that it will maintain its 779 "Bind the sense to the Spatial such that it will maintain its
768 current position relative to the Spatial no matter how the spatial 780 current position relative to the Spatial no matter how the spatial
769 moves. 'sense can be either a Camera or Listener object." 781 moves. 'sense can be either a Camera or Listener object."
770 [#^Spatial obj sense] 782 [#^Spatial obj sense]
908 [(conj init-a init-b) 920 [(conj init-a init-b)
909 (into senses-a senses-b)]) 921 (into senses-a senses-b)])
910 [[][]] 922 [[][]]
911 (for [eye (creature-eyes creature)] 923 (for [eye (creature-eyes creature)]
912 (enable-vision creature eye)))) 924 (enable-vision creature eye))))
913 925
926
927
928
929
930 ;; lower level --- nodes
931 ;; closest-node "parse/compile-x" -> makes organ, which is spatial, fn pair
932
933 ;; higher level -- organs
934 ;;
935
936 ;; higher level --- sense/effector
937 ;; these are the functions that provide world i/o, chinese-room style
938
939
914 940
915 (defn blender-creature 941 (defn blender-creature
916 "Return a creature with all joints in place." 942 "Return a creature with all joints in place."
917 [blender-path] 943 [blender-path]
918 (let [model (load-blender-model blender-path) 944 (let [model (load-blender-model blender-path)
995 me (sphere 0.5 :color ColorRGBA/Blue :physical? false) 1021 me (sphere 0.5 :color ColorRGBA/Blue :physical? false)
996 [init-hearing-fns hearing-senses] (hearing creature) 1022 [init-hearing-fns hearing-senses] (hearing creature)
997 hearing-windows (map (fn [_] (debug-hearing-window 50)) 1023 hearing-windows (map (fn [_] (debug-hearing-window 50))
998 hearing-senses) 1024 hearing-senses)
999 bell (AudioNode. (asset-manager) 1025 bell (AudioNode. (asset-manager)
1000 "Sounds/ear-and-eye.wav" false) 1026 "Sounds/pure.wav" false)
1001 ;; dream 1027 ;; dream
1002 1028
1003 ] 1029 ]
1004 (world 1030 (world
1005 (nodify [creature 1031 (nodify [creature