diff org/eyes.org @ 167:9e6a30b8c99a

renamed some functions in eyes.org
author Robert McIntyre <rlm@mit.edu>
date Sat, 04 Feb 2012 04:07:25 -0700
parents aaacf087504c
children
line wrap: on
line diff
     1.1 --- a/org/eyes.org	Sat Feb 04 03:38:05 2012 -0700
     1.2 +++ b/org/eyes.org	Sat Feb 04 04:07:25 2012 -0700
     1.3 @@ -48,10 +48,6 @@
     1.4  the eye's camera are equal to the dimensions of the eye's "UV"
     1.5  map.
     1.6  
     1.7 -
     1.8 -
     1.9 -
    1.10 -
    1.11  #+name: eyes
    1.12  #+begin_src clojure 
    1.13  (ns cortex.vision
    1.14 @@ -60,6 +56,7 @@
    1.15    the observed data to any arbitray function."
    1.16    {:author "Robert McIntyre"}
    1.17    (:use (cortex world sense util))
    1.18 +  (:use clojure.contrib.def)
    1.19    (:import com.jme3.post.SceneProcessor)
    1.20    (:import (com.jme3.util BufferUtils Screenshots))
    1.21    (:import java.nio.ByteBuffer)
    1.22 @@ -67,7 +64,6 @@
    1.23    (:import com.jme3.renderer.ViewPort)
    1.24    (:import com.jme3.math.ColorRGBA)
    1.25    (:import com.jme3.renderer.Renderer)
    1.26 -  (:import jme3tools.converters.ImageToAwt)
    1.27    (:import com.jme3.scene.Node))
    1.28  
    1.29  (cortex.import/mega-import-jme3)
    1.30 @@ -124,10 +120,10 @@
    1.31    (byteBuffer->bufferedImage!
    1.32     (frameBuffer->byteBuffer! r fb bb) bi))
    1.33  
    1.34 -(defn add-eye
    1.35 +(defn add-eye!
    1.36    "Add an eye to the world, calling continuation on every frame
    1.37    produced." 
    1.38 -  [world camera continuation]
    1.39 +  [#^Application world camera continuation]
    1.40    (let [width (.getWidth camera)
    1.41  	height (.getHeight camera)
    1.42  	render-manager (.getRenderManager world)
    1.43 @@ -148,9 +144,7 @@
    1.44     [#^Spatial eye]
    1.45     (if-let [eye-map (meta-data eye "eye")]
    1.46       (map-vals
    1.47 -      #(ImageToAwt/convert
    1.48 -        (.getImage (.loadTexture (asset-manager) %))
    1.49 -        false false 0)
    1.50 +      load-image
    1.51        (eval (read-string eye-map)))))
    1.52  
    1.53  (defn eye-dimensions
    1.54 @@ -162,16 +156,11 @@
    1.55      [(apply max (map first dimensions))
    1.56       (apply max (map second dimensions))]))
    1.57  
    1.58 -(defn creature-eyes
    1.59 -  ;;dylan
    1.60 -  "Return the children of the creature's \"eyes\" node."
    1.61 -  ;;"The eye nodes which are children of the \"eyes\" node in the
    1.62 -  ;;creature."
    1.63 -  [#^Node creature]
    1.64 -  (if-let [eye-node (.getChild creature "eyes")]
    1.65 -    (seq (.getChildren eye-node))
    1.66 -    (do (println-repl "could not find eyes node") [])))
    1.67 -
    1.68 +(defvar 
    1.69 +  ^{:arglists '([creature])}
    1.70 +  eyes
    1.71 +  (sense-nodes "eyes")
    1.72 +  "Return the children of the creature's \"eyes\" node.")
    1.73  
    1.74  (defn attach-eye
    1.75    "Attach a Camera to the appropiate area and return the Camera."
    1.76 @@ -204,7 +193,7 @@
    1.77                           (.getHeight camera)
    1.78                           BufferedImage/TYPE_BYTE_BINARY))]
    1.79      [(fn [world]
    1.80 -       (add-eye
    1.81 +       (add-eye!
    1.82          world camera
    1.83          (let [counter  (atom 0)]
    1.84            (fn [r fb bb bi]
    1.85 @@ -233,7 +222,7 @@
    1.86       [(conj init-a init-b)
    1.87        (into senses-a senses-b)])
    1.88     [[][]]      
    1.89 -   (for [eye (creature-eyes creature)]
    1.90 +   (for [eye (eyes creature)]
    1.91       (enable-vision creature eye))))
    1.92  
    1.93  
    1.94 @@ -281,11 +270,11 @@
    1.95         (let [cam (.clone (.getCamera world))
    1.96               width (.getWidth cam)
    1.97               height (.getHeight cam)]
    1.98 -         (add-eye world cam 
    1.99 +         (add-eye! world cam 
   1.100                    ;;no-op
   1.101                    (comp (view-image) BufferedImage!)
   1.102                    )
   1.103 -         (add-eye world
   1.104 +         (add-eye! world
   1.105                    (doto (.clone cam)
   1.106                      (.setLocation (Vector3f. -10 0 0))
   1.107                      (.lookAt Vector3f/ZERO Vector3f/UNIT_Y))
   1.108 @@ -293,7 +282,7 @@
   1.109                    (comp (view-image) BufferedImage!))
   1.110           ;; This is here to restore the main view
   1.111           ;; after the other views have completed processing
   1.112 -         (add-eye world (.getCamera world) no-op)))
   1.113 +         (add-eye! world (.getCamera world) no-op)))
   1.114       (fn [world tpf]
   1.115         (.rotate candy (* tpf 0.2) 0 0)))))
   1.116  #+end_src