Mercurial > cortex
comparison org/test-creature.org @ 134:ac350a0ac6b0
proprioception refrence frame is wrong, trying to fix...
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Wed, 01 Feb 2012 02:44:07 -0700 |
parents | 2ed7e60d3821 |
children | 421cc43441ae |
comparison
equal
deleted
inserted
replaced
133:2ed7e60d3821 | 134:ac350a0ac6b0 |
---|---|
1056 | 1056 |
1057 ;; higher level --- sense/effector | 1057 ;; higher level --- sense/effector |
1058 ;; these are the functions that provide world i/o, chinese-room style | 1058 ;; these are the functions that provide world i/o, chinese-room style |
1059 | 1059 |
1060 | 1060 |
1061 (defn creature-joints | |
1062 "Return the children of the creature's \"joints\" node." | |
1063 [#^Node creature] | |
1064 (if-let [joint-node (.getChild creature "joints")] | |
1065 (seq (.getChildren joint-node)) | |
1066 (do (println-repl "could not find JOINTS node") []))) | |
1067 | |
1061 | 1068 |
1062 (defn blender-creature | 1069 (defn blender-creature |
1063 "Return a creature with all joints in place." | 1070 "Return a creature with all joints in place." |
1064 [blender-path] | 1071 [blender-path] |
1065 (let [model (load-blender-model blender-path) | 1072 (let [model (load-blender-model blender-path) |
1066 joints | 1073 joints (creature-joints model)] |
1067 (if-let [joint-node (.getChild model "joints")] | 1074 (assemble-creature model joints))) |
1068 (seq (.getChildren joint-node)) | |
1069 (do (println-repl "could not find joints node") []))] | |
1070 (assemble-creature model joints))) | |
1071 | 1075 |
1072 (defn gray-scale [num] | 1076 (defn gray-scale [num] |
1073 (+ num | 1077 (+ num |
1074 (bit-shift-left num 8) | 1078 (bit-shift-left num 8) |
1075 (bit-shift-left num 16))) | 1079 (bit-shift-left num 16))) |
1165 (map | 1169 (map |
1166 (fn [[yaw pitch roll]] | 1170 (fn [[yaw pitch roll]] |
1167 [(rad->deg yaw) | 1171 [(rad->deg yaw) |
1168 (rad->deg pitch) | 1172 (rad->deg pitch) |
1169 (rad->deg roll)]) | 1173 (rad->deg roll)]) |
1170 sensor-data))))) | 1174 sensor-data))))) |
1175 | |
1176 | |
1177 (defn draw-sprite [image sprite x y color ] | |
1178 (dorun | |
1179 (for [[u v] sprite] | |
1180 (.setRGB image (+ u x) (+ v y) color)))) | |
1181 | |
1182 (defn view-angle | |
1183 "create a debug view of an angle" | |
1184 [color] | |
1185 (let [image (BufferedImage. 50 50 BufferedImage/TYPE_INT_RGB) | |
1186 previous (atom [25 25]) | |
1187 sprite [[0 0] [0 1] | |
1188 [0 -1] [-1 0] [1 0]]] | |
1189 (fn [angle] | |
1190 (let [angle (float angle)] | |
1191 (let [position | |
1192 [(+ 25 (int (* 20 (Math/cos angle)))) | |
1193 (+ 25 (int (* 20(Math/sin angle))))]] | |
1194 (draw-sprite image sprite (@previous 0) (@previous 1) 0x000000) | |
1195 (draw-sprite image sprite (position 0) (position 1) color) | |
1196 (reset! previous position)) | |
1197 image)))) | |
1198 | |
1199 (defn proprioception-debug-window | |
1200 [] | |
1201 (let [yaw (view-angle 0xFF0000) | |
1202 roll (view-angle 0x00FF00) | |
1203 pitch (view-angle 0xFFFFFF) | |
1204 v-yaw (view-image) | |
1205 v-roll (view-image) | |
1206 v-pitch (view-image) | |
1207 ] | |
1208 (fn [prop-data] | |
1209 (dorun | |
1210 (map | |
1211 (fn [[y r p]] | |
1212 (v-yaw (yaw y)) | |
1213 (v-roll (roll r)) | |
1214 (v-pitch (pitch p))) | |
1215 prop-data))))) | |
1216 | |
1171 | 1217 |
1172 | 1218 |
1173 | 1219 |
1174 | 1220 |
1175 | 1221 |