diff org/touch.org @ 226:e5db1d2ff9a8

removed outdated test from touch.org
author Robert McIntyre <rlm@mit.edu>
date Sat, 11 Feb 2012 12:53:18 -0700
parents facc2ef3fe5c
children 2a7f57e7efdb
line wrap: on
line diff
     1.1 --- a/org/touch.org	Sat Feb 11 12:32:31 2012 -0700
     1.2 +++ b/org/touch.org	Sat Feb 11 12:53:18 2012 -0700
     1.3 @@ -8,29 +8,13 @@
     1.4  
     1.5  * Touch
     1.6  
     1.7 -My creatures need to be able to feel their environments. The idea here
     1.8 -is to create thousands of small /touch receptors/ along the geometries
     1.9 -which make up the creature's body. The number of touch receptors in a
    1.10 -given area is determined by how complicated that area is, as
    1.11 -determined by the total number of triangles in that region. This way,
    1.12 -complicated regions like the hands/face, etc. get more touch receptors
    1.13 -than simpler areas of the body.
    1.14 +Touch is critical to navigation and spatial reasoning and as such I
    1.15 +need a simulated version of it to give to my AI creatures.
    1.16  
    1.17  #+name: skin-main
    1.18  #+begin_src clojure
    1.19 -(ns cortex.touch
    1.20 -  "Simulate the sense of touch in jMonkeyEngine3. Enables any Geometry
    1.21 -  to be outfitted with touch sensors with density proportional to the
    1.22 -  density of triangles along the surface of the Geometry. Enables a
    1.23 -  Geometry to know what parts of itself are touching nearby objects."
    1.24 -  {:author "Robert McIntyre"}
    1.25 -  (:use (cortex world util sense))
    1.26 -  (:use clojure.contrib.def)
    1.27 -  (:import (com.jme3.scene Geometry Node Mesh))
    1.28 -  (:import com.jme3.collision.CollisionResults)
    1.29 -  (:import com.jme3.scene.VertexBuffer$Type)
    1.30 -  (:import (com.jme3.math Triangle Vector3f Vector2f Ray Matrix4f)))
    1.31 -   
    1.32 +(in-ns 'cortex.touch)
    1.33 +
    1.34  (defn triangles
    1.35    "Return a sequence of all the Triangles which compose a given
    1.36    Geometry." 
    1.37 @@ -313,184 +297,31 @@
    1.38            (.setRGB image ((coords i) 0) ((coords i) 1)
    1.39                     (gray (sensor-data i)))))
    1.40         image))))
    1.41 - 
    1.42 -
    1.43  #+end_src
    1.44  
    1.45 +* Headers 
    1.46 +#+begin_src clojure
    1.47 +(ns cortex.touch
    1.48 +  "Simulate the sense of touch in jMonkeyEngine3. Enables any Geometry
    1.49 +  to be outfitted with touch sensors with density determined by a UV
    1.50 +  image. In this way a Geometry can know what parts of itself are
    1.51 +  touching nearby objects. Reads specially prepared blender files to
    1.52 +  construct this sense automatically."
    1.53 +  {:author "Robert McIntyre"}
    1.54 +  (:use (cortex world util sense))
    1.55 +  (:use clojure.contrib.def)
    1.56 +  (:import (com.jme3.scene Geometry Node Mesh))
    1.57 +  (:import com.jme3.collision.CollisionResults)
    1.58 +  (:import com.jme3.scene.VertexBuffer$Type)
    1.59 +  (:import (com.jme3.math Triangle Vector3f Vector2f Ray Matrix4f)))
    1.60 +#+end_src   
    1.61  
    1.62 -* Example
    1.63 -
    1.64 -#+name: touch-test
    1.65 -#+begin_src clojure 
    1.66 -(ns cortex.test.touch
    1.67 -  (:use (cortex world util touch))
    1.68 -  (:import
    1.69 -   com.jme3.scene.shape.Sphere
    1.70 -   com.jme3.math.ColorRGBA
    1.71 -   com.jme3.math.Vector3f
    1.72 -   com.jme3.material.RenderState$BlendMode
    1.73 -   com.jme3.renderer.queue.RenderQueue$Bucket
    1.74 -   com.jme3.scene.shape.Box
    1.75 -   com.jme3.scene.Node))
    1.76 -
    1.77 -(defn ray-origin-debug
    1.78 -  [ray color]
    1.79 -  (make-shape
    1.80 -   (assoc base-shape
    1.81 -     :shape (Sphere. 5 5 0.05)
    1.82 -     :name "arrow"
    1.83 -     :color color
    1.84 -     :texture false
    1.85 -     :physical? false
    1.86 -     :position
    1.87 -     (.getOrigin ray))))
    1.88 -
    1.89 -(defn ray-debug [ray color]
    1.90 -  (make-shape
    1.91 -   (assoc
    1.92 -       base-shape
    1.93 -     :name "debug-ray"
    1.94 -     :physical? false
    1.95 -     :shape (com.jme3.scene.shape.Line.
    1.96 -             (.getOrigin ray)
    1.97 -             (.add
    1.98 -              (.getOrigin ray)
    1.99 -              (.mult (.getDirection ray)
   1.100 -                     (float (.getLimit ray))))))))
   1.101 -             
   1.102 -
   1.103 -(defn contact-color [contacts]
   1.104 -  (case contacts
   1.105 -    0 ColorRGBA/Gray
   1.106 -    1  ColorRGBA/Red 
   1.107 -    2  ColorRGBA/Green 
   1.108 -    3  ColorRGBA/Yellow 
   1.109 -    4  ColorRGBA/Orange 
   1.110 -    5  ColorRGBA/Red 
   1.111 -    6  ColorRGBA/Magenta 
   1.112 -    7  ColorRGBA/Pink 
   1.113 -    8  ColorRGBA/White))
   1.114 -
   1.115 -(defn update-ray-debug [node ray contacts]
   1.116 -  (let [origin (.getChild node 0)]
   1.117 -    (.setLocalTranslation origin (.getOrigin ray))
   1.118 -    (.setColor (.getMaterial origin) "Color" (contact-color contacts))))
   1.119 -
   1.120 -(defn init-node
   1.121 -  [debug-node rays]
   1.122 -    (.detachAllChildren debug-node)
   1.123 -    (dorun 
   1.124 -     (for [ray rays]
   1.125 -       (do
   1.126 -         (.attachChild
   1.127 -          debug-node 
   1.128 -          (doto (Node.)
   1.129 -            (.attachChild (ray-origin-debug ray ColorRGBA/Gray))
   1.130 -            (.attachChild (ray-debug ray ColorRGBA/Gray))
   1.131 -            ))))))
   1.132 -
   1.133 -(defn manage-ray-debug-node [debug-node geom touch-data limit]
   1.134 -  (let [rays (normal-rays limit geom)]
   1.135 -    (if (not= (count (.getChildren debug-node)) (count touch-data))
   1.136 -      (init-node debug-node rays))
   1.137 -    (dorun 
   1.138 -     (for [n (range (count touch-data))]
   1.139 -       (update-ray-debug
   1.140 -        (.getChild debug-node n) (nth rays n) (nth touch-data n))))))
   1.141 -
   1.142 -(defn transparent-sphere []
   1.143 -  (doto
   1.144 -      (make-shape
   1.145 -       (merge base-shape
   1.146 -	      {:position (Vector3f. 0 2 0)
   1.147 -	       :name "the blob."
   1.148 -	       :material "Common/MatDefs/Misc/Unshaded.j3md"
   1.149 -	       :texture "Textures/purpleWisp.png"
   1.150 -	       :physical? true
   1.151 -	       :mass 70
   1.152 -	       :color ColorRGBA/Blue
   1.153 -	       :shape (Sphere. 10 10 1)}))
   1.154 -    (-> (.getMaterial)
   1.155 -	(.getAdditionalRenderState)
   1.156 -	(.setBlendMode RenderState$BlendMode/Alpha))
   1.157 -    (.setQueueBucket RenderQueue$Bucket/Transparent)))
   1.158 -
   1.159 -(defn transparent-box []
   1.160 -    (doto
   1.161 -      (make-shape
   1.162 -       (merge base-shape
   1.163 -	      {:position (Vector3f. 0 2 0)
   1.164 -	       :name "box"
   1.165 -	       :material "Common/MatDefs/Misc/Unshaded.j3md"
   1.166 -	       :texture "Textures/purpleWisp.png"
   1.167 -	       :physical? true
   1.168 -	       :mass 70
   1.169 -	       :color ColorRGBA/Blue
   1.170 -	       :shape (Box. 1 1 1)}))
   1.171 -    (-> (.getMaterial)
   1.172 -	(.getAdditionalRenderState)
   1.173 -	(.setBlendMode RenderState$BlendMode/Alpha))
   1.174 -    (.setQueueBucket RenderQueue$Bucket/Transparent)))
   1.175 -
   1.176 -(defn transparent-floor []
   1.177 -  (doto
   1.178 -      (box 5 0.2 5  :mass 0 :position (Vector3f. 0 -2 0)
   1.179 -           :material "Common/MatDefs/Misc/Unshaded.j3md"
   1.180 -           :texture "Textures/redWisp.png"
   1.181 -           :name "floor")
   1.182 -    (-> (.getMaterial)
   1.183 -        (.getAdditionalRenderState)
   1.184 -        (.setBlendMode RenderState$BlendMode/Alpha))
   1.185 -    (.setQueueBucket RenderQueue$Bucket/Transparent)))
   1.186 -
   1.187 -(defn test-skin 
   1.188 -  "Testing touch:
   1.189 -   you should see a ball which responds to the table
   1.190 -   and whatever balls hit it."
   1.191 -  []
   1.192 -  (let [b
   1.193 -        ;;(transparent-box)
   1.194 -        (transparent-sphere)
   1.195 -        ;;(sphere)
   1.196 -        f (transparent-floor)
   1.197 -        debug-node (Node.)
   1.198 -        node      (doto (Node.) (.attachChild b) (.attachChild f))
   1.199 -        root-node (doto (Node.) (.attachChild node)
   1.200 -                        (.attachChild debug-node))
   1.201 -        ]
   1.202 -    
   1.203 -    (world
   1.204 -     root-node
   1.205 -     {"key-return" (fire-cannon-ball node)}
   1.206 -     (fn [world]
   1.207 -       ;;  (Capture/SimpleCaptureVideo
   1.208 -       ;;   world 
   1.209 -       ;;   (file-str "/home/r/proj/cortex/tmp/blob.avi"))
   1.210 -       ;;  (no-logging)
   1.211 -       ;;(enable-debug world)
   1.212 -       ;;  (set-accuracy world (/ 1 60))
   1.213 -       )
   1.214 -     
   1.215 -     (fn [& _]
   1.216 -       (let [sensitivity 0.2
   1.217 -             touch-data (touch-percieve sensitivity b node)]
   1.218 -         (manage-ray-debug-node debug-node b touch-data sensitivity))
   1.219 -       ))))
   1.220 -
   1.221 -
   1.222 -#+end_src
   1.223 -
   1.224 -
   1.225 -
   1.226 -
   1.227 -  
   1.228 -* COMMENT code generation
   1.229 +* COMMENT Code Generation
   1.230  #+begin_src clojure :tangle ../src/cortex/touch.clj
   1.231  <<skin-main>>
   1.232  #+end_src
   1.233  
   1.234  #+begin_src clojure :tangle ../src/cortex/test/touch.clj 
   1.235 -<<touch-test>>
   1.236  #+end_src
   1.237  
   1.238  
   1.239 @@ -498,3 +329,4 @@
   1.240    
   1.241  
   1.242  
   1.243 +