# HG changeset patch # User Robert McIntyre # Date 1326256001 25200 # Node ID 4a9096f31017c45079f5fdbf140840b5bbc2fdd2 # Parent e4bcd0c481ba014e82b6e6b6c73f40437871ab1e working on touch diff -r e4bcd0c481ba -r 4a9096f31017 assets/Models/creature1/tip.png Binary file assets/Models/creature1/tip.png has changed diff -r e4bcd0c481ba -r 4a9096f31017 org/test-creature.org --- a/org/test-creature.org Tue Jan 10 08:38:50 2012 -0700 +++ b/org/test-creature.org Tue Jan 10 21:26:41 2012 -0700 @@ -125,6 +125,15 @@ (let [out (Vector3f.)] (.worldToLocal object world-coordinate out) out)) +(defn local-to-world + "Convert the local coordinates into coordinates into world relative + coordinates" + [#^Spatial object local-coordinate] + (let [world-coordinate (Vector3f.)] + (.localToWorld object local-coordinate world-coordinate) + world-coordinate)) + + (defmulti joint-dispatch "Translate blender pseudo-joints into real JME joints." (fn [constraints & _] @@ -506,6 +515,9 @@ 0)) (uv-triangle mesh tri))) +(def rasterize pixel-triangle) + + (defn triangle-bounds "Dimensions of the bounding square of the triangle in the form [x y width height]. @@ -525,14 +537,13 @@ "Search the geometry's tactile UV image for touch sensors, returning their positions in geometry-relative coordinates." [#^Geometry geo] - - ;; inside-triangle? white-coordinates triangle-transformation - ;; tri-uv-coord touch-receptor-image (let [mesh (.getMesh geo) + tris (triangles geo) + image (touch-receptor-image geo) width (.getWidth image) height (.getHeight image) - tris (triangles geo) + ;; for each triangle sensor-coords @@ -560,11 +571,99 @@ ;; translate pixel coordinates to world-space transform (triangle-transformation cutout-tri tri)] (map #(.mult transform %) whites))))] - (map sensor-coords tris))) + + (vec (map sensor-coords tris)))) + +(defn locate-tactile-sensors* + "Search the geometry's tactile UV image for touch sensors, returning + their positions in geometry-relative coordinates." + [#^Geometry geo] + (let [uv-image (touch-receptor-image geo) + width (.getWidth uv-image) + height (.getHeight uv-image) + + mesh (.getMesh geo) + mesh-tris (triangles geo) + + ;; for each triangle + sensor-coords + (fn [tri] + ;; translate triangle to uv-pixel-space + (let [uv-tri + (rasterize mesh tri width height) + bounds (vec (triangle-bounds uv-tri))] + + ;; get that part of the picture + + (apply (partial (memfn setRoi) uv-image) bounds) + (let [cutout (.crop (.getProcessor uv-image)) + ;; extract white pixels inside triangle + cutout-tri + (map-triangle + (fn [_ v] + (.subtract + v + (Vector3f. (bounds 0) (bounds 1) (float 0)))) + uv-tri) + whites (filter (partial inside-triangle? cutout-tri) + (map vector2f->vector3f + (white-coordinates cutout))) + ;; translate pixel coordinates to world-space + transform (triangle-transformation cutout-tri tri)] + (map #(.mult transform %) whites))))] + + + + (for [mesh-tri mesh-tris] + + (let [uv-tri (rasterize mesh mesh-tri width height) + bounding-box (vec (triangle-bounds uv-tri))] + (apply (partial (memfn setRoi) uv-image) bounding-box) + + + + + )) + (vec (map sensor-coords mesh-tris)))) + + + +(defn measure-touchies [#^Geometry geo] + (let [tactile-sensor-coords (locate-tactile-sensors geo) + tris (triangles geo)] + (fn [world] + (let [sensor-origins (vec + (map + #(map (partial local-to-world geo) %) + tactile-sensor-coords)) + triangle-normals (vec + (map (partial get-ray-direction geo) + tris)) + rays (flatten + (map + (fn [origins normals] + (map + #(Ray. %1 %2) + origins + normals)) + sensor-origins + (map repeat triangle-normals))) + - + ] + rays)))) + + + + + + + + + +