diff org/worm_learn.clj @ 449:09b7c8dd4365

first chapter done, half of last chapter done.
author Robert McIntyre <rlm@mit.edu>
date Wed, 26 Mar 2014 02:42:01 -0400
parents 47cfbe84f00e
children 0a4362d1f138
line wrap: on
line diff
     1.1 --- a/org/worm_learn.clj	Tue Mar 25 22:54:41 2014 -0400
     1.2 +++ b/org/worm_learn.clj	Wed Mar 26 02:42:01 2014 -0400
     1.3 @@ -27,6 +27,13 @@
     1.4  (defn worm-model []
     1.5    (load-blender-model "Models/worm/worm.blend"))
     1.6  
     1.7 +(defn worm []
     1.8 +  (let [model (load-blender-model "Models/worm/worm.blend")]
     1.9 +    {:body (doto model (body!))
    1.10 +     :touch (touch! model)
    1.11 +     :proprioception (proprioception! model)
    1.12 +     :muscles (movement! model)}))
    1.13 +
    1.14  (def output-base (File. "/home/r/proj/cortex/render/worm-learn/curl"))
    1.15  
    1.16  
    1.17 @@ -220,15 +227,8 @@
    1.18                (< 0.55 (contact worm-segment-top-tip    head-touch))))))
    1.19  
    1.20  
    1.21 -(declare phi-space phi-scan)
    1.22 +(declare phi-space phi-scan debug-experience) 
    1.23  
    1.24 -(defn debug-experience
    1.25 -  [experiences text]
    1.26 -  (cond
    1.27 -   (grand-circle? experiences) (.setText text "Grand Circle")
    1.28 -   (curled? experiences)       (.setText text "Curled")
    1.29 -   (wiggling? experiences)     (.setText text "Wiggling")
    1.30 -   (resting? experiences)      (.setText text "Resting")))
    1.31  
    1.32  
    1.33  (def standard-world-view
    1.34 @@ -277,16 +277,14 @@
    1.35            (.setFilterMode  PssmShadowRenderer$FilterMode/Bilinear))]
    1.36      (.addProcessor (.getViewPort world) pssm)))
    1.37          
    1.38 +(defn debug-experience
    1.39 +  [experiences text]
    1.40 +  (cond
    1.41 +   (grand-circle? experiences) (.setText text "Grand Circle")
    1.42 +   (curled? experiences)       (.setText text "Curled")
    1.43 +   (wiggling? experiences)     (.setText text "Wiggling")
    1.44 +   (resting? experiences)      (.setText text "Resting")))
    1.45  
    1.46 -(defn display-text [[x y :as location]]
    1.47 -  (let []
    1.48 -    (.setLocalTranslation text 300 (.getLineHeight text) 0)
    1.49 -   (fn [world]
    1.50 -     
    1.51 -  
    1.52 -  
    1.53 -  
    1.54 -  (fn [new-text]
    1.55  
    1.56  (defn worm-world
    1.57    [& {:keys [record motor-control keybindings view experiences
    1.58 @@ -294,14 +292,11 @@
    1.59    (let [{:keys [record motor-control keybindings view experiences
    1.60                  worm-model end-frame experience-watch]}
    1.61          (merge (worm-world-defaults) settings)
    1.62 -        worm (doto (worm-model) (body!))
    1.63 -        touch   (touch! worm)
    1.64 -        prop    (proprioception! worm)
    1.65 -        muscles (movement! worm)
    1.66 -        
    1.67 +       
    1.68          touch-display  (view-touch)
    1.69          prop-display   (view-proprioception)
    1.70          muscle-display (view-movement)
    1.71 +        {:keys [proprioception touch muscles body]} (worm)
    1.72          
    1.73          floor
    1.74          (box 5 1 5 :position (Vector3f. 0 -10 0)
    1.75 @@ -316,7 +311,7 @@
    1.76                        (.setColor (ColorRGBA/Black)))]
    1.77  
    1.78      (world
    1.79 -     (nodify [worm floor])
    1.80 +     (nodify [body floor])
    1.81         (merge standard-debug-controls keybindings)
    1.82         (fn [world]
    1.83           (.setLocalTranslation
    1.84 @@ -324,7 +319,7 @@
    1.85           (.attachChild (.getGuiNode world) worm-action)
    1.86           
    1.87           (enable-good-shadows world)
    1.88 -         (.setShadowMode worm RenderQueue$ShadowMode/CastAndReceive)
    1.89 +         (.setShadowMode body RenderQueue$ShadowMode/CastAndReceive)
    1.90           (.setShadowMode floor RenderQueue$ShadowMode/Receive)
    1.91                    
    1.92           (.setBackgroundColor (.getViewPort world) (ColorRGBA/White))
    1.93 @@ -332,7 +327,7 @@
    1.94           (.setDisplayFps world false)
    1.95           (position-camera world view)
    1.96           (.setTimer world timer)
    1.97 -         (display-dilated-time world timer)
    1.98 +         ;;(display-dilated-time world timer)
    1.99           (when record
   1.100             (dir! record)
   1.101             (Capture/captureVideo
   1.102 @@ -345,7 +340,7 @@
   1.103           (if (and end-frame (> (.getTime timer) end-frame))
   1.104             (.stop world))
   1.105           (let [muscle-data (vec (motor-control muscles))
   1.106 -               proprioception-data (prop)
   1.107 +               proprioception-data (proprioception)
   1.108                 touch-data (mapv #(% (.getRootNode world)) touch)]
   1.109             (when experiences
   1.110               (record-experience!