diff org/touch.org @ 240:6961377c4554

saving progress...
author Robert McIntyre <rlm@mit.edu>
date Sun, 12 Feb 2012 13:25:42 -0700
parents 78a640e3bc55
children f2e583be8584
line wrap: on
line diff
     1.1 --- a/org/touch.org	Sun Feb 12 12:58:01 2012 -0700
     1.2 +++ b/org/touch.org	Sun Feb 12 13:25:42 2012 -0700
     1.3 @@ -106,15 +106,15 @@
     1.4      
     1.5    - Find the coordinates of each pixel in pixel space. These
     1.6      coordinates are used to make the touch-topology.
     1.7 -    =(sensors-in-triangle)=
     1.8 +    =(feeler-pixel-coords)=
     1.9  
    1.10    - Find the coordinates of each pixel in world-space. These
    1.11 -    coordinates are the origins of the feelers.
    1.12 +    coordinates are the origins of the feelers. =(feeler-origins)=
    1.13      
    1.14    - Calculate the normals of the triangles in world space, and add
    1.15      them to each of the origins of the feelers. These are the
    1.16      normalized coordinates of the tips of the feelers.
    1.17 -    For both of these, =(feelers)=
    1.18 +    For both of these, =(feeler-tips)=
    1.19  
    1.20    - Generate some sort of topology for the sensors.
    1.21      =(touch-topology)=
    1.22 @@ -223,14 +223,37 @@
    1.23  
    1.24  #+name: sensors
    1.25  #+begin_src clojure
    1.26 -(defn pixel-feelers 
    1.27 +(in-ns 'cortex.touch)
    1.28 +
    1.29 +(defn feeler-pixel-coords
    1.30   "Returns the coordinates of the feelers in pixel space in lists, one
    1.31    list for each triangle, ordered in the same way as (triangles) and
    1.32    (pixel-triangles)."
    1.33   [#^Geometry geo image]
    1.34 + (map 
    1.35 +  (fn [pixel-triangle]
    1.36 +    (filter
    1.37 +     (fn [coord]
    1.38 +       (inside-triangle? (->triangle pixel-triangle)
    1.39 +                         (->vector3f coord)))
    1.40 +       (white-coordinates image (convex-bounds pixel-triangle))))
    1.41 +  (pixel-triangles geo image)))
    1.42  
    1.43 +(defn feeler-origins [#^Geometry geo image]
    1.44 +  (let [transforms
    1.45 +        (map #(triangles->affine-transform
    1.46 +               (->triangle %1) (->triangle %2))
    1.47 +             (pixel-triangles geo image)
    1.48 +             (triangles geo))]
    1.49 +    (mapcat (fn [transform coords]
    1.50 +              (map #(.mult transform (->vector3f %)) coords))
    1.51 +            transforms (feeler-pixel-coords geo image))))
    1.52  
    1.53 -
    1.54 +(defn feeler-tips [#^Geometry geo image]
    1.55 +  (let [origins (feeler-origins geo image)]
    1.56 +    (
    1.57 +  
    1.58 +)
    1.59  
    1.60  
    1.61  
    1.62 @@ -341,7 +364,10 @@
    1.63     (vector3f-seq (.get2 tri))
    1.64     (vector3f-seq (.get3 tri))])
    1.65  
    1.66 -(defn ->vector3f [[x y z]] (Vector3f. x y z))
    1.67 +(defn ->vector3f 
    1.68 +  ([coords] (Vector3f. (nth coords 0 0)
    1.69 +                       (nth coords 1 0)
    1.70 +                       (nth coords 2 0))))
    1.71  
    1.72  (defn ->triangle [points]
    1.73    (apply #(Triangle. %1 %2 %3) (map ->vector3f points)))
    1.74 @@ -423,7 +449,7 @@
    1.75           (.set mat 3 row 1))))
    1.76      mat))
    1.77  
    1.78 -(defn triangle-transformation
    1.79 +(defn triangles->affine-transform
    1.80    "Returns the affine transformation that converts each vertex in the
    1.81     first triangle into the corresponding vertex in the second
    1.82     triangle."
    1.83 @@ -482,9 +508,9 @@
    1.84  (defn convex-bounds
    1.85    "Returns the smallest square containing the given vertices, as a
    1.86     vector of integers [left top width height]."
    1.87 -  [uv-verts]
    1.88 -  (let [xs (map first uv-verts)
    1.89 -        ys (map second uv-verts)
    1.90 +  [verts]
    1.91 +  (let [xs (map first verts)
    1.92 +        ys (map second verts)
    1.93          x0 (Math/floor (apply min xs))
    1.94          y0 (Math/floor (apply min ys))
    1.95          x1 (Math/ceil (apply max xs))
    1.96 @@ -505,13 +531,16 @@
    1.97    "Is the point inside the triangle?"
    1.98    {:author "Dylan Holmes"}
    1.99    [#^Triangle tri #^Vector3f p]
   1.100 -  (let [[vert-1 vert-2 vert-3] (triangle-seq tri)]
   1.101 +  (let [[vert-1 vert-2 vert-3] [(.get1 tri) (.get2 tri) (.get3 tri)]]
   1.102      (and
   1.103       (same-side? vert-1 vert-2 vert-3 p)
   1.104       (same-side? vert-2 vert-3 vert-1 p)
   1.105       (same-side? vert-3 vert-1 vert-2 p))))
   1.106  #+end_src
   1.107  
   1.108 +#+results: triangles-4
   1.109 +: #'cortex.touch/inside-triangle?
   1.110 +
   1.111  
   1.112  * Physics Collision Objects
   1.113