# HG changeset patch # User Robert McIntyre # Date 1328378539 25200 # Node ID 66fbab414d45bf1d186a2ad15e55dccbf15d6395 # Parent 2902aca33c6e567d8849169620908f00f53889ef added muscle exertion debug view. diff -r 2902aca33c6e -r 66fbab414d45 org/movement.org --- a/org/movement.org Sat Feb 04 10:26:11 2012 -0700 +++ b/org/movement.org Sat Feb 04 11:02:19 2012 -0700 @@ -58,8 +58,9 @@ (defn movement-fn "Returns a function which when called with a integer value inside a - running simulation, will cause movement in the creature according - to the muscle's position and strength profile" + running simulation will cause movement in the creature according + to the muscle's position and strength profile. Each function + returns the amount of force applied / max force." [#^Node parts #^Node muscle] (let [target (closest-node parts muscle) axis @@ -69,15 +70,16 @@ image (load-image image-name) fibers (muscle-profile image) fiber-integral (reductions + fibers) - force-index (vec - (map - #(float (* strength (/ % (last - fiber-integral)))) - fiber-integral)) + force-index + (vec (map #(float (* strength (/ % (last fiber-integral)))) + fiber-integral)) control (.getControl target RigidBodyControl)] (fn [n] - (let [pool-index (min n (count fibers))] - (.applyTorque control (.mult axis (force-index n))))))) + (let [pool-index (max 0 (min n (dec (count fibers)))) + force (force-index pool-index)] + (.applyTorque control (.mult axis force)) + (float (/ force strength)))))) + (defn movement! "Endow the creature with the power of movement. Returns a sequence @@ -87,6 +89,26 @@ (for [muscle (muscles creature)] (movement-fn creature muscle))) +(defn movement-display-kernel + "Display muscle exertion data as a bar filling up with red." + [exertion] + (let [height 20 + width 300 + image (BufferedImage. width height + BufferedImage/TYPE_INT_RGB) + fill (min (int (* width exertion)) width)] + (dorun + (for [x (range fill) + y (range height)] + (.setRGB image x y 0xFF0000))) + image)) + +(defn view-movement + "Creates a function which accepts a list of muscle-exertion data and + displays each element of the list to the screen." + [] + (view-sense movement-display-kernel)) + #+end_src diff -r 2902aca33c6e -r 66fbab414d45 org/test-creature.org --- a/org/test-creature.org Sat Feb 04 10:26:11 2012 -0700 +++ b/org/test-creature.org Sat Feb 04 11:02:19 2012 -0700 @@ -147,8 +147,9 @@ prop (proprioception! creature) prop-display (view-proprioception) - muscle-fns (movement! creature) - + muscle-exertion (atom 0) + muscles (movement! creature) + muscle-display (view-movement) me (sphere 0.5 :color ColorRGBA/Blue :physical? false) bell (AudioNode. (asset-manager) @@ -183,9 +184,11 @@ "key-h" (fn [_ value] (if value - (do - (println-repl "muscle activating!") - ((first muscle-fns) 199)))) + (swap! muscle-exertion (partial + 20)))) + "key-n" + (fn [_ value] + (if value + (swap! muscle-exertion (fn [v] (- v 20))))) }) (fn [world] @@ -217,6 +220,8 @@ (vision-display (map #(% world) vision)) (hearing-display (map #(% world) hearing)) + + (muscle-display (map #(% @muscle-exertion) muscles)) ;;(println-repl (vision-data)) (.setLocalTranslation me (.getLocation (.getCamera world)))