# HG changeset patch # User Robert McIntyre # Date 1329078342 25200 # Node ID 6961377c4554f8b2fbe4d2314084b7afa6140904 # Parent 78a640e3bc556fae52392c25376f3544cd29924a saving progress... diff -r 78a640e3bc55 -r 6961377c4554 org/touch.org --- a/org/touch.org Sun Feb 12 12:58:01 2012 -0700 +++ b/org/touch.org Sun Feb 12 13:25:42 2012 -0700 @@ -106,15 +106,15 @@ - Find the coordinates of each pixel in pixel space. These coordinates are used to make the touch-topology. - =(sensors-in-triangle)= + =(feeler-pixel-coords)= - Find the coordinates of each pixel in world-space. These - coordinates are the origins of the feelers. + coordinates are the origins of the feelers. =(feeler-origins)= - Calculate the normals of the triangles in world space, and add them to each of the origins of the feelers. These are the normalized coordinates of the tips of the feelers. - For both of these, =(feelers)= + For both of these, =(feeler-tips)= - Generate some sort of topology for the sensors. =(touch-topology)= @@ -223,14 +223,37 @@ #+name: sensors #+begin_src clojure -(defn pixel-feelers +(in-ns 'cortex.touch) + +(defn feeler-pixel-coords "Returns the coordinates of the feelers in pixel space in lists, one list for each triangle, ordered in the same way as (triangles) and (pixel-triangles)." [#^Geometry geo image] + (map + (fn [pixel-triangle] + (filter + (fn [coord] + (inside-triangle? (->triangle pixel-triangle) + (->vector3f coord))) + (white-coordinates image (convex-bounds pixel-triangle)))) + (pixel-triangles geo image))) +(defn feeler-origins [#^Geometry geo image] + (let [transforms + (map #(triangles->affine-transform + (->triangle %1) (->triangle %2)) + (pixel-triangles geo image) + (triangles geo))] + (mapcat (fn [transform coords] + (map #(.mult transform (->vector3f %)) coords)) + transforms (feeler-pixel-coords geo image)))) - +(defn feeler-tips [#^Geometry geo image] + (let [origins (feeler-origins geo image)] + ( + +) @@ -341,7 +364,10 @@ (vector3f-seq (.get2 tri)) (vector3f-seq (.get3 tri))]) -(defn ->vector3f [[x y z]] (Vector3f. x y z)) +(defn ->vector3f + ([coords] (Vector3f. (nth coords 0 0) + (nth coords 1 0) + (nth coords 2 0)))) (defn ->triangle [points] (apply #(Triangle. %1 %2 %3) (map ->vector3f points))) @@ -423,7 +449,7 @@ (.set mat 3 row 1)))) mat)) -(defn triangle-transformation +(defn triangles->affine-transform "Returns the affine transformation that converts each vertex in the first triangle into the corresponding vertex in the second triangle." @@ -482,9 +508,9 @@ (defn convex-bounds "Returns the smallest square containing the given vertices, as a vector of integers [left top width height]." - [uv-verts] - (let [xs (map first uv-verts) - ys (map second uv-verts) + [verts] + (let [xs (map first verts) + ys (map second verts) x0 (Math/floor (apply min xs)) y0 (Math/floor (apply min ys)) x1 (Math/ceil (apply max xs)) @@ -505,13 +531,16 @@ "Is the point inside the triangle?" {:author "Dylan Holmes"} [#^Triangle tri #^Vector3f p] - (let [[vert-1 vert-2 vert-3] (triangle-seq tri)] + (let [[vert-1 vert-2 vert-3] [(.get1 tri) (.get2 tri) (.get3 tri)]] (and (same-side? vert-1 vert-2 vert-3 p) (same-side? vert-2 vert-3 vert-1 p) (same-side? vert-3 vert-1 vert-2 p)))) #+end_src +#+results: triangles-4 +: #'cortex.touch/inside-triangle? + * Physics Collision Objects