comparison org/test-creature.org @ 111:61d9c0e8d188

don't create useless touch-maps, add some eye stuf
author Robert McIntyre <rlm@mit.edu>
date Thu, 19 Jan 2012 08:09:15 -0700
parents f89f0b9ed2fe
children 128fa71ee188
comparison
equal deleted inserted replaced
110:f89f0b9ed2fe 111:61d9c0e8d188
408 "Common/MatDefs/Misc/Unshaded.j3md") 408 "Common/MatDefs/Misc/Unshaded.j3md")
409 (.setColor "Color" color) 409 (.setColor "Color" color)
410 (-> (.getAdditionalRenderState) 410 (-> (.getAdditionalRenderState)
411 (.setDepthTest false)))) 411 (.setDepthTest false))))
412 412
413
414
415 (defn colorful [] 413 (defn colorful []
416 (.getChild (worm-model) "worm-21")) 414 (.getChild (worm-model) "worm-21"))
417 415
418 (import jme3tools.converters.ImageToAwt) 416 (import jme3tools.converters.ImageToAwt)
419 417
626 (let [feeler-coords (feeler-coordinates geo) 624 (let [feeler-coords (feeler-coordinates geo)
627 tris (triangles geo) 625 tris (triangles geo)
628 limit 0.1 626 limit 0.1
629 ;;results (CollisionResults.) 627 ;;results (CollisionResults.)
630 ] 628 ]
631 (fn [node] 629 (if (empty? (touch-topology geo))
632 (let [sensor-origins 630 nil
633 (map 631 (fn [node]
634 #(map (partial local-to-world geo) %) 632 (let [sensor-origins
635 feeler-coords) 633 (map
636 triangle-normals 634 #(map (partial local-to-world geo) %)
637 (map (partial get-ray-direction geo) 635 feeler-coords)
638 tris) 636 triangle-normals
639 rays 637 (map (partial get-ray-direction geo)
640 (flatten 638 tris)
641 (map (fn [origins norm] 639 rays
642 (map #(doto (Ray. % norm) 640 (flatten
641 (map (fn [origins norm]
642 (map #(doto (Ray. % norm)
643 (.setLimit limit)) origins)) 643 (.setLimit limit)) origins))
644 sensor-origins triangle-normals))] 644 sensor-origins triangle-normals))]
645 (vector 645 (vector
646 (touch-topology geo) 646 (touch-topology geo)
647 (vec 647 (vec
648 (for [ray rays] 648 (for [ray rays]
649 (do 649 (do
650 (let [results (CollisionResults.)] 650 (let [results (CollisionResults.)]
651 (.collideWith node ray results) 651 (.collideWith node ray results)
652 (let [touch-objects 652 (let [touch-objects
653 (set 653 (set
654 (filter #(not (= geo %)) 654 (filter #(not (= geo %))
655 (map #(.getGeometry %) results)))] 655 (map #(.getGeometry %) results)))]
656 (if (> (count touch-objects) 0) 656 (if (> (count touch-objects) 0)
657 1 0))))))))))) 657 1 0))))))))))))
658 658
659
660
661 (defn touch [#^Node pieces] 659 (defn touch [#^Node pieces]
662 (map enable-touch 660 (filter (comp not nil?)
663 (filter #(isa? (class %) Geometry) 661 (map enable-touch
664 (node-seq pieces)))) 662 (filter #(isa? (class %) Geometry)
663 (node-seq pieces)))))
664
665
666 ;; human eye transmits 62kb/s to brain Bandwidth is 8.75 Mb/s
667 ;; http://en.wikipedia.org/wiki/Retina
668
669 (defn test-eye []
670 (.getChild (worm-model) "worm-11"))
671
672
673 (defn retina-sensor-image
674 "Return a map of pixel selection functions to BufferedImages
675 describing the distribution of light-sensitive components on this
676 geometry's surface. Each function creates an integer from the rgb
677 values found in the pixel. :red, :green, :blue, :gray are already
678 defined as extracting the red green blue and average components
679 respectively."
680 [#^Geometry eye]
681 (if-let [eye-map (meta-data eye "eye")]
682 (map-vals
683 #(ImageToAwt/convert
684 (.getImage (.loadTexture (asset-manager) %))
685 false false 0)
686 (read-string
687 eye-map))))
688
689
690
691
665 692
666 (defn debug-window 693 (defn debug-window
667 "creates function that offers a debug view of sensor data" 694 "creates function that offers a debug view of sensor data"
668 [] 695 []
669 (let [vi (view-image)] 696 (let [vi (view-image)]