# HG changeset patch # User Robert McIntyre # Date 1328366688 25200 # Node ID f2552d61e8df567a2134b0a2ea14b8808b99de24 # Parent 0f1c7921d967c55bdddf5f4809595d4c46ad9466 cleaned up sense-utils some more, tested system again. diff -r 0f1c7921d967 -r f2552d61e8df org/sense-util.org --- a/org/sense-util.org Sat Feb 04 07:31:08 2012 -0700 +++ b/org/sense-util.org Sat Feb 04 07:44:48 2012 -0700 @@ -6,16 +6,21 @@ #+SETUPFILE: ../../aurellem/org/setup.org #+INCLUDE: ../../aurellem/org/level-0.org - #+name: sense-util #+begin_src clojure -(ns cortex.sense) -(cortex.import/mega-import-jme3) -(import ij.process.ImageProcessor) -(import java.awt.image.BufferedImage) -(use 'cortex.util) -(use 'cortex.world) -(import jme3tools.converters.ImageToAwt) +(ns cortex.sense + "Here are functions usefull in the construction of two or more + senses/effectors." + {:author "Robert McInytre"} + (:use (cortex world util)) + (:import ij.process.ImageProcessor) + (:import jme3tools.converters.ImageToAwt) + (:import java.awt.image.BufferedImage) + (:import com.jme3.collision.CollisionResults) + (:import com.jme3.bounding.BoundingBox) + (:import (com.jme3.scene Node Spatial)) + (:import com.jme3.scene.control.AbstractControl) + (:import (com.jme3.math Quaternion Vector3f))) (defn meta-data "Get the meta-data for a node created with blender." @@ -25,8 +30,7 @@ nil)) (defn closest-node - "Return the object in creature which is closest to the given node." - ;;dylan"The closest object in creature to the given node." + "Return the node in creature which is closest to the given node." [#^Node creature #^Node eye] (loop [radius (float 0.01)] (let [results (CollisionResults.)] @@ -71,7 +75,8 @@ (defn filter-pixels "List the coordinates of all pixels matching pred, within the bounds - provided. Bounds -> [x0 y0 width height]" + provided. + bounds -> [x0 y0 width height]" {:author "Dylan Holmes"} ([pred #^BufferedImage image] (filter-pixels pred image [0 0 (.getWidth image) (.getHeight image)])) @@ -119,7 +124,7 @@ (/ (reduce + coll) (count coll))) (defn collapse-1d - "One dimensional analogue of collapse" + "One dimensional analogue of collapse." [center line] (let [length (count line) num-above (count (filter (partial < center) line)) @@ -129,7 +134,7 @@ (defn collapse "Take a set of pairs of integers and collapse them into a - contigous bitmap." + contigous bitmap with no \"holes\"." [points] (if (empty? points) [] (let @@ -157,30 +162,33 @@ (map first row)) (map second row))) (partition-by second (sort-by second flattened)))) - relocate + relocated (let [min-x (apply min (map first squeezed)) min-y (apply min (map second squeezed))] (map (fn [[x y]] [(- x min-x) (- y min-y)]) squeezed))] - relocate))) + relocated))) (defn world-to-local - "Convert the world coordinates into coordinates relative to the + "Convert the world coordinates into coordinates relative to the object (i.e. local coordinates), taking into account the rotation of object." - [#^Spatial object world-coordinate] - (.worldToLocal object world-coordinate nil)) + [#^Spatial object world-coordinate] + (.worldToLocal object world-coordinate nil)) (defn local-to-world - "Convert the local coordinates into coordinates into world relative - coordinates" - [#^Spatial object local-coordinate] - (.localToWorld object local-coordinate nil)) + "Convert the local coordinates into world relative coordinates" + [#^Spatial object local-coordinate] + (.localToWorld object local-coordinate nil)) - -(defn sense-nodes [parent-name] +(defn sense-nodes + "For each sense there is a special blender node whose children are + considered markers for an instance of a that sense. This function + generates functions to find those children, given the name of the + special parent node." + [parent-name] (fn [#^Node creature] (if-let [sense-node (.getChild creature parent-name)] (seq (.getChildren sense-node))