Mercurial > cortex
comparison org/body.org @ 138:16bdf9e80daf
working movement debug framework
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Thu, 02 Feb 2012 00:05:17 -0700 |
parents | 39c89ae5c7d0 |
children | ffbab4199c0d |
comparison
equal
deleted
inserted
replaced
137:39c89ae5c7d0 | 138:16bdf9e80daf |
---|---|
356 world-loop]] | 356 world-loop]] |
357 (let [add-keypress | 357 (let [add-keypress |
358 (fn [state keymap key] | 358 (fn [state keymap key] |
359 `(merge ~keymap | 359 `(merge ~keymap |
360 {~key | 360 {~key |
361 (fn [_ pressed?#] | 361 (fn [_# pressed?#] |
362 (reset! ~state pressed?#))})) | 362 (reset! ~state pressed?#))})) |
363 move-left? (gensym "move-left?") | 363 move-left? (gensym "move-left?") |
364 move-right? (gensym "move-right?") | 364 move-right? (gensym "move-right?") |
365 move-up? (gensym "move-up?") | 365 move-up? (gensym "move-up?") |
366 move-down? (gensym "move-down?") | 366 move-down? (gensym "move-down?") |
367 roll-left? (gensym "roll-left?") | 367 roll-left? (gensym "roll-left?") |
368 roll-right? (gensym "roll-right?") | 368 roll-right? (gensym "roll-right?") |
369 directions | 369 directions [[0 1 0][0 -1 0][0 0 1][0 0 -1][-1 0 0][1 0 0]] |
370 [(Vector3f. 0 1 0) | |
371 (Vector3f. 0 -1 0) | |
372 (Vector3f. 0 0 1) | |
373 (Vector3f. 0 0 -1) | |
374 (Vector3f. -1 0 0) | |
375 (Vector3f. 1 0 0)] | |
376 symbols [move-left? move-right? move-up? move-down? | 370 symbols [move-left? move-right? move-up? move-down? |
377 roll-left? roll-right?] | 371 roll-left? roll-right?] |
378 | 372 |
379 keymap* (vec (map #(add-keypress %1 keymap %2) | 373 keymap* (vec (map #(add-keypress %1 keymap %2) |
380 symbols | 374 symbols |
381 keyboard)) | 375 keyboard)) |
382 | 376 |
383 splice-loop (map (fn [sym force direction] | 377 splice-loop (map (fn [sym direction force] |
384 `(if (deref ~sym) | 378 `(if (deref ~sym) |
385 (tap ~object ~direction ~force))) | 379 (tap ~object |
380 (Vector3f. ~@direction) | |
381 ~force))) | |
386 symbols directions forces) | 382 symbols directions forces) |
387 | 383 |
388 world-loop* `(fn [world# tpf#] | 384 world-loop* `(fn [world# tpf#] |
389 (~world-loop world# tpf#) | 385 (~world-loop world# tpf#) |
390 ~@splice-loop)] | 386 ~@splice-loop)] |
397 ~roll-right? (atom false)] | 393 ~roll-right? (atom false)] |
398 (~world-invocation | 394 (~world-invocation |
399 ~root-node | 395 ~root-node |
400 (reduce merge ~keymap*) | 396 (reduce merge ~keymap*) |
401 ~intilization | 397 ~intilization |
402 ~world-loop*) | 398 ~world-loop*)))) |
403 ))) | |
404 | 399 |
405 | 400 |
406 (defn test-proprioception | 401 (defn test-proprioception |
407 "Testing proprioception: | 402 "Testing proprioception: |
408 You should see two foating bars, and a printout of pitch, yaw, and | 403 You should see two foating bars, and a printout of pitch, yaw, and |
423 ;; ******************************************* | 418 ;; ******************************************* |
424 | 419 |
425 floor (box 10 10 10 :position (Vector3f. 0 -15 0) | 420 floor (box 10 10 10 :position (Vector3f. 0 -15 0) |
426 :mass 0 :color ColorRGBA/Gray) | 421 :mass 0 :color ColorRGBA/Gray) |
427 | 422 |
428 move-up? (atom false) | |
429 move-down? (atom false) | |
430 move-left? (atom false) | |
431 move-right? (atom false) | |
432 roll-left? (atom false) | |
433 roll-right? (atom false) | |
434 | |
435 | |
436 root (nodify [creature floor]) | 423 root (nodify [creature floor]) |
437 prop (joint-proprioception creature joint-node) | 424 prop (joint-proprioception creature joint-node) |
438 prop-view (proprioception-debug-window)] | 425 prop-view (proprioception-debug-window)] |
439 | |
440 | |
441 | 426 |
442 (.setCollisionGroup | 427 (.setCollisionGroup |
443 (.getControl hand RigidBodyControl) | 428 (.getControl hand RigidBodyControl) |
444 PhysicsCollisionObject/COLLISION_GROUP_NONE) | 429 PhysicsCollisionObject/COLLISION_GROUP_NONE) |
445 | 430 |
447 finger | 432 finger |
448 ["key-r" "key-t" "key-f" "key-g" "key-v" "key-b"] | 433 ["key-r" "key-t" "key-f" "key-g" "key-v" "key-b"] |
449 [10 10 10 10 1 1] | 434 [10 10 10 10 1 1] |
450 (world | 435 (world |
451 root | 436 root |
452 (merge standard-debug-controls | 437 standard-debug-controls |
453 {"key-r" (fn [_ pressed?] (reset! move-up? pressed?)) | |
454 "key-t" (fn [_ pressed?] (reset! move-down? pressed?)) | |
455 "key-f" (fn [_ pressed?] (reset! move-left? pressed?)) | |
456 "key-g" (fn [_ pressed?] (reset! move-right? pressed?)) | |
457 "key-v" (fn [_ pressed?] (reset! roll-left? pressed?)) | |
458 "key-b" (fn [_ pressed?] (reset! roll-right? pressed?))}) | |
459 (fn [world] | 438 (fn [world] |
460 (.setTimer world (com.aurellem.capture.RatchetTimer. 60)) | 439 (.setTimer world (com.aurellem.capture.RatchetTimer. 60)) |
461 (set-gravity world (Vector3f. 0 0 0)) | 440 (set-gravity world (Vector3f. 0 0 0)) |
462 (light-up-everything world)) | 441 (light-up-everything world)) |
463 (fn [_ _] | 442 (fn [_ _] (prop-view (list (prop)))))))) |
464 (let [force 10 | 443 |
465 left (Vector3f. 0 1 0) | 444 |
466 right (Vector3f. 0 -1 0) | 445 |
467 up (Vector3f. 0 0 1) | |
468 down (Vector3f. 0 0 -1) | |
469 roll-left (Vector3f. -1 0 0) | |
470 roll-right (Vector3f. 1 0 0)] | |
471 (if @move-up? (tap finger up force)) | |
472 | |
473 (if @move-down? (tap finger down force)) | |
474 | |
475 (if @move-left? (tap finger left force)) | |
476 | |
477 (if @move-right? (tap finger right force)) | |
478 | |
479 (if @roll-left? (tap finger roll-left (/ force 10))) | |
480 | |
481 (if @roll-right? (tap finger roll-right (/ force 10)))) | |
482 | |
483 (prop-view (list (prop)))))))) | |
484 | 446 |
485 #+end_src | 447 #+end_src |
486 | 448 |
487 #+results: test-body | 449 #+results: test-body |
488 : #'cortex.test.body/test-proprioception | 450 : #'cortex.test.body/test-proprioception |