comparison org/touch.org @ 234:712bd7e5b148

saving progress
author Robert McIntyre <rlm@mit.edu>
date Sun, 12 Feb 2012 09:05:47 -0700
parents f27c9fd9134d
children 3fa49ff1649a
comparison
equal deleted inserted replaced
233:f27c9fd9134d 234:712bd7e5b148
72 #+end_src 72 #+end_src
73 73
74 ** TODO add image showing example touch-uv map 74 ** TODO add image showing example touch-uv map
75 ** TODO add metadata display for worm 75 ** TODO add metadata display for worm
76 76
77
77 * Skin Creation 78 * Skin Creation
79 * TODO get the actual lengths for each hair
80
81 #+begin_src clojure
82 pixel-triangles
83 xyz-triangles
84 conversions (map triangles->affine-transform pixel-triangles
85 xyz-triangles)
86
87 #+end_src
88
78 #+name: kernel 89 #+name: kernel
79 #+begin_src clojure 90 #+begin_src clojure
80 (in-ns 'cortex.touch) 91 (in-ns 'cortex.touch)
81 92
93 (declare touch-topology touch-hairs set-ray)
94
82 (defn touch-kernel 95 (defn touch-kernel
96 "Constructs a function which will return tactile sensory data from
97 'geo when called from inside a running simulation"
98 [#^Geometry geo]
99 (let [[ray-reference-origins
100 ray-reference-tips
101 ray-lengths] (touch-hairs geo)
102 current-rays (map (fn [] (Ray.)) ray-reference-origins)
103 topology (touch-topology geo)]
104 (if (empty? ray-reference-origins) nil
105 (fn [node]
106 (let [transform (.getWorldMatrix geo)]
107 (dorun
108 (map (fn [ray ref-origin ref-tip length]
109 (set-ray ray transform ref-origin ref-tip length))
110 current-rays ray-reference-origins
111 ray-reference-tips ray-lengths))
112 (vector
113 topology
114 (vec
115 (for [ray current-rays]
116 (do
117 (let [results (CollisionResults.)]
118 (.collideWith node ray results)
119 (let [touch-objects
120 (filter #(not (= geo (.getGeometry %)))
121 results)]
122 [(if (empty? touch-objects)
123 (.getLimit ray)
124 (.getDistance (first touch-objects)))
125 (.getLimit ray)])))))))))))
126
127 (defn touch-kernel*
83 "Returns a function which returns tactile sensory data when called 128 "Returns a function which returns tactile sensory data when called
84 inside a running simulation." 129 inside a running simulation."
85 [#^Geometry geo] 130 [#^Geometry geo]
86 (let [feeler-coords (feeler-coordinates geo) 131 (let [feeler-coords (feeler-coordinates geo)
87 tris (triangles geo) 132 tris (triangles geo)
346 (same-side? vert-2 vert-3 vert-1 p) 391 (same-side? vert-2 vert-3 vert-1 p)
347 (same-side? vert-3 vert-1 vert-2 p)))) 392 (same-side? vert-3 vert-1 vert-2 p))))
348 #+end_src 393 #+end_src
349 394
350 395
351
352 * Sensor Related Functions 396 * Sensor Related Functions
353 397
354 These functions analyze the touch-sensor-profile image convert the 398 These functions analyze the touch-sensor-profile image convert the
355 location of each touch sensor from pixel coordinates to UV-coordinates 399 location of each touch sensor from pixel coordinates to UV-coordinates
356 and XYZ-coordinates. 400 and XYZ-coordinates.
404 (vec (map :geometry (locate-feelers geo)))) 448 (vec (map :geometry (locate-feelers geo))))
405 #+end_src 449 #+end_src
406 450
407 * Physics Collision Objects 451 * Physics Collision Objects
408 452
409 The "hairs" are actually rays which extend from a point on a 453 The "hairs" are actually =Rays= which extend from a point on a
410 =Triangle= in the =Mesh= normal to the =Triangle's= surface. 454 =Triangle= in the =Mesh= normal to the =Triangle's= surface.
411 455
412 #+name: rays 456 #+name: rays
413 #+begin_src clojure 457 #+begin_src clojure
414 (defn get-ray-origin 458 (defn get-ray-origin
431 (.localToWorld 475 (.localToWorld
432 geom 476 geom
433 (.add (.getCenter tri) (.getNormal tri)) n+c) 477 (.add (.getCenter tri) (.getNormal tri)) n+c)
434 (.subtract n+c (get-ray-origin geom tri)))) 478 (.subtract n+c (get-ray-origin geom tri))))
435 #+end_src 479 #+end_src
436
437
438
439 * Headers 480 * Headers
440 481
441 #+name: touch-header 482 #+name: touch-header
442 #+begin_src clojure 483 #+begin_src clojure
443 (ns cortex.touch 484 (ns cortex.touch
476 (light-up-everything world)) 517 (light-up-everything world))
477 518
478 (fn [world tpf] 519 (fn [world tpf]
479 (touch-display (map #(% (.getRootNode world)) touch)))))) 520 (touch-display (map #(% (.getRootNode world)) touch))))))
480 #+end_src 521 #+end_src
481
482 * Source Listing 522 * Source Listing
483 * Next 523 * Next
484 524
485 525
486 * COMMENT Code Generation 526 * COMMENT Code Generation