changeset 137:39c89ae5c7d0

saving progress
author Robert McIntyre <rlm@mit.edu>
date Wed, 01 Feb 2012 23:46:31 -0700
parents 47a4d74761f0
children 16bdf9e80daf
files assets/Models/creature1/try-again.blend org/body.org
diffstat 2 files changed, 107 insertions(+), 60 deletions(-) [+]
line wrap: on
line diff
     1.1 Binary file assets/Models/creature1/try-again.blend has changed
     2.1 --- a/org/body.org	Wed Feb 01 17:39:23 2012 -0700
     2.2 +++ b/org/body.org	Wed Feb 01 23:46:31 2012 -0700
     2.3 @@ -66,9 +66,13 @@
     2.4  (defn joint-proprioception [#^Node parts #^Node joint]
     2.5    (let [[obj-a obj-b] (joint-targets parts joint)
     2.6          joint-rot (.getWorldRotation joint)
     2.7 -        x (.mult joint-rot Vector3f/UNIT_X)
     2.8 -        y (.mult joint-rot Vector3f/UNIT_Y)
     2.9 -        z (.mult joint-rot Vector3f/UNIT_Z)]
    2.10 +        pre-inv-a (.inverse (.getWorldRotation obj-a))
    2.11 +        x (.mult pre-inv-a (.mult joint-rot Vector3f/UNIT_X))
    2.12 +        y (.mult pre-inv-a (.mult joint-rot Vector3f/UNIT_Y))
    2.13 +        z (.mult pre-inv-a (.mult joint-rot Vector3f/UNIT_Z))]
    2.14 +    (println-repl "x:" x)
    2.15 +    (println-repl "y:" y)
    2.16 +    (println-repl "z:" z)
    2.17      ;; this function will report proprioceptive information for the
    2.18      ;; joint.
    2.19      (fn []
    2.20 @@ -341,6 +345,64 @@
    2.21  
    2.22  
    2.23  
    2.24 +(defmacro with-movement
    2.25 +  [object
    2.26 +   [up down left right roll-up roll-down :as keyboard]
    2.27 +   forces
    2.28 +   [world-invocation
    2.29 +    root-node
    2.30 +    keymap
    2.31 +    intilization
    2.32 +    world-loop]]
    2.33 +  (let [add-keypress
    2.34 +        (fn [state keymap key]
    2.35 +          `(merge ~keymap
    2.36 +                  {~key
    2.37 +                   (fn [_ pressed?#]
    2.38 +                     (reset! ~state pressed?#))}))
    2.39 +        move-left? (gensym "move-left?")
    2.40 +        move-right? (gensym "move-right?")
    2.41 +        move-up? (gensym "move-up?")
    2.42 +        move-down? (gensym "move-down?")
    2.43 +        roll-left? (gensym "roll-left?")
    2.44 +        roll-right? (gensym "roll-right?")
    2.45 +        directions
    2.46 +        [(Vector3f. 0 1 0)
    2.47 +         (Vector3f. 0 -1 0)
    2.48 +         (Vector3f. 0 0 1)
    2.49 +         (Vector3f. 0 0 -1)
    2.50 +         (Vector3f. -1 0 0)
    2.51 +         (Vector3f. 1 0 0)]
    2.52 +        symbols [move-left? move-right? move-up? move-down? 
    2.53 +                 roll-left? roll-right?]
    2.54 +
    2.55 +        keymap* (vec (map #(add-keypress %1 keymap %2)
    2.56 +                          symbols
    2.57 +                          keyboard))
    2.58 +        
    2.59 +        splice-loop (map (fn [sym force direction]
    2.60 +                           `(if (deref ~sym)
    2.61 +                              (tap ~object ~direction ~force)))
    2.62 +                         symbols directions forces)
    2.63 +
    2.64 +        world-loop* `(fn [world# tpf#]
    2.65 +                       (~world-loop world# tpf#)
    2.66 +                       ~@splice-loop)]
    2.67 +        
    2.68 +  `(let [~move-up? (atom false)
    2.69 +         ~move-down? (atom false)
    2.70 +         ~move-left? (atom false)
    2.71 +         ~move-right? (atom false)
    2.72 +         ~roll-left? (atom false)
    2.73 +         ~roll-right? (atom false)]
    2.74 +     (~world-invocation
    2.75 +      ~root-node
    2.76 +      (reduce merge ~keymap*)
    2.77 +      ~intilization
    2.78 +      ~world-loop*)
    2.79 +  )))
    2.80 +
    2.81 +
    2.82  (defn test-proprioception
    2.83    "Testing proprioception:
    2.84     You should see two foating bars, and a printout of pitch, yaw, and
    2.85 @@ -359,23 +421,10 @@
    2.86          joint (join-at-point hand finger (Vector3f. 1.2 2 0 ))
    2.87          creature (nodify [hand finger joint-node])
    2.88          ;; *******************************************
    2.89 -        rot (doto (Quaternion.)
    2.90 -               (.fromAngleAxis (/ Math/PI 4)
    2.91 -                               (Vector3f. 0 0 -1)))
    2.92 -        hand2 (box 1 0.2 0.2 :position (Vector3f. 0 1.5 -3)
    2.93 -                  :mass 0 :color ColorRGBA/Blue :rotation rot)
    2.94 -        finger2 (box 1 0.2 0.2 :position (Vector3f. 2.4 1.5 -3)
    2.95 -                    :mass 1 :color ColorRGBA/Magenta :rotation rot)
    2.96 -        joint-node2 (box 0.1 0.05 0.05 :color ColorRGBA/Gray
    2.97 -                        :position (Vector3f. 1.2 1.5 -3)
    2.98 -                        :physical? false :rotation rot)
    2.99 -        joint2 (join-at-point hand2 finger2 (Vector3f. 1.2 1.5 -3))
   2.100 -        creature2 (nodify [hand2 finger2 joint-node2])
   2.101 -        ;; *******************************************
   2.102 -        
   2.103 +                
   2.104          floor   (box 10 10 10 :position (Vector3f. 0 -15 0)
   2.105                       :mass 0 :color ColorRGBA/Gray)
   2.106 -
   2.107 +        
   2.108          move-up? (atom false)
   2.109          move-down? (atom false)
   2.110          move-left? (atom false)
   2.111 @@ -384,7 +433,7 @@
   2.112          roll-right? (atom false)
   2.113         
   2.114  
   2.115 -        root (nodify [creature creature2 floor])
   2.116 +        root (nodify [creature floor])
   2.117          prop (joint-proprioception creature joint-node)
   2.118          prop-view (proprioception-debug-window)]
   2.119               
   2.120 @@ -393,48 +442,46 @@
   2.121      (.setCollisionGroup
   2.122       (.getControl hand RigidBodyControl)
   2.123       PhysicsCollisionObject/COLLISION_GROUP_NONE)
   2.124 -    (.setCollisionGroup
   2.125 -     (.getControl hand2 RigidBodyControl)
   2.126 -     PhysicsCollisionObject/COLLISION_GROUP_NONE)
   2.127  
   2.128 -    
   2.129 -
   2.130 -    
   2.131 -    (world
   2.132 -     root
   2.133 -     (merge standard-debug-controls
   2.134 -            {"key-r" (fn [_ pressed?] (reset! move-up? pressed?))
   2.135 -             "key-t" (fn [_ pressed?] (reset! move-down? pressed?))
   2.136 -             "key-f" (fn [_ pressed?] (reset! move-left? pressed?))
   2.137 -             "key-g" (fn [_ pressed?] (reset! move-right? pressed?))
   2.138 -             "key-v" (fn [_ pressed?] (reset! roll-left? pressed?))
   2.139 -             "key-b" (fn [_ pressed?] (reset! roll-right? pressed?))})     
   2.140 -     (fn [world]
   2.141 -       (.setTimer world (com.aurellem.capture.RatchetTimer. 60))
   2.142 -       (set-gravity world (Vector3f. 0 0 0))
   2.143 -       (light-up-everything world))
   2.144 -     (fn [_ _]
   2.145 -       (let [force 10
   2.146 -             left (Vector3f. 0 1 0)
   2.147 -             right (Vector3f. 0 -1 0)
   2.148 -             up (Vector3f. 0 0 1)
   2.149 -             down (Vector3f. 0 0 -1)
   2.150 -             roll-left (Vector3f. -1 0 0)
   2.151 -             roll-right (Vector3f. 1 0 0)]
   2.152 -         (if @move-up? (do (tap finger up force)
   2.153 -                           (tap finger2 up force)))
   2.154 -         (if @move-down? (do (tap finger down force)
   2.155 -                             (tap finger2 down force)))
   2.156 -         (if @move-left? (do (tap finger left force)
   2.157 -                             (tap finger2 left force)))
   2.158 -         (if @move-right? (do (tap finger right force)
   2.159 -                              (tap finger2 right force)))
   2.160 -         (if @roll-left? (do (tap finger roll-left (/ force 10))
   2.161 -                             (tap finger2 roll-left (/ force 10))))
   2.162 -         (if @roll-right? (do (tap finger roll-right (/ force 10))
   2.163 -                              (tap finger2 roll-right (/ force 10)))))
   2.164 -       (prop-view (list (prop)))))))
   2.165 -
   2.166 +    (with-movement
   2.167 +      finger
   2.168 +      ["key-r" "key-t" "key-f" "key-g" "key-v" "key-b"]
   2.169 +      [10 10 10 10 1 1]
   2.170 +      (world
   2.171 +       root
   2.172 +       (merge standard-debug-controls
   2.173 +              {"key-r" (fn [_ pressed?] (reset! move-up? pressed?))
   2.174 +               "key-t" (fn [_ pressed?] (reset! move-down? pressed?))
   2.175 +               "key-f" (fn [_ pressed?] (reset! move-left? pressed?))
   2.176 +               "key-g" (fn [_ pressed?] (reset! move-right? pressed?))
   2.177 +               "key-v" (fn [_ pressed?] (reset! roll-left? pressed?))
   2.178 +               "key-b" (fn [_ pressed?] (reset! roll-right? pressed?))})     
   2.179 +       (fn [world]
   2.180 +         (.setTimer world (com.aurellem.capture.RatchetTimer. 60))
   2.181 +         (set-gravity world (Vector3f. 0 0 0))
   2.182 +         (light-up-everything world))
   2.183 +       (fn [_ _]
   2.184 +         (let [force 10
   2.185 +               left (Vector3f. 0 1 0)
   2.186 +               right (Vector3f. 0 -1 0)
   2.187 +               up (Vector3f. 0 0 1)
   2.188 +               down (Vector3f. 0 0 -1)
   2.189 +               roll-left (Vector3f. -1 0 0)
   2.190 +               roll-right (Vector3f. 1 0 0)]
   2.191 +           (if @move-up?  (tap finger up force))
   2.192 +           
   2.193 +           (if @move-down?  (tap finger down force))
   2.194 +           
   2.195 +           (if @move-left?  (tap finger left force))
   2.196 +           
   2.197 +           (if @move-right?  (tap finger right force))
   2.198 +           
   2.199 +           (if @roll-left?  (tap finger roll-left (/ force 10)))
   2.200 +           
   2.201 +           (if @roll-right?  (tap finger roll-right (/ force 10))))
   2.202 +         
   2.203 +         (prop-view (list (prop))))))))
   2.204 +  
   2.205  #+end_src
   2.206  
   2.207  #+results: test-body