Mercurial > cortex
changeset 167:9e6a30b8c99a
renamed some functions in eyes.org
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 04 Feb 2012 04:07:25 -0700 |
parents | e4c2cc79a171 |
children | 1c8e9d389ea4 |
files | org/eyes.org org/hearing.org org/sense-util.org org/test-creature.org |
diffstat | 4 files changed, 29 insertions(+), 42 deletions(-) [+] |
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
2.1 --- a/org/hearing.org Sat Feb 04 03:38:05 2012 -0700 2.2 +++ b/org/hearing.org Sat Feb 04 04:07:25 2012 -0700 2.3 @@ -741,22 +741,13 @@ 2.4 2.5 * Finally, Ears in clojure! 2.6 2.7 -Now that the infrastructure is complete (modulo a few patches to 2.8 -jMonkeyEngine3 to support accessing this modified version of =OpenAL= 2.9 -that are not worth discussing), the clojure ear abstraction is rather 2.10 -simple. Just as there were =SceneProcessors= for vision, there are 2.11 +Now that the infrastructure is complete the clojure ear abstraction is 2.12 +simple. Just as there were =SceneProcessors= for vision, there are 2.13 now =SoundProcessors= for hearing. 2.14 2.15 #+include "../../jmeCapture/src/com/aurellem/capture/audio/SoundProcessor.java" src java 2.16 2.17 2.18 -Ears work the same way as vision. 2.19 - 2.20 -(hearing creature) will return [init-functions sensor-functions]. The 2.21 -init functions each take the world and register a SoundProcessor that 2.22 -does foureier transforms on the incommong sound data, making it 2.23 -available to each sensor function. 2.24 - 2.25 2.26 #+name: ears 2.27 #+begin_src clojure 2.28 @@ -866,7 +857,6 @@ 2.29 (for [ear (ears creature)] 2.30 (hearing-fn creature ear))) 2.31 2.32 - 2.33 #+end_src 2.34 2.35 * Example
3.1 --- a/org/sense-util.org Sat Feb 04 03:38:05 2012 -0700 3.2 +++ b/org/sense-util.org Sat Feb 04 04:07:25 2012 -0700 3.3 @@ -13,7 +13,8 @@ 3.4 (cortex.import/mega-import-jme3) 3.5 (import ij.process.ImageProcessor) 3.6 (import java.awt.image.BufferedImage) 3.7 - 3.8 +(use 'cortex.util) 3.9 +(import jme3tools.converters.ImageToAwt) 3.10 3.11 (defn meta-data [blender-node key] 3.12 (if-let [data (.getUserData blender-node "properties")] 3.13 @@ -181,6 +182,13 @@ 3.14 (seq (.getChildren sense-node)) 3.15 (do (println-repl "could not find" parent-name "node") [])))) 3.16 3.17 +(defn load-image 3.18 + "Load an image as a BufferedImage using the asset-manager system." 3.19 + [asset-relative-path] 3.20 + (ImageToAwt/convert 3.21 + (.getImage (.loadTexture (asset-manager) asset-relative-path)) 3.22 + false false 0)) 3.23 + 3.24 3.25 #+end_src 3.26
4.1 --- a/org/test-creature.org Sat Feb 04 03:38:05 2012 -0700 4.2 +++ b/org/test-creature.org Sat Feb 04 04:07:25 2012 -0700 4.3 @@ -233,11 +233,11 @@ 4.4 (dorun (map #(% world) init-vision-fns)) 4.5 ;;(dorun (map #(% world) init-hearing-fns)) 4.6 4.7 - (add-eye world 4.8 + (add-eye! world 4.9 (attach-eye creature (test-eye)) 4.10 (comp (view-image) BufferedImage!)) 4.11 4.12 - (add-eye world (.getCamera world) no-op) 4.13 + (add-eye! world (.getCamera world) no-op) 4.14 ;;(set-gravity world (Vector3f. 0 0 0)) 4.15 ;;(com.aurellem.capture.Capture/captureVideo 4.16 ;; world (file-str "/home/r/proj/ai-videos/hand")) 4.17 @@ -308,8 +308,8 @@ 4.18 (bind-sense rock cam) 4.19 4.20 (.setTimer world (RatchetTimer. 60)) 4.21 - (add-eye world cam (comp (view-image) BufferedImage!)) 4.22 - (add-eye world (.getCamera world) no-op)) 4.23 + (add-eye! world cam (comp (view-image) BufferedImage!)) 4.24 + (add-eye! world (.getCamera world) no-op)) 4.25 ) 4.26 (fn [_ _] (println-repl rot))))) 4.27