Mercurial > cortex
comparison org/test-creature.org @ 147:72801a20b8e5
First stab at blender muscles. (gee that sounds a little violent...)
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Fri, 03 Feb 2012 00:48:34 -0700 |
parents | 68226790d1fa |
children | 511112c44b16 |
comparison
equal
deleted
inserted
replaced
146:68226790d1fa | 147:72801a20b8e5 |
---|---|
78 appropiate -- 1/2 day | 78 appropiate -- 1/2 day |
79 - [ ] muscle control -- day | 79 - [ ] muscle control -- day |
80 - [X] proprioception sensor map in the style of the other senses -- day | 80 - [X] proprioception sensor map in the style of the other senses -- day |
81 - [ ] refactor integration code to distribute to each of the senses | 81 - [ ] refactor integration code to distribute to each of the senses |
82 -- day | 82 -- day |
83 - [ ] create video showing all the senses for Winston -- 2 days | 83 - [ ] create video showing all the senses for Winston -- 2 days |
84 - [ ] send package to friends for critiques -- 2 days | |
84 - [ ] write summary of project for Winston \ | 85 - [ ] write summary of project for Winston \ |
85 - [ ] project proposals for Winston \ | 86 - [ ] project proposals for Winston \ |
86 - [ ] additional senses to be implemented for Winston | -- 2 days | 87 - [ ] additional senses to be implemented for Winston | -- 2 days |
87 - [ ] send Winston package / | 88 - [ ] send Winston package / |
88 | 89 |
1075 ;; I don't know how to encode proprioception, so for now, just return | 1076 ;; I don't know how to encode proprioception, so for now, just return |
1076 ;; a function for each joint that returns a triplet of floats which | 1077 ;; a function for each joint that returns a triplet of floats which |
1077 ;; represent relative roll, pitch, and yaw. Write display code for | 1078 ;; represent relative roll, pitch, and yaw. Write display code for |
1078 ;; this though. | 1079 ;; this though. |
1079 | 1080 |
1080 (defn muscle-fibre-values | 1081 (defn muscle-fiber-values |
1081 "Take the first row of the image and return the low-order bytes." | 1082 "get motor pool strengths" |
1082 [#^BufferedImage image] | 1083 [#^BufferedImage image] |
1083 (let [width (.getWidth image)] | 1084 (vec |
1084 (for [x (range width)] | 1085 (let [width (.getWidth image)] |
1085 (bit-and | 1086 (for [x (range width)] |
1086 0xFF | 1087 (- 255 |
1087 (.getRGB image x 0))))) | 1088 (bit-and |
1089 0x0000FF | |
1090 (.getRGB image x 0))))))) | |
1091 | |
1092 | |
1093 (defn creature-muscles | |
1094 "Return the children of the creature's \"muscles\" node." | |
1095 [#^Node creature] | |
1096 (if-let [muscle-node (.getChild creature "muscles")] | |
1097 (seq (.getChildren muscle-node)) | |
1098 (do (println-repl "could not find muscles node") []))) | |
1099 | |
1100 (defn single-muscle [#^Node parts #^Node muscle] | |
1101 (let [target (closest-node parts muscle) | |
1102 axis | |
1103 (.mult (.getWorldRotation muscle) Vector3f/UNIT_Y) | |
1104 strength (meta-data muscle "strength") | |
1105 image-name (read-string (meta-data muscle "muscle")) | |
1106 image | |
1107 (ImageToAwt/convert | |
1108 (.getImage (.loadTexture (asset-manager) image-name)) | |
1109 false false 0) | |
1110 fibers (muscle-fiber-values image) | |
1111 fiber-integral (reductions + fibers) | |
1112 force-index (vec | |
1113 (map | |
1114 #(float (* strength (/ % (last | |
1115 fiber-integral)))) | |
1116 fiber-integral)) | |
1117 control (.getControl target RigidBodyControl)] | |
1118 (fn [n] | |
1119 (let [pool-index (min n (count fibers))] | |
1120 (.applyTorque control (force-index n)))))) | |
1121 | |
1122 | |
1123 (defn enable-muscles | |
1124 "Must be called on a creature after RigidBodyControls have been | |
1125 created." | |
1126 [#^Node creature] | |
1127 (let [muscles (creature-muscles creature)] | |
1128 (for [muscle muscles] | |
1129 (single-muscle creature muscle)))) | |
1088 | 1130 |
1089 (defn test-creature [thing] | 1131 (defn test-creature [thing] |
1090 (let [x-axis | 1132 (let [x-axis |
1091 (box 1 0.01 0.01 :physical? false :color ColorRGBA/Red) | 1133 (box 1 0.01 0.01 :physical? false :color ColorRGBA/Red) |
1092 y-axis | 1134 y-axis |