diff org/sense-util.org @ 181:0f1c7921d967

removed blender.org; got rid of magic constant in sense-utils.
author Robert McIntyre <rlm@mit.edu>
date Sat, 04 Feb 2012 07:31:08 -0700
parents 9e6a30b8c99a
children f2552d61e8df
line wrap: on
line diff
     1.1 --- a/org/sense-util.org	Sat Feb 04 07:20:12 2012 -0700
     1.2 +++ b/org/sense-util.org	Sat Feb 04 07:31:08 2012 -0700
     1.3 @@ -14,9 +14,12 @@
     1.4  (import ij.process.ImageProcessor)
     1.5  (import java.awt.image.BufferedImage)
     1.6  (use 'cortex.util)
     1.7 +(use 'cortex.world)
     1.8  (import jme3tools.converters.ImageToAwt)
     1.9  
    1.10 -(defn meta-data [blender-node key]
    1.11 +(defn meta-data
    1.12 +  "Get the meta-data for a node created with blender."
    1.13 +  [blender-node key]
    1.14    (if-let [data (.getUserData blender-node "properties")]
    1.15      (.findValue data key)
    1.16      nil))
    1.17 @@ -51,16 +54,21 @@
    1.18         (controlUpdate [tpf]
    1.19           (let [total-rotation
    1.20                 (.mult base-anti-rotation (.getWorldRotation obj))]
    1.21 -           (.setLocation sense
    1.22 -                         (.add
    1.23 -                          (.mult total-rotation sense-offset)
    1.24 -                          (.getWorldTranslation obj)))
    1.25 -           (.setRotation sense
    1.26 -                         (.mult total-rotation initial-sense-rotation))))
    1.27 +           (.setLocation
    1.28 +            sense
    1.29 +            (.add
    1.30 +             (.mult total-rotation sense-offset)
    1.31 +             (.getWorldTranslation obj)))
    1.32 +           (.setRotation
    1.33 +            sense
    1.34 +            (.mult total-rotation initial-sense-rotation))))
    1.35         (controlRender [_ _])))))
    1.36  
    1.37 -(def white -1)
    1.38 -  
    1.39 +(def white 0xFFFFFF)
    1.40 +
    1.41 +(defn white? [rgb]
    1.42 +  (= (bit-and white rgb) white))
    1.43 +
    1.44  (defn filter-pixels
    1.45    "List the coordinates of all pixels matching pred, within the bounds
    1.46     provided. Bounds -> [x0 y0 width height]"
    1.47 @@ -80,16 +88,13 @@
    1.48  (defn white-coordinates
    1.49    "Coordinates of all the white pixels in a subset of the image."
    1.50    ([#^BufferedImage image bounds]
    1.51 -     (filter-pixels #(= % white) image bounds))
    1.52 +     (filter-pixels white? image bounds))
    1.53    ([#^BufferedImage image]
    1.54 -     (filter-pixels #(= % white) image)))
    1.55 +     (filter-pixels white? image)))
    1.56  
    1.57  (defn points->image
    1.58    "Take a sparse collection of points and visuliaze it as a
    1.59     BufferedImage."
    1.60 -
    1.61 -  ;; TODO maybe parallelize this since it's easy
    1.62 -
    1.63    [points]
    1.64    (if (empty? points)
    1.65      (BufferedImage. 1 1 BufferedImage/TYPE_BYTE_BINARY)
    1.66 @@ -108,7 +113,6 @@
    1.67        (dorun 
    1.68         (for [index (range (count points))]
    1.69           (.setRGB image (- (xs index) x0) (- (ys index) y0) -1)))
    1.70 -      
    1.71        image)))
    1.72  
    1.73  (defn average [coll]
    1.74 @@ -188,8 +192,20 @@
    1.75    (ImageToAwt/convert
    1.76     (.getImage (.loadTexture (asset-manager) asset-relative-path))
    1.77     false false 0))
    1.78 -  
    1.79  
    1.80 +(defn jme-to-blender
    1.81 +  "Convert from JME coordinates to Blender coordinates"
    1.82 +  [#^Vector3f in]
    1.83 +  (Vector3f. (.getX in)
    1.84 +             (- (.getZ in))
    1.85 +             (.getY in)))
    1.86 +
    1.87 +(defn blender-to-jme
    1.88 +  "Convert from Blender coordinates to JME coordinates"
    1.89 +  [#^Vector3f in]
    1.90 +  (Vector3f. (.getX in)
    1.91 +             (.getZ in)
    1.92 +             (- (.getY in))))
    1.93  #+end_src
    1.94  
    1.95  #+results: sense-util