comparison org/test-creature.org @ 130:b26017d1fe9a

added workaround for problem with point2point joints in native bullet; added basic muscle description image.
author Robert McIntyre <rlm@mit.edu>
date Mon, 30 Jan 2012 05:47:51 -0700
parents bab47091534e
children 2ed7e60d3821
comparison
equal deleted inserted replaced
129:bab47091534e 130:b26017d1fe9a
319 (:type constraints))) 319 (:type constraints)))
320 320
321 (defmethod joint-dispatch :point 321 (defmethod joint-dispatch :point
322 [constraints control-a control-b pivot-a pivot-b rotation] 322 [constraints control-a control-b pivot-a pivot-b rotation]
323 (println-repl "creating POINT2POINT joint") 323 (println-repl "creating POINT2POINT joint")
324 (Point2PointJoint. 324 ;; bullet's point2point joints are BROKEN, so we must use the
325 control-a 325 ;; generic 6DOF joint instead of an actual Point2Point joint!
326 control-b 326
327 pivot-a 327 ;; should be able to do this:
328 pivot-b)) 328 (comment
329 (Point2PointJoint.
330 control-a
331 control-b
332 pivot-a
333 pivot-b))
334
335 ;; but instead we must do this:
336 (println-repl "substuting 6DOF joint for POINT2POINT joint!")
337 (doto
338 (SixDofJoint.
339 control-a
340 control-b
341 pivot-a
342 pivot-b
343 false)
344 (.setLinearLowerLimit Vector3f/ZERO)
345 (.setLinearUpperLimit Vector3f/ZERO)
346 ;;(.setAngularLowerLimit (Vector3f. 1 1 1))
347 ;;(.setAngularUpperLimit (Vector3f. 0 0 0))
348
349 ))
350
329 351
330 (defmethod joint-dispatch :hinge 352 (defmethod joint-dispatch :hinge
331 [constraints control-a control-b pivot-a pivot-b rotation] 353 [constraints control-a control-b pivot-a pivot-b rotation]
332 (println-repl "creating HINGE joint") 354 (println-repl "creating HINGE joint")
333 (let [axis 355 (let [axis
408 (joint-dispatch constraints 430 (joint-dispatch constraints
409 control-a control-b 431 control-a control-b
410 pivot-a pivot-b 432 pivot-a pivot-b
411 joint-rotation)) 433 joint-rotation))
412 (println-repl "could not find joint meta-data!")))) 434 (println-repl "could not find joint meta-data!"))))
435
436
437
413 438
414 (defn assemble-creature [#^Node pieces joints] 439 (defn assemble-creature [#^Node pieces joints]
415 (dorun 440 (dorun
416 (map 441 (map
417 (fn [geom] 442 (fn [geom]
1013 (defn gray-scale [num] 1038 (defn gray-scale [num]
1014 (+ num 1039 (+ num
1015 (bit-shift-left num 8) 1040 (bit-shift-left num 8)
1016 (bit-shift-left num 16))) 1041 (bit-shift-left num 16)))
1017 1042
1018 (defn debug-window 1043 (defn debug-touch-window
1019 "creates function that offers a debug view of sensor data" 1044 "creates function that offers a debug view of sensor data"
1020 [] 1045 []
1021 (let [vi (view-image)] 1046 (let [vi (view-image)]
1022 (fn 1047 (fn
1023 [[coords sensor-data]] 1048 [[coords sensor-data]]
1064 ;;(defn test-touch [world creature] 1089 ;;(defn test-touch [world creature]
1065 1090
1066 1091
1067 1092
1068 1093
1069 ;; here's how motor-control/ proprioception will work: 1094 ;; here's how motor-control/ proprioception will work: Each muscle is
1070 1095 ;; defined by a 1-D array of numbers (the "motor pool") each of which
1096 ;; represent muscle fibers. A muscle also has a scalar :strength
1097 ;; factor which determines how strong the muscle as a whole is.
1098 ;; The effector function for a muscle takes a number < (count
1099 ;; motor-pool) and that number is said to "activate" all the muscle
1100 ;; fibers whose index is lower than the number. Each fiber will apply
1101 ;; force in proportion to its value in the array. Lower values cause
1102 ;; less force. The lower values can be put at the "beginning" of the
1103 ;; 1-D array to simulate the layout of actual human muscles, which are
1104 ;; capable of more percise movements when exerting less force.
1105
1106 ;; I don't know how to encode proprioception, so for now, just return
1107 ;; a function for each joint that returns a triplet of floats which
1108 ;; represent relative roll, pitch, and yaw. Write display code for
1109 ;; this though.
1110
1111 (defn muscle-fibre-values
1112 "Take the first row of the image and return the low-order bytes."
1113 [#^BufferedImage image]
1114 (let [width (.getWidth image)]
1115 (for [x (range width)]
1116 (bit-and
1117 0xFF
1118 (.getRGB image x 0)))))
1119
1120
1121 (defn rad->deg [rad]
1122 (* 180 (/ Math/PI) rad))
1123
1124
1125 (defn debug-prop-window
1126 "create a debug view for proprioception"
1127 []
1128 (let [vi (view-image)]
1129 (fn [sensor-data]
1130 (println-repl
1131 (map
1132 (fn [[yaw pitch roll]]
1133 [(rad->deg yaw)
1134 (rad->deg pitch)
1135 (rad->deg roll)])
1136 sensor-data)))))
1071 1137
1072 1138
1073 1139
1074 1140
1075 1141
1081 (box 0.01 1 0.01 :physical? false :color ColorRGBA/Green) 1147 (box 0.01 1 0.01 :physical? false :color ColorRGBA/Green)
1082 z-axis 1148 z-axis
1083 (box 0.01 0.01 1 :physical? false :color ColorRGBA/Blue) 1149 (box 0.01 0.01 1 :physical? false :color ColorRGBA/Blue)
1084 creature (blender-creature thing) 1150 creature (blender-creature thing)
1085 touch-nerves (touch creature) 1151 touch-nerves (touch creature)
1086 touch-debug-windows (map (fn [_] (debug-window)) touch-nerves) 1152 touch-debug-windows (map (fn [_] (debug-touch-window)) touch-nerves)
1087 [init-vision-fns vision-data] (vision creature) 1153 [init-vision-fns vision-data] (vision creature)
1088 vision-debug (map (fn [_] (debug-vision-window)) vision-data) 1154 vision-debug (map (fn [_] (debug-vision-window)) vision-data)
1089 me (sphere 0.5 :color ColorRGBA/Blue :physical? false) 1155 me (sphere 0.5 :color ColorRGBA/Blue :physical? false)
1090 [init-hearing-fns hearing-senses] (hearing creature) 1156 [init-hearing-fns hearing-senses] (hearing creature)
1091 hearing-windows (map (fn [_] (debug-hearing-window 50)) 1157 hearing-windows (map (fn [_] (debug-hearing-window 50))
1092 hearing-senses) 1158 hearing-senses)
1093 bell (AudioNode. (asset-manager) 1159 bell (AudioNode. (asset-manager)
1094 "Sounds/pure.wav" false) 1160 "Sounds/pure.wav" false)
1161 prop (proprioception creature)
1162 prop-debug (debug-prop-window)
1095 ;; dream 1163 ;; dream
1096 1164
1097 ] 1165 ]
1098 (world 1166 (world
1099 (nodify [creature 1167 (nodify [creature
1129 ) 1197 )
1130 (fn [world tpf] 1198 (fn [world tpf]
1131 ;;(dorun 1199 ;;(dorun
1132 ;; (map #(%1 %2) touch-nerves (repeat (.getRootNode world)))) 1200 ;; (map #(%1 %2) touch-nerves (repeat (.getRootNode world))))
1133 1201
1134 1202 (prop-debug (prop))
1135 1203
1136 (dorun 1204 (dorun
1137 (map #(%1 (%2 (.getRootNode world))) 1205 (map #(%1 (%2 (.getRootNode world)))
1138 touch-debug-windows touch-nerves)) 1206 touch-debug-windows touch-nerves))
1139 1207
1199 ;;node (nodify (conj collision-points obj-b)) 1267 ;;node (nodify (conj collision-points obj-b))
1200 1268
1201 sim 1269 sim
1202 (world node 1270 (world node
1203 {"key-space" 1271 {"key-space"
1204 vvvvvv (fn [_ value] 1272 (fn [_ value]
1205 (if value 1273 (if value
1206 (let [cr (CollisionResults.)] 1274 (let [cr (CollisionResults.)]
1207 (.collideWith node bounds-b cr) 1275 (.collideWith node bounds-b cr)
1208 (println-repl (map #(.getContactPoint %) cr)) 1276 (println-repl (map #(.getContactPoint %) cr))
1209 cr)))} 1277 cr)))}