Mercurial > cortex
comparison org/depth-map.org @ 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 | |
children | a86555b02916 |
comparison
equal
deleted
inserted
replaced
457:ee977613c244 | 458:42ddfe406c0a |
---|---|
1 | |
2 #+begin_src clojure | |
3 (ns cortex.depth-map | |
4 "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) | |
10 | |
11 (:import (com.jme3.math Triangle Vector3f Vector2f Ray Matrix4f))) | |
12 | |
13 (cortex.import/mega-import-jme3) | |
14 | |
15 (defn convert-pixel-to-ray | |
16 [camera x y] | |
17 (let [pixel-arrow | |
18 (.getWorldCoordinates | |
19 camera | |
20 (Vector2f. (float x) (float y)) | |
21 ;; this is the "z depth" and can be anything, since | |
22 ;; we only care about direction | |
23 (float 1)) | |
24 ;; now that we have the direction of a pixel, subtract | |
25 ray (Ray.)] | |
26 (set-ray ray Matrix4f/IDENTITY (.getLocation camera) | |
27 pixel-arrow) ray)) | |
28 | |
29 | |
30 (defn generate-depth-map-points | |
31 "Generate a data structure representating the depth of the first | |
32 object to collide with a ray from the camera's current position." | |
33 [world camera] | |
34 (let [width (.getWidth camera) | |
35 height (.getHeight camera) | |
36 pixels (for [x (range width) y (range height)] | |
37 [x y]) | |
38 | |
39 depths | |
40 (for [[x y] pixels] | |
41 (let [ray (convert-pixel-to-ray camera x y) | |
42 results (CollisionResults.)] | |
43 (.collideWith world ray results) | |
44 (.getDistance (.getClosestCollision results))))] | |
45 (zipmap pixels depths))) | |
46 | |
47 (defn test-world [] | |
48 (nodify [(floor*) (brick-wall*)])) | |
49 | |
50 (defn run-depth-map-test [] | |
51 #+end_src |