comparison org/touch.org @ 227:2a7f57e7efdb

working on touch.org
author Robert McIntyre <rlm@mit.edu>
date Sat, 11 Feb 2012 14:12:17 -0700
parents e5db1d2ff9a8
children 0589c35f04f2
comparison
equal deleted inserted replaced
226:e5db1d2ff9a8 227:2a7f57e7efdb
15 #+begin_src clojure 15 #+begin_src clojure
16 (in-ns 'cortex.touch) 16 (in-ns 'cortex.touch)
17 17
18 (defn triangles 18 (defn triangles
19 "Return a sequence of all the Triangles which compose a given 19 "Return a sequence of all the Triangles which compose a given
20 Geometry." 20 Geometry."
21 [#^Geometry geom] 21 [#^Geometry geom]
22 (let 22 (let
23 [mesh (.getMesh geom) 23 [mesh (.getMesh geom)
24 triangles (transient [])] 24 triangles (transient [])]
25 (dorun 25 (dorun
61 or nil if it does not exist." 61 or nil if it does not exist."
62 [#^Geometry obj] 62 [#^Geometry obj]
63 (if-let [image-path (meta-data obj "touch")] 63 (if-let [image-path (meta-data obj "touch")]
64 (load-image image-path))) 64 (load-image image-path)))
65 65
66 (defn triangle 66 (defn mesh-triangle
67 "Get the triangle specified by triangle-index from the mesh within 67 "Get the triangle specified by triangle-index from the mesh within
68 bounds." 68 bounds."
69 [#^Mesh mesh triangle-index] 69 [#^Mesh mesh triangle-index]
70 (let [scratch (Triangle.)] 70 (let [scratch (Triangle.)]
71 (.getTriangle mesh triangle-index scratch) 71 (.getTriangle mesh triangle-index scratch)
78 (let [indices (int-array 3)] 78 (let [indices (int-array 3)]
79 (.getTriangle mesh triangle-index indices) 79 (.getTriangle mesh triangle-index indices)
80 (vec indices))) 80 (vec indices)))
81 81
82 (defn vertex-UV-coord 82 (defn vertex-UV-coord
83 "Get the uv-coordinates of the vertex named by vertex-index" 83 "Get the UV-coordinates of the vertex named by vertex-index"
84 [#^Mesh mesh vertex-index] 84 [#^Mesh mesh vertex-index]
85 (let [UV-buffer 85 (let [UV-buffer
86 (.getData 86 (.getData
87 (.getBuffer 87 (.getBuffer
88 mesh 88 mesh
89 VertexBuffer$Type/TexCoord))] 89 VertexBuffer$Type/TexCoord))]
90 [(.get UV-buffer (* vertex-index 2)) 90 [(.get UV-buffer (* vertex-index 2))
91 (.get UV-buffer (+ 1 (* vertex-index 2)))])) 91 (.get UV-buffer (+ 1 (* vertex-index 2)))]))
92 92
93 (defn triangle-UV-coord 93 (defn triangle-UV-coord
94 "Get the uv-cooridnates of the triangle's verticies." 94 "Get the UV-cooridnates of the triangle's verticies."
95 [#^Mesh mesh width height triangle-index] 95 [#^Mesh mesh width height triangle-index]
96 (map (fn [[u v]] (vector (* width u) (* height v))) 96 (map (fn [[u v]] (vector (* width u) (* height v)))
97 (map (partial vertex-UV-coord mesh) 97 (map (partial vertex-UV-coord mesh)
98 (triangle-vertex-indices mesh triangle-index)))) 98 (triangle-vertex-indices mesh triangle-index))))
99 99
198 (filter (comp (partial inside-triangle? cutout-triangle) 198 (filter (comp (partial inside-triangle? cutout-triangle)
199 (fn [[u v]] (Vector3f. u v 0))) 199 (fn [[u v]] (Vector3f. u v 0)))
200 (white-coordinates image bounds)) 200 (white-coordinates image bounds))
201 UV->geometry (triangle-transformation 201 UV->geometry (triangle-transformation
202 cutout-triangle 202 cutout-triangle
203 (triangle mesh tri-index)) 203 (mesh-triangle mesh tri-index))
204 geometry-sensor-coords 204 geometry-sensor-coords
205 (map (fn [[u v]] (.mult UV->geometry (Vector3f. u v 0))) 205 (map (fn [[u v]] (.mult UV->geometry (Vector3f. u v 0)))
206 UV-sensor-coords)] 206 UV-sensor-coords)]
207 {:UV UV-sensor-coords :geometry geometry-sensor-coords})) 207 {:UV UV-sensor-coords :geometry geometry-sensor-coords}))
208 208