Mercurial > cortex
view org/touch.org @ 411:a331d5ff73e0
saving progress for the night. completed self-organizing touch, still working on stream predicates.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Tue, 18 Mar 2014 23:04:48 -0400 |
parents | 4f5a5d5f1613 |
children | 5205535237fb 42ddfe406c0a |
line wrap: on
line source
1 #+title: Simulated Sense of Touch2 #+author: Robert McIntyre3 #+email: rlm@mit.edu4 #+description: Simulated touch for AI research using JMonkeyEngine and clojure.5 #+keywords: simulation, tactile sense, jMonkeyEngine3, clojure6 #+SETUPFILE: ../../aurellem/org/setup.org7 #+INCLUDE: ../../aurellem/org/level-0.org9 * Touch11 Touch is critical to navigation and spatial reasoning and as such I12 need a simulated version of it to give to my AI creatures.14 Human skin has a wide array of touch sensors, each of which specialize15 in detecting different vibrational modes and pressures. These sensors16 can integrate a vast expanse of skin (i.e. your entire palm), or a17 tiny patch of skin at the tip of your finger. The hairs of the skin18 help detect objects before they even come into contact with the skin19 proper.21 However, touch in my simulated world can not exactly correspond to22 human touch because my creatures are made out of completely rigid23 segments that don't deform like human skin.25 Instead of measuring deformation or vibration, I surround each rigid26 part with a plenitude of hair-like objects (/feelers/) which do not27 interact with the physical world. Physical objects can pass through28 them with no effect. The feelers are able to tell when other objects29 pass through them, and they constantly report how much of their extent30 is covered. So even though the creature's body parts do not deform,31 the feelers create a margin around those body parts which achieves a32 sense of touch which is a hybrid between a human's sense of33 deformation and sense from hairs.35 Implementing touch in jMonkeyEngine follows a different technical route36 than vision and hearing. Those two senses piggybacked off37 jMonkeyEngine's 3D audio and video rendering subsystems. To simulate38 touch, I use jMonkeyEngine's physics system to execute many small39 collision detections, one for each feeler. The placement of the40 feelers is determined by a UV-mapped image which shows where each41 feeler should be on the 3D surface of the body.43 * Defining Touch Meta-Data in Blender45 Each geometry can have a single UV map which describes the position of46 the feelers which will constitute its sense of touch. This image path47 is stored under the "touch" key. The image itself is black and white,48 with black meaning a feeler length of 0 (no feeler is present) and49 white meaning a feeler length of =scale=, which is a float stored50 under the key "scale".52 #+name: meta-data53 #+begin_src clojure54 (defn tactile-sensor-profile55 "Return the touch-sensor distribution image in BufferedImage format,56 or nil if it does not exist."57 [#^Geometry obj]58 (if-let [image-path (meta-data obj "touch")]59 (load-image image-path)))61 (defn tactile-scale62 "Return the length of each feeler. Default scale is 0.0163 jMonkeyEngine units."64 [#^Geometry obj]65 (if-let [scale (meta-data obj "scale")]66 scale 0.1))67 #+end_src69 Here is an example of a UV-map which specifies the position of touch70 sensors along the surface of the upper segment of the worm.72 #+attr_html: width=75573 #+caption: This is the tactile-sensor-profile for the upper segment of the worm. It defines regions of high touch sensitivity (where there are many white pixels) and regions of low sensitivity (where white pixels are sparse).74 [[../images/finger-UV.png]]76 * Implementation Summary78 To simulate touch there are three conceptual steps. For each solid79 object in the creature, you first have to get UV image and scale80 parameter which define the position and length of the feelers. Then,81 you use the triangles which compose the mesh and the UV data stored in82 the mesh to determine the world-space position and orientation of each83 feeler. Then once every frame, update these positions and orientations84 to match the current position and orientation of the object, and use85 physics collision detection to gather tactile data.87 Extracting the meta-data has already been described. The third step,88 physics collision detection, is handled in =touch-kernel=.89 Translating the positions and orientations of the feelers from the90 UV-map to world-space is itself a three-step process.92 - Find the triangles which make up the mesh in pixel-space and in93 world-space. =triangles= =pixel-triangles=.95 - Find the coordinates of each feeler in world-space. These are the96 origins of the feelers. =feeler-origins=.98 - Calculate the normals of the triangles in world space, and add99 them to each of the origins of the feelers. These are the100 normalized coordinates of the tips of the feelers. =feeler-tips=.102 * Triangle Math103 ** Shrapnel Conversion Functions105 #+name: triangles-1106 #+begin_src clojure107 (defn vector3f-seq [#^Vector3f v]108 [(.getX v) (.getY v) (.getZ v)])110 (defn triangle-seq [#^Triangle tri]111 [(vector3f-seq (.get1 tri))112 (vector3f-seq (.get2 tri))113 (vector3f-seq (.get3 tri))])115 (defn ->vector3f116 ([coords] (Vector3f. (nth coords 0 0)117 (nth coords 1 0)118 (nth coords 2 0))))120 (defn ->triangle [points]121 (apply #(Triangle. %1 %2 %3) (map ->vector3f points)))122 #+end_src124 It is convenient to treat a =Triangle= as a vector of vectors, and a125 =Vector2f= or =Vector3f= as vectors of floats. (->vector3f) and126 (->triangle) undo the operations of =vector3f-seq= and127 =triangle-seq=. If these classes implemented =Iterable= then =seq=128 would work on them automatically.130 ** Decomposing a 3D shape into Triangles132 The rigid objects which make up a creature have an underlying133 =Geometry=, which is a =Mesh= plus a =Material= and other important134 data involved with displaying the object.136 A =Mesh= is composed of =Triangles=, and each =Triangle= has three137 vertices which have coordinates in world space and UV space.139 Here, =triangles= gets all the world-space triangles which compose a140 mesh, while =pixel-triangles= gets those same triangles expressed in141 pixel coordinates (which are UV coordinates scaled to fit the height142 and width of the UV image).144 #+name: triangles-2145 #+begin_src clojure146 (in-ns 'cortex.touch)147 (defn triangle148 "Get the triangle specified by triangle-index from the mesh."149 [#^Geometry geo triangle-index]150 (triangle-seq151 (let [scratch (Triangle.)]152 (.getTriangle (.getMesh geo) triangle-index scratch) scratch)))154 (defn triangles155 "Return a sequence of all the Triangles which compose a given156 Geometry."157 [#^Geometry geo]158 (map (partial triangle geo) (range (.getTriangleCount (.getMesh geo)))))160 (defn triangle-vertex-indices161 "Get the triangle vertex indices of a given triangle from a given162 mesh."163 [#^Mesh mesh triangle-index]164 (let [indices (int-array 3)]165 (.getTriangle mesh triangle-index indices)166 (vec indices)))168 (defn vertex-UV-coord169 "Get the UV-coordinates of the vertex named by vertex-index"170 [#^Mesh mesh vertex-index]171 (let [UV-buffer172 (.getData173 (.getBuffer174 mesh175 VertexBuffer$Type/TexCoord))]176 [(.get UV-buffer (* vertex-index 2))177 (.get UV-buffer (+ 1 (* vertex-index 2)))]))179 (defn pixel-triangle [#^Geometry geo image index]180 (let [mesh (.getMesh geo)181 width (.getWidth image)182 height (.getHeight image)]183 (vec (map (fn [[u v]] (vector (* width u) (* height v)))184 (map (partial vertex-UV-coord mesh)185 (triangle-vertex-indices mesh index))))))187 (defn pixel-triangles188 "The pixel-space triangles of the Geometry, in the same order as189 (triangles geo)"190 [#^Geometry geo image]191 (let [height (.getHeight image)192 width (.getWidth image)]193 (map (partial pixel-triangle geo image)194 (range (.getTriangleCount (.getMesh geo))))))195 #+end_src196 ** The Affine Transform from one Triangle to Another198 =pixel-triangles= gives us the mesh triangles expressed in pixel199 coordinates and =triangles= gives us the mesh triangles expressed in200 world coordinates. The tactile-sensor-profile gives the position of201 each feeler in pixel-space. In order to convert pixel-space202 coordinates into world-space coordinates we need something that takes203 coordinates on the surface of one triangle and gives the corresponding204 coordinates on the surface of another triangle.206 Triangles are [[http://mathworld.wolfram.com/AffineTransformation.html ][affine]], which means any triangle can be transformed into207 any other by a combination of translation, scaling, and208 rotation. The affine transformation from one triangle to another209 is readily computable if the triangle is expressed in terms of a $4x4$210 matrix.212 \begin{bmatrix}213 x_1 & x_2 & x_3 & n_x \\214 y_1 & y_2 & y_3 & n_y \\215 z_1 & z_2 & z_3 & n_z \\216 1 & 1 & 1 & 1217 \end{bmatrix}219 Here, the first three columns of the matrix are the vertices of the220 triangle. The last column is the right-handed unit normal of the221 triangle.223 With two triangles $T_{1}$ and $T_{2}$ each expressed as a matrix like224 above, the affine transform from $T_{1}$ to $T_{2}$ is226 $T_{2}T_{1}^{-1}$228 The clojure code below recapitulates the formulas above, using229 jMonkeyEngine's =Matrix4f= objects, which can describe any affine230 transformation.232 #+name: triangles-3233 #+begin_src clojure234 (in-ns 'cortex.touch)236 (defn triangle->matrix4f237 "Converts the triangle into a 4x4 matrix: The first three columns238 contain the vertices of the triangle; the last contains the unit239 normal of the triangle. The bottom row is filled with 1s."240 [#^Triangle t]241 (let [mat (Matrix4f.)242 [vert-1 vert-2 vert-3]243 ((comp vec map) #(.get t %) (range 3))244 unit-normal (do (.calculateNormal t)(.getNormal t))245 vertices [vert-1 vert-2 vert-3 unit-normal]]246 (dorun247 (for [row (range 4) col (range 3)]248 (do249 (.set mat col row (.get (vertices row) col))250 (.set mat 3 row 1)))) mat))252 (defn triangles->affine-transform253 "Returns the affine transformation that converts each vertex in the254 first triangle into the corresponding vertex in the second255 triangle."256 [#^Triangle tri-1 #^Triangle tri-2]257 (.mult258 (triangle->matrix4f tri-2)259 (.invert (triangle->matrix4f tri-1))))260 #+end_src261 ** Triangle Boundaries263 For efficiency's sake I will divide the tactile-profile image into264 small squares which inscribe each pixel-triangle, then extract the265 points which lie inside the triangle and map them to 3D-space using266 =triangle-transform= above. To do this I need a function,267 =convex-bounds= which finds the smallest box which inscribes a 2D268 triangle.270 =inside-triangle?= determines whether a point is inside a triangle271 in 2D pixel-space.273 #+name: triangles-4274 #+begin_src clojure275 (defn convex-bounds276 "Returns the smallest square containing the given vertices, as a277 vector of integers [left top width height]."278 [verts]279 (let [xs (map first verts)280 ys (map second verts)281 x0 (Math/floor (apply min xs))282 y0 (Math/floor (apply min ys))283 x1 (Math/ceil (apply max xs))284 y1 (Math/ceil (apply max ys))]285 [x0 y0 (- x1 x0) (- y1 y0)]))287 (defn same-side?288 "Given the points p1 and p2 and the reference point ref, is point p289 on the same side of the line that goes through p1 and p2 as ref is?"290 [p1 p2 ref p]291 (<=292 0293 (.dot294 (.cross (.subtract p2 p1) (.subtract p p1))295 (.cross (.subtract p2 p1) (.subtract ref p1)))))297 (defn inside-triangle?298 "Is the point inside the triangle?"299 {:author "Dylan Holmes"}300 [#^Triangle tri #^Vector3f p]301 (let [[vert-1 vert-2 vert-3] [(.get1 tri) (.get2 tri) (.get3 tri)]]302 (and303 (same-side? vert-1 vert-2 vert-3 p)304 (same-side? vert-2 vert-3 vert-1 p)305 (same-side? vert-3 vert-1 vert-2 p))))306 #+end_src308 * Feeler Coordinates310 The triangle-related functions above make short work of calculating311 the positions and orientations of each feeler in world-space.313 #+name: sensors314 #+begin_src clojure315 (in-ns 'cortex.touch)317 (defn feeler-pixel-coords318 "Returns the coordinates of the feelers in pixel space in lists, one319 list for each triangle, ordered in the same way as (triangles) and320 (pixel-triangles)."321 [#^Geometry geo image]322 (map323 (fn [pixel-triangle]324 (filter325 (fn [coord]326 (inside-triangle? (->triangle pixel-triangle)327 (->vector3f coord)))328 (white-coordinates image (convex-bounds pixel-triangle))))329 (pixel-triangles geo image)))331 (defn feeler-world-coords332 "Returns the coordinates of the feelers in world space in lists, one333 list for each triangle, ordered in the same way as (triangles) and334 (pixel-triangles)."335 [#^Geometry geo image]336 (let [transforms337 (map #(triangles->affine-transform338 (->triangle %1) (->triangle %2))339 (pixel-triangles geo image)340 (triangles geo))]341 (map (fn [transform coords]342 (map #(.mult transform (->vector3f %)) coords))343 transforms (feeler-pixel-coords geo image))))345 (defn feeler-origins346 "The world space coordinates of the root of each feeler."347 [#^Geometry geo image]348 (reduce concat (feeler-world-coords geo image)))350 (defn feeler-tips351 "The world space coordinates of the tip of each feeler."352 [#^Geometry geo image]353 (let [world-coords (feeler-world-coords geo image)354 normals355 (map356 (fn [triangle]357 (.calculateNormal triangle)358 (.clone (.getNormal triangle)))359 (map ->triangle (triangles geo)))]361 (mapcat (fn [origins normal]362 (map #(.add % normal) origins))363 world-coords normals)))365 (defn touch-topology366 "touch-topology? is not a function."367 [#^Geometry geo image]368 (collapse (reduce concat (feeler-pixel-coords geo image))))369 #+end_src370 * Simulated Touch372 =touch-kernel= generates functions to be called from within a373 simulation that perform the necessary physics collisions to collect374 tactile data, and =touch!= recursively applies it to every node in375 the creature.377 #+name: kernel378 #+begin_src clojure379 (in-ns 'cortex.touch)381 (defn set-ray [#^Ray ray #^Matrix4f transform382 #^Vector3f origin #^Vector3f tip]383 ;; Doing everything locally reduces garbage collection by enough to384 ;; be worth it.385 (.mult transform origin (.getOrigin ray))386 (.mult transform tip (.getDirection ray))387 (.subtractLocal (.getDirection ray) (.getOrigin ray))388 (.normalizeLocal (.getDirection ray)))390 (import com.jme3.math.FastMath)393 (defn touch-kernel394 "Constructs a function which will return tactile sensory data from395 'geo when called from inside a running simulation"396 [#^Geometry geo]397 (if-let398 [profile (tactile-sensor-profile geo)]399 (let [ray-reference-origins (feeler-origins geo profile)400 ray-reference-tips (feeler-tips geo profile)401 ray-length (tactile-scale geo)402 current-rays (map (fn [_] (Ray.)) ray-reference-origins)403 topology (touch-topology geo profile)404 correction (float (* ray-length -0.2))]406 ;; slight tolerance for very close collisions.407 (dorun408 (map (fn [origin tip]409 (.addLocal origin (.mult (.subtract tip origin)410 correction)))411 ray-reference-origins ray-reference-tips))412 (dorun (map #(.setLimit % ray-length) current-rays))413 (fn [node]414 (let [transform (.getWorldMatrix geo)]415 (dorun416 (map (fn [ray ref-origin ref-tip]417 (set-ray ray transform ref-origin ref-tip))418 current-rays ray-reference-origins419 ray-reference-tips))420 (vector421 topology422 (vec423 (for [ray current-rays]424 (do425 (let [results (CollisionResults.)]426 (.collideWith node ray results)427 (let [touch-objects428 (filter #(not (= geo (.getGeometry %)))429 results)430 limit (.getLimit ray)]431 [(if (empty? touch-objects)432 limit433 (let [response434 (apply min (map #(.getDistance %)435 touch-objects))]436 (FastMath/clamp437 (float438 (if (> response limit) (float 0.0)439 (+ response correction)))440 (float 0.0)441 limit)))442 limit])))))))))))444 (defn touch!445 "Endow the creature with the sense of touch. Returns a sequence of446 functions, one for each body part with a tactile-sensor-profile,447 each of which when called returns sensory data for that body part."448 [#^Node creature]449 (filter450 (comp not nil?)451 (map touch-kernel452 (filter #(isa? (class %) Geometry)453 (node-seq creature)))))454 #+end_src456 #+results: kernel457 : #'cortex.touch/touch!459 * Visualizing Touch461 Each feeler is represented in the image as a single pixel. The462 greyscale value of each pixel represents how deep the feeler463 represented by that pixel is inside another object. Black means that464 nothing is touching the feeler, while white means that the feeler is465 completely inside another object, which is presumably flush with the466 surface of the triangle from which the feeler originates.468 #+name: visualization469 #+begin_src clojure470 (in-ns 'cortex.touch)472 (defn touch->gray473 "Convert a pair of [distance, max-distance] into a gray-scale pixel."474 [distance max-distance]475 (gray (- 255 (rem (int (* 255 (/ distance max-distance))) 256))))477 (defn view-touch478 "Creates a function which accepts a list of touch sensor-data and479 displays each element to the screen."480 []481 (view-sense482 (fn [[coords sensor-data]]483 (let [image (points->image coords)]484 (dorun485 (for [i (range (count coords))]486 (.setRGB image ((coords i) 0) ((coords i) 1)487 (apply touch->gray (sensor-data i)))))488 image))))489 #+end_src491 #+results: visualization492 : #'cortex.touch/view-touch494 * Basic Test of Touch496 The worm's sense of touch is a bit complicated, so for this basic test497 I'll use a new creature --- a simple cube which has touch sensors498 evenly distributed along each of its sides.500 #+name: test-touch-0501 #+begin_src clojure502 (in-ns 'cortex.test.touch)504 (defn touch-cube []505 (load-blender-model "Models/test-touch/touch-cube.blend"))506 #+end_src508 ** The Touch Cube509 #+begin_html510 <div class="figure">511 <center>512 <video controls="controls" width="500">513 <source src="../video/touch-cube.ogg" type="video/ogg"514 preload="none" poster="../images/aurellem-1280x480.png" />515 </video>516 <br> <a href="http://youtu.be/aEao4m8meAI"> YouTube </a>517 </center>518 <p>A simple creature with evenly distributed touch sensors.</p>519 </div>520 #+end_html522 The tactile-sensor-profile image for this simple creature looks like523 this:525 #+attr_html: width=500526 #+caption: The distribution of feelers along the touch-cube. The colors of the faces are irrelevant; only the white pixels specify feelers.527 [[../images/touch-profile.png]]529 #+name: test-touch-1530 #+begin_src clojure531 (in-ns 'cortex.test.touch)533 (defn test-basic-touch534 "Testing touch:535 You should see a cube fall onto a table. There is a cross-shaped536 display which reports the cube's sensation of touch. This display537 should change when the cube hits the table, and whenever you hit538 the cube with balls.540 Keys:541 <space> : fire ball"542 ([] (test-basic-touch false))543 ([record?]544 (let [the-cube (doto (touch-cube) (body!))545 touch (touch! the-cube)546 touch-display (view-touch)]547 (world548 (nodify [the-cube549 (box 10 1 10 :position (Vector3f. 0 -10 0)550 :color ColorRGBA/Gray :mass 0)])552 standard-debug-controls554 (fn [world]555 (let [timer (IsoTimer. 60)]556 (.setTimer world timer)557 (display-dilated-time world timer))558 (if record?559 (Capture/captureVideo560 world561 (File. "/home/r/proj/cortex/render/touch-cube/main-view/")))562 (speed-up world)563 (light-up-everything world))565 (fn [world tpf]566 (touch-display567 (map #(% (.getRootNode world)) touch)568 (if record?569 (File. "/home/r/proj/cortex/render/touch-cube/touch/"))))))))570 #+end_src572 #+results: test-touch-1573 : #'cortex.test.touch/test-basic-touch575 ** Basic Touch Demonstration577 #+begin_html578 <div class="figure">579 <center>580 <video controls="controls" width="755">581 <source src="../video/basic-touch.ogg" type="video/ogg"582 preload="none" poster="../images/aurellem-1280x480.png" />583 </video>584 <br> <a href="http://youtu.be/8xNEtD-a8f0"> YouTube </a>585 </center>586 <p>The simple creature responds to touch.</p>587 </div>588 #+end_html590 ** Generating the Basic Touch Video591 #+name: magick4592 #+begin_src clojure593 (ns cortex.video.magick4594 (:import java.io.File)595 (:use clojure.java.shell))597 (defn images [path]598 (sort (rest (file-seq (File. path)))))600 (def base "/home/r/proj/cortex/render/touch-cube/")602 (defn pics [file]603 (images (str base file)))605 (defn combine-images []606 (let [main-view (pics "main-view")607 touch (pics "touch/0")608 background (repeat 9001 (File. (str base "background.png")))609 targets (map610 #(File. (str base "out/" (format "%07d.png" %)))611 (range 0 (count main-view)))]612 (dorun613 (pmap614 (comp615 (fn [[background main-view touch target]]616 (println target)617 (sh "convert"618 touch619 "-resize" "x300"620 "-rotate" "180"621 background622 "-swap" "0,1"623 "-geometry" "+776+129"624 "-composite"625 main-view "-geometry" "+66+21" "-composite"626 target))627 (fn [& args] (map #(.getCanonicalPath %) args)))628 background main-view touch targets))))629 #+end_src631 #+begin_src sh :results silent632 cd ~/proj/cortex/render/touch-cube/633 ffmpeg -r 60 -i out/%07d.png -b:v 9000k -c:v libtheora basic-touch.ogg634 #+end_src636 #+begin_src sh :results silent637 cd ~/proj/cortex/render/touch-cube/638 ffmpeg -r 30 -i blender-intro/%07d.png -b:v 9000k -c:v libtheora touch-cube.ogg639 #+end_src641 * Adding Touch to the Worm643 #+name: test-touch-2644 #+begin_src clojure645 (in-ns 'cortex.test.touch)647 (defn test-worm-touch648 "Testing touch:649 You will see the worm fall onto a table. There is a display which650 reports the worm's sense of touch. It should change when the worm651 hits the table and when you hit it with balls.653 Keys:654 <space> : fire ball"655 ([] (test-worm-touch false))656 ([record?]657 (let [the-worm (doto (worm) (body!))658 touch (touch! the-worm)659 touch-display (view-touch)]660 (world661 (nodify [the-worm (floor)])662 standard-debug-controls664 (fn [world]665 (let [timer (IsoTimer. 60)]666 (.setTimer world timer)667 (display-dilated-time world timer))668 (if record?669 (Capture/captureVideo670 world671 (File. "/home/r/proj/cortex/render/worm-touch/main-view/")))672 (speed-up world)673 (light-up-everything world))675 (fn [world tpf]676 (touch-display677 (map #(% (.getRootNode world)) touch)678 (if record?679 (File. "/home/r/proj/cortex/render/worm-touch/touch/"))))))))680 #+end_src682 #+results: test-touch-2683 : #'cortex.test.touch/test-worm-touch685 ** Worm Touch Demonstration686 #+begin_html687 <div class="figure">688 <center>689 <video controls="controls" width="550">690 <source src="../video/worm-touch.ogg" type="video/ogg"691 preload="none" poster="../images/aurellem-1280x480.png" />692 </video>693 <br> <a href="http://youtu.be/RHx2wqzNVcU"> YouTube </a>694 </center>695 <p>The worm responds to touch.</p>696 </div>697 #+end_html700 ** Generating the Worm Touch Video701 #+name: magick5702 #+begin_src clojure703 (ns cortex.video.magick5704 (:import java.io.File)705 (:use clojure.java.shell))707 (defn images [path]708 (sort (rest (file-seq (File. path)))))710 (def base "/home/r/proj/cortex/render/worm-touch/")712 (defn pics [file]713 (images (str base file)))715 (defn combine-images []716 (let [main-view (pics "main-view")717 touch (pics "touch/0")718 targets (map719 #(File. (str base "out/" (format "%07d.png" %)))720 (range 0 (count main-view)))]721 (dorun722 (pmap723 (comp724 (fn [[ main-view touch target]]725 (println target)726 (sh "convert"727 main-view728 touch "-geometry" "+0+0" "-composite"729 target))730 (fn [& args] (map #(.getCanonicalPath %) args)))731 main-view touch targets))))732 #+end_src734 #+begin_src sh :results silent735 cd ~/proj/cortex/render/worm-touch736 ffmpeg -r 60 -i out/%07d.png -b:v 9000k -c:v libtheora worm-touch.ogg737 #+end_src739 * Headers741 #+name: touch-header742 #+begin_src clojure743 (ns cortex.touch744 "Simulate the sense of touch in jMonkeyEngine3. Enables any Geometry745 to be outfitted with touch sensors with density determined by a UV746 image. In this way a Geometry can know what parts of itself are747 touching nearby objects. Reads specially prepared blender files to748 construct this sense automatically."749 {:author "Robert McIntyre"}750 (:use (cortex world util sense))751 (:import (com.jme3.scene Geometry Node Mesh))752 (:import com.jme3.collision.CollisionResults)753 (:import com.jme3.scene.VertexBuffer$Type)754 (:import (com.jme3.math Triangle Vector3f Vector2f Ray Matrix4f)))755 #+end_src757 #+name: test-touch-header758 #+begin_src clojure759 (ns cortex.test.touch760 (:use (cortex world util sense body touch))761 (:use cortex.test.body)762 (:import (com.aurellem.capture Capture IsoTimer))763 (:import java.io.File)764 (:import (com.jme3.math Vector3f ColorRGBA)))765 #+end_src767 #+results: test-touch-header768 : com.jme3.math.ColorRGBA770 * Source Listing771 - [[../src/cortex/touch.clj][cortex.touch]]772 - [[../src/cortex/test/touch.clj][cortex.test.touch]]773 - [[../src/cortex/video/magick4.clj][cortex.video.magick4]]774 - [[../src/cortex/video/magick5.clj][cortex.video.magick5]]775 - [[../assets/Models/test-touch/touch-cube.blend][touch-cube.blend]]776 #+html: <ul> <li> <a href="../org/touch.org">This org file</a> </li> </ul>777 - [[http://hg.bortreb.com ][source-repository]]779 * Next780 So far I've implemented simulated Vision, Hearing, and781 Touch, the most obvious and prominent senses that humans782 have. Smell and Taste shall remain unimplemented for783 now. This accounts for the "five senses" that feature so784 prominently in our lives. But humans have far more than the785 five main senses. There are internal chemical senses, pain786 (which is *not* the same as touch), heat sensitivity, and787 our sense of balance, among others. One extra sense is so788 important that I must implement it to have a hope of making789 creatures that can gracefully control their own bodies. It790 is Proprioception, which is the sense of the location of791 each body part in relation to the other body parts.793 Close your eyes, and touch your nose with your right index794 finger. How did you do it? You could not see your hand, and795 neither your hand nor your nose could use the sense of touch796 to guide the path of your hand. There are no sound cues,797 and Taste and Smell certainly don't provide any help. You798 know where your hand is without your other senses because of799 Proprioception.801 Onward to [[./proprioception.org][proprioception]]!803 * COMMENT Code Generation804 #+begin_src clojure :tangle ../src/cortex/touch.clj805 <<touch-header>>806 <<meta-data>>807 <<triangles-1>>808 <<triangles-2>>809 <<triangles-3>>810 <<triangles-4>>811 <<sensors>>812 <<kernel>>813 <<visualization>>814 #+end_src816 #+begin_src clojure :tangle ../src/cortex/test/touch.clj817 <<test-touch-header>>818 <<test-touch-0>>819 <<test-touch-1>>820 <<test-touch-2>>821 #+end_src823 #+begin_src clojure :tangle ../src/cortex/video/magick4.clj824 <<magick4>>825 #+end_src827 #+begin_src clojure :tangle ../src/cortex/video/magick5.clj828 <<magick5>>829 #+end_src