Mercurial > cortex
comparison org/test-creature.org @ 104:ee302b65213b
removed outdated code
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 14 Jan 2012 23:05:52 -0700 |
parents | 85ee8bb80edf |
children | 3334bf15854b |
comparison
equal
deleted
inserted
replaced
103:85ee8bb80edf | 104:ee302b65213b |
---|---|
4 #+description: | 4 #+description: |
5 #+keywords: simulation, jMonkeyEngine3, clojure | 5 #+keywords: simulation, jMonkeyEngine3, clojure |
6 #+SETUPFILE: ../../aurellem/org/setup.org | 6 #+SETUPFILE: ../../aurellem/org/setup.org |
7 #+INCLUDE: ../../aurellem/org/level-0.org | 7 #+INCLUDE: ../../aurellem/org/level-0.org |
8 | 8 |
9 | |
10 * objectives | 9 * objectives |
11 - [X] get an overall bitmap-like image for touch | 10 - [X] get an overall bitmap-like image for touch |
12 - [X] write code to visuliaze this bitmap | 11 - [X] write code to visuliaze this bitmap |
13 - [ ] directly change the UV-pixels to show touch sensor activation | 12 - [ ] directly change the UV-pixels to show touch sensor activation |
14 - [ ] write an explination for why b&w bitmaps for senses is appropiate | 13 - [ ] write an explination for why b&w bitmaps for senses is appropiate |
32 angles. I also need to determine weather to use log-polar or cartesian | 31 angles. I also need to determine weather to use log-polar or cartesian |
33 for the visual input, and I need to determine how/wether to | 32 for the visual input, and I need to determine how/wether to |
34 disceritise the visual input. | 33 disceritise the visual input. |
35 | 34 |
36 I also want to be able to visualize both the sensors and the | 35 I also want to be able to visualize both the sensors and the |
37 effectors in pretty pictures. This semi-retarted creature will by my | 36 effectors in pretty pictures. This semi-retarted creature will be my |
38 first attempt at bringing everything together. | 37 first attempt at bringing everything together. |
39 | 38 |
40 * The creature's body | 39 * The creature's body |
41 | 40 |
42 Still going to do an eve-like body in blender, but due to problems | 41 Still going to do an eve-like body in blender, but due to problems |
43 importing the joints, etc into jMonkeyEngine3, I',m going to do all | 42 importing the joints, etc into jMonkeyEngine3, I'm going to do all |
44 the connecting here in clojure code, using the names of the individual | 43 the connecting here in clojure code, using the names of the individual |
45 components and trial and error. Later, I'll maybe make some sort of | 44 components and trial and error. Later, I'll maybe make some sort of |
46 creature-building modifications to blender that support whatever | 45 creature-building modifications to blender that support whatever |
47 discreitized senses I'm going to make. | 46 discreitized senses I'm going to make. |
48 | 47 |
163 (map vector | 162 (map vector |
164 (collapse-1d (first center) | 163 (collapse-1d (first center) |
165 (map first row)) | 164 (map first row)) |
166 (map second row))) | 165 (map second row))) |
167 (partition-by second (sort-by second flattened)))) | 166 (partition-by second (sort-by second flattened)))) |
168 ;;vi (view-image) | |
169 relocate | 167 relocate |
170 (let [min-x (apply min (map first squeezed)) | 168 (let [min-x (apply min (map first squeezed)) |
171 min-y (apply min (map second squeezed))] | 169 min-y (apply min (map second squeezed))] |
172 (map (fn [[x y]] | 170 (map (fn [[x y]] |
173 [(- x min-x) | 171 [(- x min-x) |
174 (- y min-y)]) | 172 (- y min-y)]) |
175 squeezed)) | 173 squeezed))] |
176 ] | |
177 ;;(vi (points->image points)) | |
178 ;;(Thread/sleep 1000) | |
179 ;;(vi (points->image flattened)) | |
180 ;;(Thread/sleep 1000) | |
181 ;;(vi (points->image squeezed)) | |
182 relocate | 174 relocate |
183 )) | 175 )) |
184 | 176 |
185 (defn load-bullet [] | 177 (defn load-bullet [] |
186 (let [sim (world (Node.) {} no-op no-op)] | 178 (let [sim (world (Node.) {} no-op no-op)] |
903 (.applyTorque control | 895 (.applyTorque control |
904 (.mult (.getPhysicsRotation control) | 896 (.mult (.getPhysicsRotation control) |
905 (Vector3f. 1 0 0)))))))) | 897 (Vector3f. 1 0 0)))))))) |
906 | 898 |
907 | 899 |
908 (defn locate-feelers* | |
909 "Search the geometry's tactile UV image for touch sensors, returning | |
910 their positions in geometry-relative coordinates." | |
911 [#^Geometry geo] | |
912 (let [uv-image (touch-receptor-image geo) | |
913 width (.getWidth uv-image) | |
914 height (.getHeight uv-image) | |
915 | |
916 mesh (.getMesh geo) | |
917 mesh-tris (triangles geo) | |
918 | |
919 ;; for each triangle | |
920 sensor-coords | |
921 (fn [tri] | |
922 ;; translate triangle to uv-pixel-space | |
923 (let [uv-tri | |
924 (rasterize mesh tri width height) | |
925 bounds (vec (triangle-bounds uv-tri))] | |
926 | |
927 ;; get that part of the picture | |
928 | |
929 (apply (partial (memfn setRoi) uv-image) bounds) | |
930 (let [cutout (.crop (.getProcessor uv-image)) | |
931 ;; extract white pixels inside triangle | |
932 cutout-tri | |
933 (map-triangle | |
934 (fn [_ v] | |
935 (.subtract | |
936 v | |
937 (Vector3f. (bounds 0) (bounds 1) (float 0)))) | |
938 uv-tri) | |
939 whites (filter (partial inside-triangle? cutout-tri) | |
940 (map vector2f->vector3f | |
941 (white-coordinates cutout))) | |
942 ;; translate pixel coordinates to world-space | |
943 transform (triangle-transformation cutout-tri tri)] | |
944 (map #(.mult transform %) whites))))] | |
945 | |
946 (for [mesh-tri mesh-tris] | |
947 | |
948 (let [uv-tri (rasterize mesh mesh-tri width height) | |
949 bounding-box (vec (triangle-bounds uv-tri))] | |
950 (apply (partial (memfn setRoi) uv-image) bounding-box) | |
951 )) | |
952 (vec (map sensor-coords mesh-tris)))) | |
953 | |
954 | |
955 (defn tactile-coords [#^Geometry obj] | |
956 (let [mesh (.getMesh obj) | |
957 num-triangles (.getTriangleCount mesh) | |
958 num-verticies (.getVertexCount mesh) | |
959 uv-coord (partial uv-coord mesh) | |
960 triangle-indices (partial triangle-indices mesh) | |
961 receptors (touch-receptor-image obj) | |
962 tris (triangles obj) | |
963 ] | |
964 (map | |
965 (fn [[tri-1 tri-2 tri-3]] | |
966 (let [width (.getWidth receptors) | |
967 height (.getHeight receptors) | |
968 uv-1 (uv-coord tri-1) | |
969 uv-2 (uv-coord tri-2) | |
970 uv-3 (uv-coord tri-3) | |
971 x-coords (map #(.getX %) [uv-1 uv-2 uv-3]) | |
972 y-coords (map #(.getY %) [uv-1 uv-2 uv-3]) | |
973 max-x (Math/ceil (* width (apply max x-coords))) | |
974 min-x (Math/floor (* width (apply min x-coords))) | |
975 max-y (Math/ceil (* height (apply max y-coords))) | |
976 min-y (Math/floor (* height (apply min y-coords))) | |
977 | |
978 image-1 (Vector2f. (* width (.getX uv-1)) | |
979 (* height (.getY uv-1))) | |
980 image-2 (Vector2f. (* width (.getX uv-2)) | |
981 (* height (.getY uv-2))) | |
982 image-3 (Vector2f. (* width (.getX uv-3)) | |
983 (* height (.getY uv-3))) | |
984 left-corner | |
985 (Vector2f. min-x min-y) | |
986 ] | |
987 | |
988 (.setRoi receptors min-x min-y (- max-x min-x) (- max-y min-y)) | |
989 (let [processor (.crop (.getProcessor receptors))] | |
990 (map | |
991 #(.add left-corner %) | |
992 | |
993 (filter | |
994 (partial | |
995 inside-triangle? | |
996 (.subtract image-1 left-corner) | |
997 (.subtract image-2 left-corner) | |
998 (.subtract image-3 left-corner)) | |
999 (white-coordinates processor)))) | |
1000 )) (map triangle-indices (range num-triangles))))) | |
1001 | |
1002 #+end_src | 900 #+end_src |
1003 | 901 |
1004 #+results: body-1 | 902 #+results: body-1 |
1005 : #'cortex.silly/test-joint | 903 : #'cortex.silly/tactile-coords |
1006 | 904 |
1007 | 905 |
1008 * COMMENT purgatory | 906 * COMMENT purgatory |
1009 #+begin_src clojure | 907 #+begin_src clojure |
1010 (defn bullet-trans [] | 908 (defn bullet-trans [] |