changeset 458:42ddfe406c0a

working on depth maps for the lulz.
author Robert McIntyre <rlm@mit.edu>
date Tue, 11 Jun 2013 07:13:42 -0400
parents ee977613c244
children a86555b02916
files org/body.org org/depth-map.org org/gabor.org org/touch.org org/util.org
diffstat 5 files changed, 121 insertions(+), 63 deletions(-) [+]
line wrap: on
line diff
     1.1 --- a/org/body.org	Fri Jun 07 11:49:09 2013 -0400
     1.2 +++ b/org/body.org	Tue Jun 11 07:13:42 2013 -0400
     1.3 @@ -179,6 +179,9 @@
     1.4        no-op)))
     1.5  #+end_src
     1.6  
     1.7 +#+results: test-2
     1.8 +: #'cortex.test.body/test-hand-2
     1.9 +
    1.10  #+begin_html
    1.11  <div class="figure">
    1.12  <center>
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/org/depth-map.org	Tue Jun 11 07:13:42 2013 -0400
     2.3 @@ -0,0 +1,51 @@
     2.4 +
     2.5 +#+begin_src clojure
     2.6 +(ns cortex.depth-map
     2.7 +  "lol depth maps."
     2.8 +  {:author "Robert McIntyre"}
     2.9 +  (:use (cortex world util body sense vision touch))
    2.10 +  (:import (com.jme3.scene Geometry Node Mesh))
    2.11 +  (:import com.jme3.collision.CollisionResults)
    2.12 +  (:import com.jme3.scene.VertexBuffer$Type)
    2.13 +
    2.14 +  (:import (com.jme3.math Triangle Vector3f Vector2f Ray Matrix4f)))
    2.15 +
    2.16 +(cortex.import/mega-import-jme3)
    2.17 +
    2.18 +(defn convert-pixel-to-ray
    2.19 +  [camera x y]
    2.20 +  (let [pixel-arrow
    2.21 +        (.getWorldCoordinates
    2.22 +         camera
    2.23 +         (Vector2f. (float x) (float y))
    2.24 +         ;; this is the "z depth" and can be anything, since
    2.25 +         ;; we only care about direction
    2.26 +         (float 1))
    2.27 +        ;; now that we have the direction of a pixel, subtract
    2.28 +        ray (Ray.)]
    2.29 +    (set-ray ray Matrix4f/IDENTITY (.getLocation camera)
    2.30 +             pixel-arrow) ray))
    2.31 +
    2.32 +
    2.33 +(defn generate-depth-map-points
    2.34 +  "Generate a data structure representating the depth of the first
    2.35 +  object to collide with a ray from the camera's current position."
    2.36 +  [world camera]
    2.37 +  (let [width (.getWidth camera)
    2.38 +        height (.getHeight camera)
    2.39 +        pixels (for [x (range width) y (range height)]
    2.40 +                 [x y])
    2.41 +        
    2.42 +        depths
    2.43 +        (for [[x y] pixels]
    2.44 +          (let [ray (convert-pixel-to-ray camera x y)
    2.45 +                results (CollisionResults.)]
    2.46 +            (.collideWith world ray results)
    2.47 +            (.getDistance (.getClosestCollision results))))]
    2.48 +    (zipmap pixels depths)))
    2.49 +
    2.50 +(defn test-world []
    2.51 +  (nodify [(floor*) (brick-wall*)]))
    2.52 +
    2.53 +(defn run-depth-map-test []
    2.54 +#+end_src
    2.55 \ No newline at end of file
     3.1 --- a/org/gabor.org	Fri Jun 07 11:49:09 2013 -0400
     3.2 +++ b/org/gabor.org	Tue Jun 11 07:13:42 2013 -0400
     3.3 @@ -177,68 +177,6 @@
     3.4    (println (.dump kernel)))
     3.5                             
     3.6  
     3.7 -(def brick-length 0.48)
     3.8 -(def brick-width 0.24)
     3.9 -(def brick-height 0.12)
    3.10 -(def gravity (Vector3f. 0 -9.81 0))
    3.11 -
    3.12 -
    3.13 -(defn brick* [position]
    3.14 -  (println "get brick.")
    3.15 -  (doto (box brick-length brick-height brick-width
    3.16 -	     :position position :name "brick"
    3.17 -	     :material "Common/MatDefs/Misc/Unshaded.j3md"
    3.18 -	     :texture "Textures/Terrain/BrickWall/BrickWall.jpg"
    3.19 -	     :mass 34)
    3.20 -    (->
    3.21 -     (.getMesh)
    3.22 -     (.scaleTextureCoordinates (Vector2f. 1 0.5)))
    3.23 -    (.setShadowMode RenderQueue$ShadowMode/CastAndReceive)
    3.24 -    )
    3.25 -  )
    3.26 -
    3.27 -
    3.28 -(defn floor*
    3.29 -  "make a sturdy, unmovable physical floor"
    3.30 -  []
    3.31 -  (box 10 0.1 5 :name "floor" :mass 0 
    3.32 -       :color ColorRGBA/Gray :position (Vector3f. 0 0 0)))
    3.33 -
    3.34 -(defn floor* []
    3.35 -  (doto (box 10 0.1 5 :name "floor" ;10 0.1 5 ; 240 0.1 240
    3.36 -	     :material "Common/MatDefs/Misc/Unshaded.j3md"
    3.37 -	     :texture "Textures/BronzeCopper030.jpg"
    3.38 -	     :position (Vector3f. 0 0 0 )
    3.39 -	     :mass 0)
    3.40 -    (->
    3.41 -     (.getMesh)
    3.42 -     (.scaleTextureCoordinates (Vector2f. 3 6)));64 64
    3.43 -    (->
    3.44 -     (.getMaterial)
    3.45 -     (.getTextureParam "ColorMap")
    3.46 -     (.getTextureValue)
    3.47 -     (.setWrap Texture$WrapMode/Repeat))
    3.48 -    (.setShadowMode RenderQueue$ShadowMode/Receive)
    3.49 -  ))
    3.50 -
    3.51 -
    3.52 -(defn brick-wall* []
    3.53 -  (let [node (Node. "brick-wall")]
    3.54 -    (dorun
    3.55 -     (map
    3.56 -      (comp  #(.attachChild node %) brick*)
    3.57 -       (for [y (range 10)
    3.58 -	     x (range 4)
    3.59 -	     z (range 1)]
    3.60 -       	    (Vector3f.
    3.61 -       	     (+ (* 2 x brick-length)
    3.62 -		(if (even? (+ y z)) 
    3.63 -		  (/ brick-length 4) (/ brick-length -4)))
    3.64 -       	     (+ (* brick-height (inc (* 2 y))))
    3.65 -	     (* 2 z brick-width) ))))
    3.66 -    (.setShadowMode node RenderQueue$ShadowMode/CastAndReceive)
    3.67 -    node))
    3.68 -
    3.69  (import com.aurellem.capture.Capture)
    3.70  
    3.71  (import java.io.File)
     4.1 --- a/org/touch.org	Fri Jun 07 11:49:09 2013 -0400
     4.2 +++ b/org/touch.org	Tue Jun 11 07:13:42 2013 -0400
     4.3 @@ -388,7 +388,6 @@
     4.4    (.normalizeLocal (.getDirection ray)))
     4.5  
     4.6  (import com.jme3.math.FastMath)
     4.7 -
     4.8   
     4.9  (defn touch-kernel
    4.10    "Constructs a function which will return tactile sensory data from
     5.1 --- a/org/util.org	Fri Jun 07 11:49:09 2013 -0400
     5.2 +++ b/org/util.org	Tue Jun 11 07:13:42 2013 -0400
     5.3 @@ -365,6 +365,73 @@
     5.4                        (into-array String ["blend"]))) model))
     5.5  
     5.6  
     5.7 +
     5.8 +(def brick-length 0.48)
     5.9 +(def brick-width 0.24)
    5.10 +(def brick-height 0.12)
    5.11 +(def gravity (Vector3f. 0 -9.81 0))
    5.12 +
    5.13 +(import com.jme3.math.Vector2f)
    5.14 +(import com.jme3.renderer.queue.RenderQueue$ShadowMode)
    5.15 +(import com.jme3.texture.Texture$WrapMode)
    5.16 +
    5.17 +(defn brick* [position]
    5.18 +  (println "get brick.")
    5.19 +  (doto (box brick-length brick-height brick-width
    5.20 +	     :position position :name "brick"
    5.21 +	     :material "Common/MatDefs/Misc/Unshaded.j3md"
    5.22 +	     :texture "Textures/Terrain/BrickWall/BrickWall.jpg"
    5.23 +	     :mass 34)
    5.24 +    (->
    5.25 +     (.getMesh)
    5.26 +     (.scaleTextureCoordinates (Vector2f. 1 0.5)))
    5.27 +    (.setShadowMode RenderQueue$ShadowMode/CastAndReceive)
    5.28 +    )
    5.29 +  )
    5.30 +
    5.31 +
    5.32 +(defn floor*
    5.33 +  "make a sturdy, unmovable physical floor"
    5.34 +  []
    5.35 +  (box 10 0.1 5 :name "floor" :mass 0 
    5.36 +       :color ColorRGBA/Gray :position (Vector3f. 0 0 0)))
    5.37 +
    5.38 +(defn floor* []
    5.39 +  (doto (box 10 0.1 5 :name "floor" ;10 0.1 5 ; 240 0.1 240
    5.40 +	     :material "Common/MatDefs/Misc/Unshaded.j3md"
    5.41 +	     :texture "Textures/BronzeCopper030.jpg"
    5.42 +	     :position (Vector3f. 0 0 0 )
    5.43 +	     :mass 0)
    5.44 +    (->
    5.45 +     (.getMesh)
    5.46 +     (.scaleTextureCoordinates (Vector2f. 3 6)));64 64
    5.47 +    (->
    5.48 +     (.getMaterial)
    5.49 +     (.getTextureParam "ColorMap")
    5.50 +     (.getTextureValue)
    5.51 +     (.setWrap Texture$WrapMode/Repeat))
    5.52 +    (.setShadowMode RenderQueue$ShadowMode/Receive)
    5.53 +  ))
    5.54 +
    5.55 +
    5.56 +(defn brick-wall* []
    5.57 +  (let [node (Node. "brick-wall")]
    5.58 +    (dorun
    5.59 +     (map
    5.60 +      (comp  #(.attachChild node %) brick*)
    5.61 +       (for [y (range 10)
    5.62 +	     x (range 4)
    5.63 +	     z (range 1)]
    5.64 +       	    (Vector3f.
    5.65 +       	     (+ (* 2 x brick-length)
    5.66 +		(if (even? (+ y z)) 
    5.67 +		  (/ brick-length 4) (/ brick-length -4)))
    5.68 +       	     (+ (* brick-height (inc (* 2 y))))
    5.69 +	     (* 2 z brick-width) ))))
    5.70 +    (.setShadowMode node RenderQueue$ShadowMode/CastAndReceive)
    5.71 +    node))
    5.72 +
    5.73 +
    5.74  #+end_src
    5.75  
    5.76