Mercurial > cortex
changeset 191:66fbab414d45
added muscle exertion debug view.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 04 Feb 2012 11:02:19 -0700 |
parents | 2902aca33c6e |
children | deac7b708750 |
files | org/movement.org org/test-creature.org |
diffstat | 2 files changed, 41 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
1.1 --- a/org/movement.org Sat Feb 04 10:26:11 2012 -0700 1.2 +++ b/org/movement.org Sat Feb 04 11:02:19 2012 -0700 1.3 @@ -58,8 +58,9 @@ 1.4 1.5 (defn movement-fn 1.6 "Returns a function which when called with a integer value inside a 1.7 - running simulation, will cause movement in the creature according 1.8 - to the muscle's position and strength profile" 1.9 + running simulation will cause movement in the creature according 1.10 + to the muscle's position and strength profile. Each function 1.11 + returns the amount of force applied / max force." 1.12 [#^Node parts #^Node muscle] 1.13 (let [target (closest-node parts muscle) 1.14 axis 1.15 @@ -69,15 +70,16 @@ 1.16 image (load-image image-name) 1.17 fibers (muscle-profile image) 1.18 fiber-integral (reductions + fibers) 1.19 - force-index (vec 1.20 - (map 1.21 - #(float (* strength (/ % (last 1.22 - fiber-integral)))) 1.23 - fiber-integral)) 1.24 + force-index 1.25 + (vec (map #(float (* strength (/ % (last fiber-integral)))) 1.26 + fiber-integral)) 1.27 control (.getControl target RigidBodyControl)] 1.28 (fn [n] 1.29 - (let [pool-index (min n (count fibers))] 1.30 - (.applyTorque control (.mult axis (force-index n))))))) 1.31 + (let [pool-index (max 0 (min n (dec (count fibers)))) 1.32 + force (force-index pool-index)] 1.33 + (.applyTorque control (.mult axis force)) 1.34 + (float (/ force strength)))))) 1.35 + 1.36 1.37 (defn movement! 1.38 "Endow the creature with the power of movement. Returns a sequence 1.39 @@ -87,6 +89,26 @@ 1.40 (for [muscle (muscles creature)] 1.41 (movement-fn creature muscle))) 1.42 1.43 +(defn movement-display-kernel 1.44 + "Display muscle exertion data as a bar filling up with red." 1.45 + [exertion] 1.46 + (let [height 20 1.47 + width 300 1.48 + image (BufferedImage. width height 1.49 + BufferedImage/TYPE_INT_RGB) 1.50 + fill (min (int (* width exertion)) width)] 1.51 + (dorun 1.52 + (for [x (range fill) 1.53 + y (range height)] 1.54 + (.setRGB image x y 0xFF0000))) 1.55 + image)) 1.56 + 1.57 +(defn view-movement 1.58 + "Creates a function which accepts a list of muscle-exertion data and 1.59 + displays each element of the list to the screen." 1.60 + [] 1.61 + (view-sense movement-display-kernel)) 1.62 + 1.63 #+end_src 1.64 1.65
2.1 --- a/org/test-creature.org Sat Feb 04 10:26:11 2012 -0700 2.2 +++ b/org/test-creature.org Sat Feb 04 11:02:19 2012 -0700 2.3 @@ -147,8 +147,9 @@ 2.4 prop (proprioception! creature) 2.5 prop-display (view-proprioception) 2.6 2.7 - muscle-fns (movement! creature) 2.8 - 2.9 + muscle-exertion (atom 0) 2.10 + muscles (movement! creature) 2.11 + muscle-display (view-movement) 2.12 2.13 me (sphere 0.5 :color ColorRGBA/Blue :physical? false) 2.14 bell (AudioNode. (asset-manager) 2.15 @@ -183,9 +184,11 @@ 2.16 "key-h" 2.17 (fn [_ value] 2.18 (if value 2.19 - (do 2.20 - (println-repl "muscle activating!") 2.21 - ((first muscle-fns) 199)))) 2.22 + (swap! muscle-exertion (partial + 20)))) 2.23 + "key-n" 2.24 + (fn [_ value] 2.25 + (if value 2.26 + (swap! muscle-exertion (fn [v] (- v 20))))) 2.27 2.28 }) 2.29 (fn [world] 2.30 @@ -217,6 +220,8 @@ 2.31 (vision-display (map #(% world) vision)) 2.32 2.33 (hearing-display (map #(% world) hearing)) 2.34 + 2.35 + (muscle-display (map #(% @muscle-exertion) muscles)) 2.36 2.37 ;;(println-repl (vision-data)) 2.38 (.setLocalTranslation me (.getLocation (.getCamera world)))