changeset 140:22444eb20ecc

de-macrofication complete.
author Robert McIntyre <rlm@mit.edu>
date Thu, 02 Feb 2012 01:32:31 -0700
parents ffbab4199c0d
children 22e193b5c60f
files org/body.org
diffstat 1 files changed, 59 insertions(+), 64 deletions(-) [+]
line wrap: on
line diff
     1.1 --- a/org/body.org	Thu Feb 02 00:57:18 2012 -0700
     1.2 +++ b/org/body.org	Thu Feb 02 01:32:31 2012 -0700
     1.3 @@ -345,56 +345,54 @@
     1.4  
     1.5  
     1.6  
     1.7 -(defmacro with-movement
     1.8 +(defn with-movement
     1.9    [object
    1.10     [up down left right roll-up roll-down :as keyboard]
    1.11     forces
    1.12 -   [world-invocation
    1.13 -    root-node
    1.14 +   [root-node
    1.15      keymap
    1.16      intilization
    1.17      world-loop]]
    1.18    (let [add-keypress
    1.19          (fn [state keymap key]
    1.20 -          `(merge ~keymap
    1.21 -                  {~key
    1.22 -                   (fn [_# pressed?#]
    1.23 -                     (reset! ~state pressed?#))}))
    1.24 -        move-left? (gensym "move-left?")
    1.25 -        move-right? (gensym "move-right?")
    1.26 -        move-up? (gensym "move-up?")
    1.27 -        move-down? (gensym "move-down?")
    1.28 -        roll-left? (gensym "roll-left?")
    1.29 -        roll-right? (gensym "roll-right?")
    1.30 -        directions [[0 1 0][0 -1 0][0 0 1][0 0 -1][-1 0 0][1 0 0]]
    1.31 -        symbols [move-left? move-right? move-up? move-down? 
    1.32 +          (merge keymap
    1.33 +                  {key
    1.34 +                   (fn [_ pressed?]
    1.35 +                     (reset! state pressed?))}))
    1.36 +        move-up? (atom false)
    1.37 +        move-down? (atom false)
    1.38 +        move-left? (atom false)
    1.39 +        move-right? (atom false)
    1.40 +        roll-left? (atom false)
    1.41 +        roll-right? (atom false)
    1.42 +        
    1.43 +        directions [(Vector3f. 0 1 0)(Vector3f. 0 -1 0)
    1.44 +                    (Vector3f. 0 0 1)(Vector3f. 0 0 -1)
    1.45 +                    (Vector3f. -1 0 0)(Vector3f. 1 0 0)]
    1.46 +        atoms [move-left? move-right? move-up? move-down? 
    1.47                   roll-left? roll-right?]
    1.48  
    1.49 -        keymap* (vec (map #(add-keypress %1 keymap %2)
    1.50 -                          symbols
    1.51 -                          keyboard))
    1.52 +        keymap* (reduce merge
    1.53 +                        (map #(add-keypress %1 keymap %2)
    1.54 +                             atoms
    1.55 +                             keyboard))
    1.56          
    1.57 -        splice-loop (map (fn [sym direction force]
    1.58 -                           `(if (deref ~sym)
    1.59 -                              (tap ~object
    1.60 -                                   (Vector3f. ~@direction)
    1.61 -                                   ~force)))
    1.62 -                         symbols directions forces)
    1.63 +        splice-loop (fn []
    1.64 +                      (dorun
    1.65 +                       (map
    1.66 +                        (fn [sym direction force]
    1.67 +                          (if @sym
    1.68 +                            (tap object direction force)))
    1.69 +                        atoms directions forces)))
    1.70  
    1.71 -        world-loop* `(fn [world# tpf#]
    1.72 -                       (~world-loop world# tpf#)
    1.73 -                       ~@splice-loop)]
    1.74 -  `(let [~move-up? (atom false)
    1.75 -         ~move-down? (atom false)
    1.76 -         ~move-left? (atom false)
    1.77 -         ~move-right? (atom false)
    1.78 -         ~roll-left? (atom false)
    1.79 -         ~roll-right? (atom false)]
    1.80 -     (~world-invocation
    1.81 -      ~root-node
    1.82 -      (reduce merge ~keymap*)
    1.83 -      ~intilization
    1.84 -      ~world-loop*))))
    1.85 +        world-loop* (fn [world tpf]
    1.86 +                       (world-loop world tpf)
    1.87 +                       (splice-loop))]
    1.88 +
    1.89 +     [root-node
    1.90 +      keymap*
    1.91 +      intilization
    1.92 +      world-loop*]))
    1.93  
    1.94  
    1.95  (defn test-proprioception
    1.96 @@ -427,15 +425,15 @@
    1.97          
    1.98          controls
    1.99          (merge standard-debug-controls
   1.100 -               {"key-y"
   1.101 +               {"key-o"
   1.102                  (fn [_ _] (.setEnabled finger-control true))
   1.103 -                "key-u"
   1.104 +                "key-p"
   1.105                  (fn [_ _] (.setEnabled finger-control false))
   1.106 +                "key-k"
   1.107 +                (fn [_ _] (.setEnabled hand-control true))
   1.108 +                "key-l"
   1.109 +                (fn [_ _] (.setEnabled hand-control false))
   1.110                  "key-i"
   1.111 -                (fn [_ _] (.setEnabled hand-control true))
   1.112 -                "key-o"
   1.113 -                (fn [_ _] (.setEnabled hand-control false))
   1.114 -                "key-q"
   1.115                  (fn [world _] (set-gravity world (Vector3f. 0 0 0)))
   1.116                  }
   1.117                 )
   1.118 @@ -446,27 +444,24 @@
   1.119         (.getControl hand RigidBodyControl)
   1.120         PhysicsCollisionObject/COLLISION_GROUP_NONE)
   1.121        )
   1.122 -    
   1.123 -    (with-movement
   1.124 -      hand
   1.125 -      ["key-w" "key-e" "key-s" "key-d" "key-x" "key-c"]
   1.126 -      [10 10 10 10 1 1]
   1.127 -      (with-movement
   1.128 -        finger
   1.129 -        ["key-r" "key-t" "key-f" "key-g" "key-v" "key-b"]
   1.130 -        [10 10 10 10 1 1]
   1.131 -        (world
   1.132 -         root
   1.133 -         controls
   1.134 -         (fn [world]
   1.135 -         (.setTimer world (com.aurellem.capture.RatchetTimer. 60))
   1.136 -         (set-gravity world (Vector3f. 0 0 0))
   1.137 -         (light-up-everything world))
   1.138 -         (fn [_ _] (prop-view (list (prop)))))))))
   1.139 +    (apply
   1.140 +     world
   1.141 +     (with-movement
   1.142 +       hand
   1.143 +       ["key-y" "key-u" "key-h" "key-j" "key-n" "key-m"]
   1.144 +       [10 10 10 10 1 1]
   1.145 +       (with-movement
   1.146 +         finger
   1.147 +         ["key-r" "key-t" "key-f" "key-g" "key-v" "key-b"]
   1.148 +         [10 10 10 10 1 1]
   1.149 +         [root
   1.150 +          controls
   1.151 +          (fn [world]
   1.152 +            (.setTimer world (com.aurellem.capture.RatchetTimer. 60))
   1.153 +            (set-gravity world (Vector3f. 0 0 0))
   1.154 +            (light-up-everything world))
   1.155 +          (fn [_ _] (prop-view (list (prop))))])))))
   1.156  
   1.157 -
   1.158 -
   1.159 -  
   1.160  #+end_src
   1.161  
   1.162  #+results: test-body