Mercurial > cortex
comparison org/body.org @ 140:22444eb20ecc
de-macrofication complete.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Thu, 02 Feb 2012 01:32:31 -0700 |
parents | ffbab4199c0d |
children | 22e193b5c60f |
comparison
equal
deleted
inserted
replaced
139:ffbab4199c0d | 140:22444eb20ecc |
---|---|
343 (.mult (.getPhysicsRotation control) | 343 (.mult (.getPhysicsRotation control) |
344 (.mult (.normalize direction) (float force)))))) | 344 (.mult (.normalize direction) (float force)))))) |
345 | 345 |
346 | 346 |
347 | 347 |
348 (defmacro with-movement | 348 (defn with-movement |
349 [object | 349 [object |
350 [up down left right roll-up roll-down :as keyboard] | 350 [up down left right roll-up roll-down :as keyboard] |
351 forces | 351 forces |
352 [world-invocation | 352 [root-node |
353 root-node | |
354 keymap | 353 keymap |
355 intilization | 354 intilization |
356 world-loop]] | 355 world-loop]] |
357 (let [add-keypress | 356 (let [add-keypress |
358 (fn [state keymap key] | 357 (fn [state keymap key] |
359 `(merge ~keymap | 358 (merge keymap |
360 {~key | 359 {key |
361 (fn [_# pressed?#] | 360 (fn [_ pressed?] |
362 (reset! ~state pressed?#))})) | 361 (reset! state pressed?))})) |
363 move-left? (gensym "move-left?") | 362 move-up? (atom false) |
364 move-right? (gensym "move-right?") | 363 move-down? (atom false) |
365 move-up? (gensym "move-up?") | 364 move-left? (atom false) |
366 move-down? (gensym "move-down?") | 365 move-right? (atom false) |
367 roll-left? (gensym "roll-left?") | 366 roll-left? (atom false) |
368 roll-right? (gensym "roll-right?") | 367 roll-right? (atom false) |
369 directions [[0 1 0][0 -1 0][0 0 1][0 0 -1][-1 0 0][1 0 0]] | 368 |
370 symbols [move-left? move-right? move-up? move-down? | 369 directions [(Vector3f. 0 1 0)(Vector3f. 0 -1 0) |
370 (Vector3f. 0 0 1)(Vector3f. 0 0 -1) | |
371 (Vector3f. -1 0 0)(Vector3f. 1 0 0)] | |
372 atoms [move-left? move-right? move-up? move-down? | |
371 roll-left? roll-right?] | 373 roll-left? roll-right?] |
372 | 374 |
373 keymap* (vec (map #(add-keypress %1 keymap %2) | 375 keymap* (reduce merge |
374 symbols | 376 (map #(add-keypress %1 keymap %2) |
375 keyboard)) | 377 atoms |
378 keyboard)) | |
376 | 379 |
377 splice-loop (map (fn [sym direction force] | 380 splice-loop (fn [] |
378 `(if (deref ~sym) | 381 (dorun |
379 (tap ~object | 382 (map |
380 (Vector3f. ~@direction) | 383 (fn [sym direction force] |
381 ~force))) | 384 (if @sym |
382 symbols directions forces) | 385 (tap object direction force))) |
383 | 386 atoms directions forces))) |
384 world-loop* `(fn [world# tpf#] | 387 |
385 (~world-loop world# tpf#) | 388 world-loop* (fn [world tpf] |
386 ~@splice-loop)] | 389 (world-loop world tpf) |
387 `(let [~move-up? (atom false) | 390 (splice-loop))] |
388 ~move-down? (atom false) | 391 |
389 ~move-left? (atom false) | 392 [root-node |
390 ~move-right? (atom false) | 393 keymap* |
391 ~roll-left? (atom false) | 394 intilization |
392 ~roll-right? (atom false)] | 395 world-loop*])) |
393 (~world-invocation | |
394 ~root-node | |
395 (reduce merge ~keymap*) | |
396 ~intilization | |
397 ~world-loop*)))) | |
398 | 396 |
399 | 397 |
400 (defn test-proprioception | 398 (defn test-proprioception |
401 "Testing proprioception: | 399 "Testing proprioception: |
402 You should see two foating bars, and a printout of pitch, yaw, and | 400 You should see two foating bars, and a printout of pitch, yaw, and |
425 finger-control (.getControl finger RigidBodyControl) | 423 finger-control (.getControl finger RigidBodyControl) |
426 hand-control (.getControl hand RigidBodyControl) | 424 hand-control (.getControl hand RigidBodyControl) |
427 | 425 |
428 controls | 426 controls |
429 (merge standard-debug-controls | 427 (merge standard-debug-controls |
430 {"key-y" | 428 {"key-o" |
431 (fn [_ _] (.setEnabled finger-control true)) | 429 (fn [_ _] (.setEnabled finger-control true)) |
432 "key-u" | 430 "key-p" |
433 (fn [_ _] (.setEnabled finger-control false)) | 431 (fn [_ _] (.setEnabled finger-control false)) |
432 "key-k" | |
433 (fn [_ _] (.setEnabled hand-control true)) | |
434 "key-l" | |
435 (fn [_ _] (.setEnabled hand-control false)) | |
434 "key-i" | 436 "key-i" |
435 (fn [_ _] (.setEnabled hand-control true)) | |
436 "key-o" | |
437 (fn [_ _] (.setEnabled hand-control false)) | |
438 "key-q" | |
439 (fn [world _] (set-gravity world (Vector3f. 0 0 0))) | 437 (fn [world _] (set-gravity world (Vector3f. 0 0 0))) |
440 } | 438 } |
441 ) | 439 ) |
442 | 440 |
443 ] | 441 ] |
444 (comment | 442 (comment |
445 (.setCollisionGroup | 443 (.setCollisionGroup |
446 (.getControl hand RigidBodyControl) | 444 (.getControl hand RigidBodyControl) |
447 PhysicsCollisionObject/COLLISION_GROUP_NONE) | 445 PhysicsCollisionObject/COLLISION_GROUP_NONE) |
448 ) | 446 ) |
449 | 447 (apply |
450 (with-movement | 448 world |
451 hand | 449 (with-movement |
452 ["key-w" "key-e" "key-s" "key-d" "key-x" "key-c"] | 450 hand |
453 [10 10 10 10 1 1] | 451 ["key-y" "key-u" "key-h" "key-j" "key-n" "key-m"] |
454 (with-movement | 452 [10 10 10 10 1 1] |
455 finger | 453 (with-movement |
456 ["key-r" "key-t" "key-f" "key-g" "key-v" "key-b"] | 454 finger |
457 [10 10 10 10 1 1] | 455 ["key-r" "key-t" "key-f" "key-g" "key-v" "key-b"] |
458 (world | 456 [10 10 10 10 1 1] |
459 root | 457 [root |
460 controls | 458 controls |
461 (fn [world] | 459 (fn [world] |
462 (.setTimer world (com.aurellem.capture.RatchetTimer. 60)) | 460 (.setTimer world (com.aurellem.capture.RatchetTimer. 60)) |
463 (set-gravity world (Vector3f. 0 0 0)) | 461 (set-gravity world (Vector3f. 0 0 0)) |
464 (light-up-everything world)) | 462 (light-up-everything world)) |
465 (fn [_ _] (prop-view (list (prop))))))))) | 463 (fn [_ _] (prop-view (list (prop))))]))))) |
466 | 464 |
467 | |
468 | |
469 | |
470 #+end_src | 465 #+end_src |
471 | 466 |
472 #+results: test-body | 467 #+results: test-body |
473 : #'cortex.test.body/test-proprioception | 468 : #'cortex.test.body/test-proprioception |
474 | 469 |