# HG changeset patch # User Robert McIntyre # Date 1328365868 25200 # Node ID 0f1c7921d967c55bdddf5f4809595d4c46ad9466 # Parent f1b078375484d799ae6bf51e22843c9a47873b10 removed blender.org; got rid of magic constant in sense-utils. diff -r f1b078375484 -r 0f1c7921d967 org/blender.org --- a/org/blender.org Sat Feb 04 07:20:12 2012 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,19 +0,0 @@ -#+title: Blender Clojure utilities -#+author: Robert McIntyre -#+email: rlm@mit.edu -#+description: blender utilities -#+keywords: simulation, jMonkeyEngine3, clojure, blender -#+SETUPFILE: ../../aurellem/org/setup.org -#+INCLUDE: ../../aurellem/org/level-0.org - - -#+name: blender -#+begin_src clojure - -#+end_src - - -* COMMENT generate source -#+begin_src clojure :tangle ../src/cortex/blender.clj -<> -#+end_src diff -r f1b078375484 -r 0f1c7921d967 org/movement.org --- a/org/movement.org Sat Feb 04 07:20:12 2012 -0700 +++ b/org/movement.org Sat Feb 04 07:31:08 2012 -0700 @@ -87,7 +87,6 @@ (for [muscle (muscles creature)] (movement-fn creature muscle))) - #+end_src diff -r f1b078375484 -r 0f1c7921d967 org/sense-util.org --- a/org/sense-util.org Sat Feb 04 07:20:12 2012 -0700 +++ b/org/sense-util.org Sat Feb 04 07:31:08 2012 -0700 @@ -14,9 +14,12 @@ (import ij.process.ImageProcessor) (import java.awt.image.BufferedImage) (use 'cortex.util) +(use 'cortex.world) (import jme3tools.converters.ImageToAwt) -(defn meta-data [blender-node key] +(defn meta-data + "Get the meta-data for a node created with blender." + [blender-node key] (if-let [data (.getUserData blender-node "properties")] (.findValue data key) nil)) @@ -51,16 +54,21 @@ (controlUpdate [tpf] (let [total-rotation (.mult base-anti-rotation (.getWorldRotation obj))] - (.setLocation sense - (.add - (.mult total-rotation sense-offset) - (.getWorldTranslation obj))) - (.setRotation sense - (.mult total-rotation initial-sense-rotation)))) + (.setLocation + sense + (.add + (.mult total-rotation sense-offset) + (.getWorldTranslation obj))) + (.setRotation + sense + (.mult total-rotation initial-sense-rotation)))) (controlRender [_ _]))))) -(def white -1) - +(def white 0xFFFFFF) + +(defn white? [rgb] + (= (bit-and white rgb) white)) + (defn filter-pixels "List the coordinates of all pixels matching pred, within the bounds provided. Bounds -> [x0 y0 width height]" @@ -80,16 +88,13 @@ (defn white-coordinates "Coordinates of all the white pixels in a subset of the image." ([#^BufferedImage image bounds] - (filter-pixels #(= % white) image bounds)) + (filter-pixels white? image bounds)) ([#^BufferedImage image] - (filter-pixels #(= % white) image))) + (filter-pixels white? image))) (defn points->image "Take a sparse collection of points and visuliaze it as a BufferedImage." - - ;; TODO maybe parallelize this since it's easy - [points] (if (empty? points) (BufferedImage. 1 1 BufferedImage/TYPE_BYTE_BINARY) @@ -108,7 +113,6 @@ (dorun (for [index (range (count points))] (.setRGB image (- (xs index) x0) (- (ys index) y0) -1))) - image))) (defn average [coll] @@ -188,8 +192,20 @@ (ImageToAwt/convert (.getImage (.loadTexture (asset-manager) asset-relative-path)) false false 0)) - +(defn jme-to-blender + "Convert from JME coordinates to Blender coordinates" + [#^Vector3f in] + (Vector3f. (.getX in) + (- (.getZ in)) + (.getY in))) + +(defn blender-to-jme + "Convert from Blender coordinates to JME coordinates" + [#^Vector3f in] + (Vector3f. (.getX in) + (.getZ in) + (- (.getY in)))) #+end_src #+results: sense-util