Mercurial > cortex
view org/depth-map.org @ 530:21b8389922ee
fix vermopomorphic footnote.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 26 Apr 2014 19:36:13 -0400 |
parents | a86555b02916 |
children |
line wrap: on
line source
2 #+begin_src clojure3 (ns cortex.depth-map4 "lol depth maps."5 {:author "Robert McIntyre"}6 (:use (cortex world util body sense vision touch))7 (:import (com.jme3.scene Geometry Node Mesh))8 (:import com.jme3.collision.CollisionResults)9 (:import com.jme3.scene.VertexBuffer$Type)11 (:import (com.jme3.math Triangle Vector3f Vector2f Ray Matrix4f)))13 (cortex.import/mega-import-jme3)15 (defn convert-pixel-to-ray16 [camera ray x y]17 (let [pixel-arrow18 (.getWorldCoordinates19 camera20 (Vector2f. (float x) (float y))21 ;; this is the "z depth" and can be anything, since22 ;; we only care about direction23 (float 1))24 ;; now that we have the direction of a pixel, subtract25 ray (Ray.)]26 (set-ray ray Matrix4f/IDENTITY (.getLocation camera)27 pixel-arrow) ray))29 (defn generate-depth-map-points30 "Generate a data structure representating the depth of the first31 object to collide with a ray from the camera's current position."32 [world camera]33 (let [width (.getWidth camera)34 height (.getHeight camera)35 pixels (for [x (range width) y (range height)]36 [x y])37 temp-ray (Ray.)38 depths39 (for [[x y] pixels]40 (let [ray (convert-pixel-to-ray camera temp-ray x y)41 results (CollisionResults.)]42 (.collideWith world ray results)43 (if-let [closest (.getClosestCollision results)]44 (.hashCode (.getGeometry closest)) 0)))]46 (zipmap pixels depths)))48 (defn test-world []49 (nodify [(floor*) (brick-wall*)]))51 (import com.aurellem.capture.RatchetTimer)53 (defn depth-map-test []54 (let [the-world (test-world)]55 (world56 the-world57 ;;controls58 standard-debug-controls59 ;;init60 (fn [world]61 (let [timer (RatchetTimer. 60)]62 (.setTimer world timer)63 (display-dilated-time world timer)))64 ;; update65 no-op)))67 #+end_src