Mercurial > cortex
comparison org/worm_learn.clj @ 449:09b7c8dd4365
first chapter done, half of last chapter done.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Wed, 26 Mar 2014 02:42:01 -0400 |
parents | 47cfbe84f00e |
children | 0a4362d1f138 |
comparison
equal
deleted
inserted
replaced
448:af13fc73e851 | 449:09b7c8dd4365 |
---|---|
24 | 24 |
25 (def hand "Models/test-creature/hand.blend") | 25 (def hand "Models/test-creature/hand.blend") |
26 | 26 |
27 (defn worm-model [] | 27 (defn worm-model [] |
28 (load-blender-model "Models/worm/worm.blend")) | 28 (load-blender-model "Models/worm/worm.blend")) |
29 | |
30 (defn worm [] | |
31 (let [model (load-blender-model "Models/worm/worm.blend")] | |
32 {:body (doto model (body!)) | |
33 :touch (touch! model) | |
34 :proprioception (proprioception! model) | |
35 :muscles (movement! model)})) | |
29 | 36 |
30 (def output-base (File. "/home/r/proj/cortex/render/worm-learn/curl")) | 37 (def output-base (File. "/home/r/proj/cortex/render/worm-learn/curl")) |
31 | 38 |
32 | 39 |
33 (defn motor-control-program | 40 (defn motor-control-program |
218 head-touch (worm-touch 4)] | 225 head-touch (worm-touch 4)] |
219 (and (< 0.55 (contact worm-segment-bottom-tip tail-touch)) | 226 (and (< 0.55 (contact worm-segment-bottom-tip tail-touch)) |
220 (< 0.55 (contact worm-segment-top-tip head-touch)))))) | 227 (< 0.55 (contact worm-segment-top-tip head-touch)))))) |
221 | 228 |
222 | 229 |
223 (declare phi-space phi-scan) | 230 (declare phi-space phi-scan debug-experience) |
224 | 231 |
225 (defn debug-experience | |
226 [experiences text] | |
227 (cond | |
228 (grand-circle? experiences) (.setText text "Grand Circle") | |
229 (curled? experiences) (.setText text "Curled") | |
230 (wiggling? experiences) (.setText text "Wiggling") | |
231 (resting? experiences) (.setText text "Resting"))) | |
232 | 232 |
233 | 233 |
234 (def standard-world-view | 234 (def standard-world-view |
235 [(Vector3f. 4.207176, -3.7366982, 3.0816958) | 235 [(Vector3f. 4.207176, -3.7366982, 3.0816958) |
236 (Quaternion. 0.11118768, 0.87678415, 0.24434438, -0.3989771)]) | 236 (Quaternion. 0.11118768, 0.87678415, 0.24434438, -0.3989771)]) |
275 (.setShadowIntensity (float 0.6)) | 275 (.setShadowIntensity (float 0.6)) |
276 (.setCompareMode PssmShadowRenderer$CompareMode/Software) | 276 (.setCompareMode PssmShadowRenderer$CompareMode/Software) |
277 (.setFilterMode PssmShadowRenderer$FilterMode/Bilinear))] | 277 (.setFilterMode PssmShadowRenderer$FilterMode/Bilinear))] |
278 (.addProcessor (.getViewPort world) pssm))) | 278 (.addProcessor (.getViewPort world) pssm))) |
279 | 279 |
280 | 280 (defn debug-experience |
281 (defn display-text [[x y :as location]] | 281 [experiences text] |
282 (let [] | 282 (cond |
283 (.setLocalTranslation text 300 (.getLineHeight text) 0) | 283 (grand-circle? experiences) (.setText text "Grand Circle") |
284 (fn [world] | 284 (curled? experiences) (.setText text "Curled") |
285 | 285 (wiggling? experiences) (.setText text "Wiggling") |
286 | 286 (resting? experiences) (.setText text "Resting"))) |
287 | 287 |
288 | |
289 (fn [new-text] | |
290 | 288 |
291 (defn worm-world | 289 (defn worm-world |
292 [& {:keys [record motor-control keybindings view experiences | 290 [& {:keys [record motor-control keybindings view experiences |
293 worm-model end-frame experience-watch] :as settings}] | 291 worm-model end-frame experience-watch] :as settings}] |
294 (let [{:keys [record motor-control keybindings view experiences | 292 (let [{:keys [record motor-control keybindings view experiences |
295 worm-model end-frame experience-watch]} | 293 worm-model end-frame experience-watch]} |
296 (merge (worm-world-defaults) settings) | 294 (merge (worm-world-defaults) settings) |
297 worm (doto (worm-model) (body!)) | 295 |
298 touch (touch! worm) | |
299 prop (proprioception! worm) | |
300 muscles (movement! worm) | |
301 | |
302 touch-display (view-touch) | 296 touch-display (view-touch) |
303 prop-display (view-proprioception) | 297 prop-display (view-proprioception) |
304 muscle-display (view-movement) | 298 muscle-display (view-movement) |
299 {:keys [proprioception touch muscles body]} (worm) | |
305 | 300 |
306 floor | 301 floor |
307 (box 5 1 5 :position (Vector3f. 0 -10 0) | 302 (box 5 1 5 :position (Vector3f. 0 -10 0) |
308 :mass 0 | 303 :mass 0 |
309 :texture "Textures/aurellem.png" | 304 :texture "Textures/aurellem.png" |
314 worm-action (doto (BitmapText. font false) | 309 worm-action (doto (BitmapText. font false) |
315 (.setSize 35) | 310 (.setSize 35) |
316 (.setColor (ColorRGBA/Black)))] | 311 (.setColor (ColorRGBA/Black)))] |
317 | 312 |
318 (world | 313 (world |
319 (nodify [worm floor]) | 314 (nodify [body floor]) |
320 (merge standard-debug-controls keybindings) | 315 (merge standard-debug-controls keybindings) |
321 (fn [world] | 316 (fn [world] |
322 (.setLocalTranslation | 317 (.setLocalTranslation |
323 worm-action 20 470 0) | 318 worm-action 20 470 0) |
324 (.attachChild (.getGuiNode world) worm-action) | 319 (.attachChild (.getGuiNode world) worm-action) |
325 | 320 |
326 (enable-good-shadows world) | 321 (enable-good-shadows world) |
327 (.setShadowMode worm RenderQueue$ShadowMode/CastAndReceive) | 322 (.setShadowMode body RenderQueue$ShadowMode/CastAndReceive) |
328 (.setShadowMode floor RenderQueue$ShadowMode/Receive) | 323 (.setShadowMode floor RenderQueue$ShadowMode/Receive) |
329 | 324 |
330 (.setBackgroundColor (.getViewPort world) (ColorRGBA/White)) | 325 (.setBackgroundColor (.getViewPort world) (ColorRGBA/White)) |
331 (.setDisplayStatView world false) | 326 (.setDisplayStatView world false) |
332 (.setDisplayFps world false) | 327 (.setDisplayFps world false) |
333 (position-camera world view) | 328 (position-camera world view) |
334 (.setTimer world timer) | 329 (.setTimer world timer) |
335 (display-dilated-time world timer) | 330 ;;(display-dilated-time world timer) |
336 (when record | 331 (when record |
337 (dir! record) | 332 (dir! record) |
338 (Capture/captureVideo | 333 (Capture/captureVideo |
339 world | 334 world |
340 (dir! (File. record "main-view")))) | 335 (dir! (File. record "main-view")))) |
343 ) | 338 ) |
344 (fn [world tpf] | 339 (fn [world tpf] |
345 (if (and end-frame (> (.getTime timer) end-frame)) | 340 (if (and end-frame (> (.getTime timer) end-frame)) |
346 (.stop world)) | 341 (.stop world)) |
347 (let [muscle-data (vec (motor-control muscles)) | 342 (let [muscle-data (vec (motor-control muscles)) |
348 proprioception-data (prop) | 343 proprioception-data (proprioception) |
349 touch-data (mapv #(% (.getRootNode world)) touch)] | 344 touch-data (mapv #(% (.getRootNode world)) touch)] |
350 (when experiences | 345 (when experiences |
351 (record-experience! | 346 (record-experience! |
352 experiences {:touch touch-data | 347 experiences {:touch touch-data |
353 :proprioception proprioception-data | 348 :proprioception proprioception-data |