Mercurial > cortex
diff org/test-creature.org @ 158:811127d79d24
refactored muscles
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Fri, 03 Feb 2012 06:33:37 -0700 |
parents | 84c67be00abe |
children | 75b6c2ebbf8e |
line wrap: on
line diff
1.1 --- a/org/test-creature.org Fri Feb 03 06:21:39 2012 -0700 1.2 +++ b/org/test-creature.org Fri Feb 03 06:33:37 2012 -0700 1.3 @@ -38,7 +38,7 @@ 1.4 the connecting here in clojure code, using the names of the individual 1.5 components and trial and error. Later, I'll maybe make some sort of 1.6 creature-building modifications to blender that support whatever 1.7 -discreitized senses I'm going to make. 1.8 +discritized senses I'm going to make. 1.9 1.10 #+name: body-1 1.11 #+begin_src clojure 1.12 @@ -49,7 +49,8 @@ 1.13 ;; TODO remove this! 1.14 (require 'cortex.import) 1.15 (cortex.import/mega-import-jme3) 1.16 -(use '(cortex world util body hearing touch vision sense proprioception)) 1.17 +(use '(cortex world util body hearing touch vision sense 1.18 +proprioception movement)) 1.19 1.20 (rlm.rlm-commands/help) 1.21 (import java.awt.image.BufferedImage) 1.22 @@ -421,72 +422,6 @@ 1.23 1.24 1.25 1.26 -;; here's how motor-control/ proprioception will work: Each muscle is 1.27 -;; defined by a 1-D array of numbers (the "motor pool") each of which 1.28 -;; represent muscle fibers. A muscle also has a scalar :strength 1.29 -;; factor which determines how strong the muscle as a whole is. 1.30 -;; The effector function for a muscle takes a number < (count 1.31 -;; motor-pool) and that number is said to "activate" all the muscle 1.32 -;; fibers whose index is lower than the number. Each fiber will apply 1.33 -;; force in proportion to its value in the array. Lower values cause 1.34 -;; less force. The lower values can be put at the "beginning" of the 1.35 -;; 1-D array to simulate the layout of actual human muscles, which are 1.36 -;; capable of more percise movements when exerting less force. 1.37 - 1.38 -;; I don't know how to encode proprioception, so for now, just return 1.39 -;; a function for each joint that returns a triplet of floats which 1.40 -;; represent relative roll, pitch, and yaw. Write display code for 1.41 -;; this though. 1.42 - 1.43 -(defn muscle-fiber-values 1.44 - "get motor pool strengths" 1.45 - [#^BufferedImage image] 1.46 - (vec 1.47 - (let [width (.getWidth image)] 1.48 - (for [x (range width)] 1.49 - (- 255 1.50 - (bit-and 1.51 - 0x0000FF 1.52 - (.getRGB image x 0))))))) 1.53 - 1.54 - 1.55 -(defn creature-muscles 1.56 - "Return the children of the creature's \"muscles\" node." 1.57 - [#^Node creature] 1.58 - (if-let [muscle-node (.getChild creature "muscles")] 1.59 - (seq (.getChildren muscle-node)) 1.60 - (do (println-repl "could not find muscles node") []))) 1.61 - 1.62 -(defn single-muscle [#^Node parts #^Node muscle] 1.63 - (let [target (closest-node parts muscle) 1.64 - axis 1.65 - (.mult (.getWorldRotation muscle) Vector3f/UNIT_Y) 1.66 - strength (meta-data muscle "strength") 1.67 - image-name (read-string (meta-data muscle "muscle")) 1.68 - image 1.69 - (ImageToAwt/convert 1.70 - (.getImage (.loadTexture (asset-manager) image-name)) 1.71 - false false 0) 1.72 - fibers (muscle-fiber-values image) 1.73 - fiber-integral (reductions + fibers) 1.74 - force-index (vec 1.75 - (map 1.76 - #(float (* strength (/ % (last 1.77 - fiber-integral)))) 1.78 - fiber-integral)) 1.79 - control (.getControl target RigidBodyControl)] 1.80 - (fn [n] 1.81 - (let [pool-index (min n (count fibers))] 1.82 - (.applyTorque control (.mult axis (force-index n))))))) 1.83 - 1.84 - 1.85 -(defn enable-muscles 1.86 - "Must be called on a creature after RigidBodyControls have been 1.87 - created." 1.88 - [#^Node creature] 1.89 - (let [muscles (creature-muscles creature)] 1.90 - (for [muscle muscles] 1.91 - (single-muscle creature muscle)))) 1.92 1.93 (defn test-creature [thing] 1.94 (let [x-axis