# HG changeset patch # User Robert McIntyre # Date 1370949222 14400 # Node ID 42ddfe406c0a3897eb833cdb6b9b3ee59b098166 # Parent ee977613c2442ff3c26e8b4ac72ce0e439bdbfde working on depth maps for the lulz. diff -r ee977613c244 -r 42ddfe406c0a org/body.org --- a/org/body.org Fri Jun 07 11:49:09 2013 -0400 +++ b/org/body.org Tue Jun 11 07:13:42 2013 -0400 @@ -179,6 +179,9 @@ no-op))) #+end_src +#+results: test-2 +: #'cortex.test.body/test-hand-2 + #+begin_html
diff -r ee977613c244 -r 42ddfe406c0a org/depth-map.org --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org/depth-map.org Tue Jun 11 07:13:42 2013 -0400 @@ -0,0 +1,51 @@ + +#+begin_src clojure +(ns cortex.depth-map + "lol depth maps." + {:author "Robert McIntyre"} + (:use (cortex world util body sense vision touch)) + (:import (com.jme3.scene Geometry Node Mesh)) + (:import com.jme3.collision.CollisionResults) + (:import com.jme3.scene.VertexBuffer$Type) + + (:import (com.jme3.math Triangle Vector3f Vector2f Ray Matrix4f))) + +(cortex.import/mega-import-jme3) + +(defn convert-pixel-to-ray + [camera x y] + (let [pixel-arrow + (.getWorldCoordinates + camera + (Vector2f. (float x) (float y)) + ;; this is the "z depth" and can be anything, since + ;; we only care about direction + (float 1)) + ;; now that we have the direction of a pixel, subtract + ray (Ray.)] + (set-ray ray Matrix4f/IDENTITY (.getLocation camera) + pixel-arrow) ray)) + + +(defn generate-depth-map-points + "Generate a data structure representating the depth of the first + object to collide with a ray from the camera's current position." + [world camera] + (let [width (.getWidth camera) + height (.getHeight camera) + pixels (for [x (range width) y (range height)] + [x y]) + + depths + (for [[x y] pixels] + (let [ray (convert-pixel-to-ray camera x y) + results (CollisionResults.)] + (.collideWith world ray results) + (.getDistance (.getClosestCollision results))))] + (zipmap pixels depths))) + +(defn test-world [] + (nodify [(floor*) (brick-wall*)])) + +(defn run-depth-map-test [] +#+end_src \ No newline at end of file diff -r ee977613c244 -r 42ddfe406c0a org/gabor.org --- a/org/gabor.org Fri Jun 07 11:49:09 2013 -0400 +++ b/org/gabor.org Tue Jun 11 07:13:42 2013 -0400 @@ -177,68 +177,6 @@ (println (.dump kernel))) -(def brick-length 0.48) -(def brick-width 0.24) -(def brick-height 0.12) -(def gravity (Vector3f. 0 -9.81 0)) - - -(defn brick* [position] - (println "get brick.") - (doto (box brick-length brick-height brick-width - :position position :name "brick" - :material "Common/MatDefs/Misc/Unshaded.j3md" - :texture "Textures/Terrain/BrickWall/BrickWall.jpg" - :mass 34) - (-> - (.getMesh) - (.scaleTextureCoordinates (Vector2f. 1 0.5))) - (.setShadowMode RenderQueue$ShadowMode/CastAndReceive) - ) - ) - - -(defn floor* - "make a sturdy, unmovable physical floor" - [] - (box 10 0.1 5 :name "floor" :mass 0 - :color ColorRGBA/Gray :position (Vector3f. 0 0 0))) - -(defn floor* [] - (doto (box 10 0.1 5 :name "floor" ;10 0.1 5 ; 240 0.1 240 - :material "Common/MatDefs/Misc/Unshaded.j3md" - :texture "Textures/BronzeCopper030.jpg" - :position (Vector3f. 0 0 0 ) - :mass 0) - (-> - (.getMesh) - (.scaleTextureCoordinates (Vector2f. 3 6)));64 64 - (-> - (.getMaterial) - (.getTextureParam "ColorMap") - (.getTextureValue) - (.setWrap Texture$WrapMode/Repeat)) - (.setShadowMode RenderQueue$ShadowMode/Receive) - )) - - -(defn brick-wall* [] - (let [node (Node. "brick-wall")] - (dorun - (map - (comp #(.attachChild node %) brick*) - (for [y (range 10) - x (range 4) - z (range 1)] - (Vector3f. - (+ (* 2 x brick-length) - (if (even? (+ y z)) - (/ brick-length 4) (/ brick-length -4))) - (+ (* brick-height (inc (* 2 y)))) - (* 2 z brick-width) )))) - (.setShadowMode node RenderQueue$ShadowMode/CastAndReceive) - node)) - (import com.aurellem.capture.Capture) (import java.io.File) diff -r ee977613c244 -r 42ddfe406c0a org/touch.org --- a/org/touch.org Fri Jun 07 11:49:09 2013 -0400 +++ b/org/touch.org Tue Jun 11 07:13:42 2013 -0400 @@ -388,7 +388,6 @@ (.normalizeLocal (.getDirection ray))) (import com.jme3.math.FastMath) - (defn touch-kernel "Constructs a function which will return tactile sensory data from diff -r ee977613c244 -r 42ddfe406c0a org/util.org --- a/org/util.org Fri Jun 07 11:49:09 2013 -0400 +++ b/org/util.org Tue Jun 11 07:13:42 2013 -0400 @@ -365,6 +365,73 @@ (into-array String ["blend"]))) model)) + +(def brick-length 0.48) +(def brick-width 0.24) +(def brick-height 0.12) +(def gravity (Vector3f. 0 -9.81 0)) + +(import com.jme3.math.Vector2f) +(import com.jme3.renderer.queue.RenderQueue$ShadowMode) +(import com.jme3.texture.Texture$WrapMode) + +(defn brick* [position] + (println "get brick.") + (doto (box brick-length brick-height brick-width + :position position :name "brick" + :material "Common/MatDefs/Misc/Unshaded.j3md" + :texture "Textures/Terrain/BrickWall/BrickWall.jpg" + :mass 34) + (-> + (.getMesh) + (.scaleTextureCoordinates (Vector2f. 1 0.5))) + (.setShadowMode RenderQueue$ShadowMode/CastAndReceive) + ) + ) + + +(defn floor* + "make a sturdy, unmovable physical floor" + [] + (box 10 0.1 5 :name "floor" :mass 0 + :color ColorRGBA/Gray :position (Vector3f. 0 0 0))) + +(defn floor* [] + (doto (box 10 0.1 5 :name "floor" ;10 0.1 5 ; 240 0.1 240 + :material "Common/MatDefs/Misc/Unshaded.j3md" + :texture "Textures/BronzeCopper030.jpg" + :position (Vector3f. 0 0 0 ) + :mass 0) + (-> + (.getMesh) + (.scaleTextureCoordinates (Vector2f. 3 6)));64 64 + (-> + (.getMaterial) + (.getTextureParam "ColorMap") + (.getTextureValue) + (.setWrap Texture$WrapMode/Repeat)) + (.setShadowMode RenderQueue$ShadowMode/Receive) + )) + + +(defn brick-wall* [] + (let [node (Node. "brick-wall")] + (dorun + (map + (comp #(.attachChild node %) brick*) + (for [y (range 10) + x (range 4) + z (range 1)] + (Vector3f. + (+ (* 2 x brick-length) + (if (even? (+ y z)) + (/ brick-length 4) (/ brick-length -4))) + (+ (* brick-height (inc (* 2 y)))) + (* 2 z brick-width) )))) + (.setShadowMode node RenderQueue$ShadowMode/CastAndReceive) + node)) + + #+end_src