comparison org/util.org @ 160:33278bf028e7

refactored joints
author Robert McIntyre <rlm@mit.edu>
date Fri, 03 Feb 2012 06:47:05 -0700
parents c95179907951
children c33a8e5fe7bc
comparison
equal deleted inserted replaced
159:75b6c2ebbf8e 160:33278bf028e7
396 396
397 (def standard-debug-controls 397 (def standard-debug-controls
398 {"key-space" (fire-cannon-ball)}) 398 {"key-space" (fire-cannon-ball)})
399 399
400 400
401 (defn tap [obj direction force]
402 (let [control (.getControl obj RigidBodyControl)]
403 (.applyTorque
404 control
405 (.mult (.getPhysicsRotation control)
406 (.mult (.normalize direction) (float force))))))
407
408
409 (defn with-movement
410 [object
411 [up down left right roll-up roll-down :as keyboard]
412 forces
413 [root-node
414 keymap
415 intilization
416 world-loop]]
417 (let [add-keypress
418 (fn [state keymap key]
419 (merge keymap
420 {key
421 (fn [_ pressed?]
422 (reset! state pressed?))}))
423 move-up? (atom false)
424 move-down? (atom false)
425 move-left? (atom false)
426 move-right? (atom false)
427 roll-left? (atom false)
428 roll-right? (atom false)
429
430 directions [(Vector3f. 0 1 0)(Vector3f. 0 -1 0)
431 (Vector3f. 0 0 1)(Vector3f. 0 0 -1)
432 (Vector3f. -1 0 0)(Vector3f. 1 0 0)]
433 atoms [move-left? move-right? move-up? move-down?
434 roll-left? roll-right?]
435
436 keymap* (reduce merge
437 (map #(add-keypress %1 keymap %2)
438 atoms
439 keyboard))
440
441 splice-loop (fn []
442 (dorun
443 (map
444 (fn [sym direction force]
445 (if @sym
446 (tap object direction force)))
447 atoms directions forces)))
448
449 world-loop* (fn [world tpf]
450 (world-loop world tpf)
451 (splice-loop))]
452 [root-node
453 keymap*
454 intilization
455 world-loop*]))
456
401 457
402 458
403 #+end_src 459 #+end_src
404 460
405 461