annotate org/integration.org @ 298:85f3ff3e3f26

still working on video generation
author Robert McIntyre <rlm@mit.edu>
date Thu, 16 Feb 2012 20:05:54 -0700
parents d1206b11ae2d
children 47fe4f7b74b3
rev   line source
rlm@281 1 #+title:
rlm@73 2 #+author: Robert McIntyre
rlm@73 3 #+email: rlm@mit.edu
rlm@73 4 #+description:
rlm@73 5 #+keywords: simulation, jMonkeyEngine3, clojure
rlm@73 6 #+SETUPFILE: ../../aurellem/org/setup.org
rlm@73 7 #+INCLUDE: ../../aurellem/org/level-0.org
rlm@73 8
rlm@281 9 * Intro
rlm@129 10
rlm@281 11 This is the ultimate test which features all of the senses that I've
rlm@281 12 made so far. The blender file for the creature serves as an example of
rlm@281 13 a fully equipped creature in terms of senses. You can find it [[../assets/Models/test-creature/hand.blend][here]].
rlm@73 14
rlm@192 15 #+name: integration
rlm@73 16 #+begin_src clojure
rlm@192 17 (ns cortex.integration
rlm@73 18 "let's play!"
rlm@192 19 {:author "Robert McIntyre"}
rlm@281 20 (:use (cortex world util body sense
rlm@281 21 hearing touch vision proprioception movement))
rlm@192 22 (:import (com.jme3.math ColorRGBA Vector3f))
rlm@281 23 (:import java.io.File)
rlm@192 24 (:import com.jme3.audio.AudioNode)
rlm@192 25 (:import com.aurellem.capture.RatchetTimer))
rlm@73 26
rlm@281 27 (dorun (cortex.import/mega-import-jme3))
rlm@281 28 (rlm.rlm-commands/help)
rlm@74 29
rlm@281 30 (def hand "Models/test-creature/hand.blend")
rlm@78 31
rlm@281 32 (def output-base (File. "/home/r/proj/cortex/render/hand"))
rlm@189 33
rlm@297 34
rlm@297 35 ;; Let the hand fall palm-up
rlm@297 36
rlm@297 37 ;; it curls its phalanges, starting with the pinky.
rlm@297 38
rlm@297 39 ;; it lets these fall back down?
rlm@297 40
rlm@297 41 ;; block falls down onto the hand, accompanied by a sound. The block
rlm@297 42 ;; can be seen by the hand's eye.
rlm@297 43
rlm@297 44 ;; hand FORCEFULLY catapults the block so that it hits the camera.
rlm@297 45
rlm@297 46
rlm@296 47 (defn motor-control-program
rlm@296 48 "Create a function which will execute the motor script"
rlm@296 49 [muscle-positions
rlm@296 50 script]
rlm@296 51 (let [current-frame (atom -1)
rlm@296 52 keyed-script (group-by first script)
rlm@296 53 current-forces (atom {}) ]
rlm@296 54 (fn [effectors]
rlm@296 55 (let [indexed-effectors (vec effectors)]
rlm@296 56 (dorun
rlm@296 57 (for [[_ part force] (keyed-script (swap! current-frame inc))]
rlm@296 58 (swap! current-forces (fn [m] (assoc m part force)))))
rlm@296 59 (doall (map (fn [effector power]
rlm@296 60 (effector (int power)))
rlm@296 61 effectors
rlm@296 62 (map #(@current-forces % 0) muscle-positions)))))))
rlm@296 63
rlm@296 64 (def muscle-positions
rlm@296 65 [:pointer-2-e
rlm@296 66 :pointer-2-f
rlm@296 67 :thumb-1
rlm@296 68 :thumb-1
rlm@296 69 :pointer-1-e
rlm@296 70 :pointer-1-f
rlm@296 71 :thumb-2-e
rlm@296 72 :thumb-2-f
rlm@296 73 :middle-1-e
rlm@296 74 :middle-1-f
rlm@296 75 :pointer-3-f
rlm@296 76 :pointer-3-e
rlm@296 77 :middle-2-e
rlm@296 78 :middle-2-f
rlm@296 79 :middle-3-f
rlm@296 80 :middle-3-e
rlm@296 81 :pinky-2-e
rlm@296 82 :pinky-2-f
rlm@296 83 :pinky-3-f
rlm@296 84 :pinky-3-e
rlm@296 85 :ring-3-e
rlm@296 86 :ring-3-f
rlm@296 87 :ring-2-f
rlm@296 88 :ring-2-e
rlm@296 89 :ring-1-e
rlm@296 90 :ring-1-f
rlm@296 91 :thumb-1-e
rlm@296 92 :thumb-1-f
rlm@296 93 :pinky-1-f
rlm@296 94 :pinky-1-e])
rlm@296 95
rlm@296 96 (def full 9001)
rlm@296 97 ;; the systax here is [keyframe body-part force]
rlm@296 98 (def wiggle-each-finger-tip
rlm@298 99 [[300 :pinky-3-f 50]
rlm@298 100 [320 :pinky-2-f 80]
rlm@298 101 [340 :pinky-1-f 100]
rlm@297 102
rlm@298 103 [310 :ring-3-f 100]
rlm@298 104 [330 :ring-2-f 120]
rlm@298 105 [350 :ring-1-f 140]
rlm@296 106
rlm@298 107 [330 :middle-3-f 120]
rlm@298 108 [340 :middle-2-f 120]
rlm@298 109 [360 :middle-1-f 30]
rlm@296 110
rlm@298 111 [350 :pointer-3-f 120]
rlm@298 112 [360 :pointer-2-f 120]
rlm@298 113 [380 :pointer-1-f 30]
rlm@296 114
rlm@298 115 [800 :pinky-3-f 0]
rlm@298 116 [800 :pinky-2-f 0]
rlm@298 117 [800 :pinky-1-f 0]
rlm@296 118
rlm@298 119 [800 :ring-3-f 0]
rlm@298 120 [800 :ring-2-f 0]
rlm@298 121 [800 :ring-1-f 0]
rlm@296 122
rlm@298 123 [800 :middle-3-f 0]
rlm@298 124 [800 :middle-2-f 0]
rlm@298 125 [800 :middle-1-f 0]
rlm@296 126
rlm@298 127 [800 :pointer-3-f 0]
rlm@298 128 [800 :pointer-2-f 0]
rlm@298 129 [800 :pointer-1-f 0]
rlm@297 130
rlm@297 131
rlm@298 132 [800 :pinky-3-e 50]
rlm@298 133 [800 :pinky-2-e 80]
rlm@298 134 [800 :pinky-1-e 100]
rlm@297 135
rlm@298 136 [800 :ring-3-e 100]
rlm@298 137 [800 :ring-2-e 120]
rlm@298 138 [800 :ring-1-e 140]
rlm@298 139
rlm@298 140 [800 :middle-3-e 120]
rlm@298 141 [800 :middle-2-e 120]
rlm@298 142 [800 :middle-1-e 30]
rlm@298 143
rlm@298 144 [800 :pointer-3-e 120]
rlm@298 145 [800 :pointer-2-e 120]
rlm@298 146 [800 :pointer-1-e 30]
rlm@298 147
rlm@298 148 [870 :pinky-3-e 0]
rlm@298 149 [870 :pinky-2-e 0]
rlm@298 150 [870 :pinky-1-e 0]
rlm@298 151
rlm@298 152 [870 :ring-3-e 0]
rlm@298 153 [870 :ring-2-e 0]
rlm@298 154 [870 :ring-1-e 0]
rlm@298 155
rlm@298 156 [870 :middle-3-e 0]
rlm@298 157 [870 :middle-2-e 0]
rlm@298 158 [870 :middle-1-e 0]
rlm@298 159
rlm@298 160 [870 :pointer-3-e 0]
rlm@298 161 [870 :pointer-2-e 0]
rlm@298 162 [870 :pointer-1-e 0]
rlm@298 163
rlm@298 164 [1500 :pointer-1-f full]
rlm@298 165 [1500 :pointer-2-f full]
rlm@298 166 [1500 :pointer-3-f full]
rlm@298 167
rlm@298 168 [1500 :middle-1-f full]
rlm@298 169 [1500 :middle-2-f full]
rlm@298 170 [1500 :middle-3-f full]
rlm@298 171
rlm@298 172 [1510 :pointer-1-f 0]
rlm@298 173 [1510 :pointer-2-f 0]
rlm@298 174 [1510 :pointer-3-f 0]
rlm@298 175
rlm@298 176 [1510 :middle-1-f 0]
rlm@298 177 [1510 :middle-2-f 0]
rlm@298 178 [1510 :middle-3-f 0]
rlm@297 179 ])
rlm@297 180
rlm@298 181 (defn gen-summon-ball [debug?]
rlm@298 182 (let [wait (atom 1100)]
rlm@297 183 (fn [world]
rlm@297 184 (if (= 0 (swap! wait dec))
rlm@297 185 (let [brick
rlm@297 186 (box 0.8 0.8 0.8 :mass 0.05
rlm@298 187 :position (Vector3f. -0.5 0 0.5)
rlm@298 188 :color (ColorRGBA/Red))
rlm@298 189 bell (AudioNode. (asset-manager)
rlm@298 190 "Sounds/pure.wav" false)]
rlm@298 191 (.play bell)
rlm@298 192 (if debug?
rlm@298 193 (.addControl
rlm@298 194 brick
rlm@298 195 (proxy [AbstractControl] []
rlm@298 196 (controlUpdate [tpf]
rlm@298 197 (println-repl (.getWorldTranslation brick)))
rlm@298 198 (controlRender [_ _]))))
rlm@297 199 (add-element world brick))))))
rlm@297 200
rlm@296 201
rlm@295 202 (def control-list
rlm@295 203 [
rlm@295 204 0 ;;pointer-21 #<Vector3f (0.99999994, 0.0, 0.0)>
rlm@296 205 0 ;;pointer-21 #<Vector3f (-0.99999994, 0.0, 0.0)>
rlm@295 206 0 ;;thumb-11 #<Vector3f (-0.8802276, -0.39781287, -0.25873658)>
rlm@295 207 0 ;;thumb-11 #<Vector3f (0.8485723, 0.46149826, 0.2587364)>
rlm@295 208 0 ;;pointer-11 #<Vector3f (0.99999994, 0.0, 0.0)>
rlm@295 209 0 ;;pointer-11 #<Vector3f (-0.99999994, 0.0, 0.0)>
rlm@295 210 0 ;;thumb-2.0011 #<Vector3f (-0.71705645, -0.44753736, -0.5343599)>
rlm@295 211 0 ;;thumb-2.0011 #<Vector3f (-0.10567085, 0.83862597, 0.53435963)>
rlm@295 212 0 ;;middle-11 #<Vector3f (0.99999994, 0.0, 0.0)>
rlm@295 213 0 ;;middle-11 #<Vector3f (-0.99999994, 0.0, 0.0)>
rlm@298 214 0 ;;pointer-31 #<Vector3f (-0.99999994, 0.0, 0.0)>
rlm@295 215 0 ;;pointer-31 #<Vector3f (0.99999994, 0.0, 0.0)>
rlm@295 216 0 ;;middle-21 #<Vector3f (0.99999994, 0.0, 0.0)>
rlm@295 217 0 ;;middle-21 #<Vector3f (-0.99999994, 0.0, 0.0)>
rlm@295 218 0 ;;middle-31 #<Vector3f (-0.99999994, 0.0, 0.0)>
rlm@295 219 0 ;;middle-31 #<Vector3f (0.99999994, 0.0, 0.0)>
rlm@295 220 0 ;;pinky-21 #<Vector3f (0.99999994, 0.0, 0.0)>
rlm@295 221 0 ;;pinky-21 #<Vector3f (-0.99999994, 0.0, 0.0)>
rlm@296 222 0 ;;pinky-31 #<Vector3f (-1, 0.0, 0.0)>
rlm@296 223 0 ;;pinky-31 #<Vector3f (1.0, 0.0, 0.0)>
rlm@295 224 0 ;;ring-31 #<Vector3f (0.99999994, 0.0, 0.0)>
rlm@295 225 0 ;;ring-31 #<Vector3f (-0.99999994, 0.0, 0.0)>
rlm@295 226 0 ;;ring-21 #<Vector3f (-0.99999994, 0.0, 0.0)>
rlm@295 227 0 ;;ring-21 #<Vector3f (0.99999994, 0.0, 0.0)>
rlm@295 228 0 ;;ring-11 #<Vector3f (0.99999994, 0.0, 0.0)>
rlm@295 229 0 ;;ring-11 #<Vector3f (-0.99999994, 0.0, 0.0)>
rlm@295 230 0 ;;thumb-11 #<Vector3f (-0.43154645, 0.7302033, 0.5296894)>
rlm@295 231 0 ;;thumb-11 #<Vector3f (-0.8032993, -0.2722854, -0.5296895)>
rlm@295 232 0 ;;pinky-11 #<Vector3f (-0.99999994, 0.0, 0.0)>
rlm@295 233 0 ;;pinky-11 #<Vector3f (0.99999994, 0.0, 0.0)>
rlm@295 234 ])
rlm@295 235
rlm@298 236 (import com.aurellem.capture.Capture)
rlm@298 237
rlm@281 238 (defn test-everything!
rlm@281 239 ([] (test-everything! false))
rlm@281 240 ([record?]
rlm@281 241 (let [me (sphere 0.5 :color ColorRGBA/Blue :physical? false)
rlm@281 242
rlm@298 243 base (File. "/home/r/proj/cortex/render/hand")
rlm@298 244
rlm@298 245
rlm@281 246 creature (doto (load-blender-model hand)
rlm@281 247 (body!))
rlm@297 248
rlm@298 249 summon-ball (gen-summon-ball false)
rlm@192 250 ;;;;;;;;;;;; Sensors/Effectors ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
rlm@298 251 touch (touch! creature)
rlm@298 252 touch-display (view-touch)
rlm@189 253
rlm@298 254 vision (vision! creature)
rlm@298 255 vision-display (view-vision)
rlm@189 256
rlm@298 257 hearing (hearing! creature)
rlm@298 258 hearing-display (view-hearing)
rlm@189 259
rlm@173 260 prop (proprioception! creature)
rlm@190 261 prop-display (view-proprioception)
rlm@148 262
rlm@296 263 control-script (motor-control-program
rlm@296 264 muscle-positions wiggle-each-finger-tip)
rlm@191 265 muscles (movement! creature)
rlm@281 266 muscle-display (view-movement)
rlm@281 267 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
rlm@189 268
rlm@281 269 fix-display (gen-fix-display)]
rlm@285 270 (world
rlm@285 271 (nodify [creature
rlm@285 272 (box 10 2 10 :position (Vector3f. 0 -9 0)
rlm@285 273 :color ColorRGBA/Gray :mass 0)
rlm@285 274 me])
rlm@298 275 standard-debug-controls
rlm@298 276
rlm@285 277 (fn [world]
rlm@285 278 (.setTimer world (RatchetTimer. 60))
rlm@297 279 (position-camera
rlm@298 280 world (Vector3f. -0.13217318, 5.816415, -5.3089414)
rlm@298 281 (Quaternion. 0.55685693, 0.0042774677, -0.0028673497, 0.83059245))
rlm@298 282
rlm@285 283 (light-up-everything world)
rlm@285 284 (enable-debug world)
rlm@285 285 (add-camera! world
rlm@285 286 (add-eye! creature
rlm@285 287 (.getChild
rlm@285 288 (.getChild creature "eyes") "eye"))
rlm@285 289 (comp (view-image) BufferedImage!))
rlm@298 290
rlm@298 291 (if record?
rlm@298 292 (Capture/captureVideo
rlm@298 293 world (File. base "main")))
rlm@298 294 (if record?
rlm@298 295 (Capture/captureAudio
rlm@298 296 world (File. base "main.wav"))))
rlm@285 297 (fn [world tpf]
rlm@298 298 (prop-display
rlm@298 299 (prop)
rlm@298 300 (if record? (File. base "proprio")))
rlm@298 301 (touch-display
rlm@298 302 (map #(% (.getRootNode world)) touch)
rlm@298 303 (if record? (File. base "touch")))
rlm@298 304 (vision-display
rlm@298 305 (map #(% world) vision)
rlm@298 306 (if record? (File. base "vision")))
rlm@298 307 (hearing-display
rlm@298 308 (map #(% world) hearing)
rlm@298 309 (if record? (File. base "hearing")))
rlm@298 310 (muscle-display
rlm@298 311 (control-script muscles)
rlm@298 312 (if record? (File. base "muscle")))
rlm@298 313
rlm@297 314 (summon-ball world)
rlm@298 315
rlm@285 316 (.setLocalTranslation me (.getLocation (.getCamera world)))
rlm@285 317 (fix-display world))))))
rlm@298 318
rlm@298 319
rlm@298 320 (comment
rlm@298 321 ;; list of touch targets
rlm@298 322 0 middle-11
rlm@298 323 1 middle-21
rlm@298 324 2 middle-31
rlm@298 325 3 pinky-11
rlm@298 326 4 pinky-21
rlm@298 327 5 pinky-31
rlm@298 328 6 pointer-11
rlm@298 329 7 pointer-21
rlm@298 330 8 pointer-31
rlm@298 331 9 ring-11
rlm@298 332 10 ring-21
rlm@298 333 11 ring-31
rlm@298 334 12 thumb-11
rlm@298 335 13 thumb-2.0011
rlm@298 336
rlm@298 337
rlm@298 338 ;; list of vision targets
rlm@298 339 0 :all
rlm@298 340 1 :green
rlm@298 341 2 :blue
rlm@298 342 3 :red
rlm@298 343
rlm@298 344 ;; list of proprio targets
rlm@298 345 0 middle-11 -> middle-21
rlm@298 346 1 middle-21 -> middle-31
rlm@298 347 2 thumb-11 -> thumb-2.0011
rlm@298 348 3 pointer-11 -> pointer-21
rlm@298 349 4 pointer-21 -> pointer-31
rlm@298 350 5 ring-21 -> ring-31
rlm@298 351 6 ring-11 -> ring-21
rlm@298 352 7 pinky-21 -> pinky-31
rlm@298 353 8 pinky-11 -> pinky-21
rlm@298 354 9 middle-11 -> palm1
rlm@298 355 10 pinky-11 -> palm1
rlm@298 356 11 palm1 -> pointer-11
rlm@298 357 12 palm1 -> ring-11
rlm@298 358 13 palm1 -> thumb-11
rlm@298 359
rlm@298 360
rlm@298 361 ;; list of muscle targets
rlm@298 362 0 :pointer-2-e
rlm@298 363 1 :pointer-2-f
rlm@298 364 2 :thumb-1
rlm@298 365 3 :thumb-1
rlm@298 366 4 :pointer-1-e
rlm@298 367 5 :pointer-1-f
rlm@298 368 6 :thumb-2-e
rlm@298 369 7 :thumb-2-f
rlm@298 370 8 :middle-1-e
rlm@298 371 9 :middle-1-f
rlm@298 372 10 :pointer-3-f
rlm@298 373 11 :pointer-3-e
rlm@298 374 12 :middle-2-e
rlm@298 375 13 :middle-2-f
rlm@298 376 14 :middle-3-f
rlm@298 377 15 :middle-3-e
rlm@298 378 16 :pinky-2-e
rlm@298 379 17 :pinky-2-f
rlm@298 380 18 :pinky-3-f
rlm@298 381 19 :pinky-3-e
rlm@298 382 20 :ring-3-e
rlm@298 383 21 :ring-3-f
rlm@298 384 22 :ring-2-f
rlm@298 385 23 :ring-2-e
rlm@298 386 24 :ring-1-e
rlm@298 387 25 :ring-1-f
rlm@298 388 26 :thumb-1-e
rlm@298 389 27 :thumb-1-f
rlm@298 390 28 :pinky-1-f
rlm@298 391 29 :pinky-1-e
rlm@298 392 )
rlm@298 393
rlm@298 394
rlm@298 395
rlm@298 396 ;; rotate touch 180
rlm@298 397
rlm@298 398 ;; rotate mucles 90 counter-clockwise
rlm@298 399 ;; scale muscles to 15x60
rlm@298 400
rlm@298 401 finger width : 113
rlm@298 402 finger height : 357
rlm@298 403
rlm@298 404 thumb width : 113
rlm@298 405
rlm@298 406 pinky --- 0,195
rlm@298 407 ring --- 111,100
rlm@298 408 middle --- 228,0
rlm@298 409 pointer -- 436,96
rlm@298 410 thumb --- 486,420
rlm@298 411
rlm@298 412
rlm@298 413
rlm@298 414 within a finger (coordinates of top left corner (x,y)):
rlm@298 415
rlm@298 416 tip-flexor : 0,7
rlm@298 417 tip-extensor : 98,7
rlm@298 418 tip : 18,0
rlm@298 419
rlm@298 420 joint-2-3 : 32,79
rlm@298 421
rlm@298 422 mid-flexor : 19,131
rlm@298 423 mid-extensor : 80,131
rlm@298 424 mid : 30,133
rlm@298 425
rlm@298 426 joint-1-2 : 32,193
rlm@298 427
rlm@298 428 base-flexor : 19,245
rlm@298 429 base-extensor : 80,245
rlm@298 430 base : 39,247
rlm@298 431
rlm@298 432 joint-palm-1 : 32,307
rlm@298 433
rlm@298 434
rlm@298 435 Thumb is the same as finger, except it has two more pieces
rlm@298 436
rlm@298 437 extra-flexor-1 : 2,131
rlm@298 438 extra-flexor-2 : 100,131
rlm@298 439
rlm@298 440 ;; rotate entire thumb 45 degrees clockwise
rlm@298 441
rlm@298 442 within vision
rlm@298 443 gray -- 165,577
rlm@298 444 green -- 278,577
rlm@298 445 blue -- 165,682
rlm@298 446 red -- 278,682
rlm@298 447
rlm@298 448 entire hand : 809, 22
rlm@298 449 main view : 78,202
rlm@298 450 hearing : 784,819
rlm@298 451
rlm@298 452 hand-size: 688x769
rlm@298 453
rlm@298 454
rlm@298 455 total image size:
rlm@298 456 1600x894
rlm@298 457
rlm@298 458 (def base (File. "/home/r/proj/cortex/render/hand"))
rlm@298 459
rlm@298 460
rlm@298 461
rlm@298 462 (defn prepare-muscle [muscle]
rlm@298 463 ["(" muscle "-rotate" "90" "-scale" "15x60!" ")"])
rlm@298 464
rlm@298 465 (defn prepare-touch [touch]
rlm@298 466 ["(" touch "-rotate" "180" ")"])
rlm@298 467
rlm@298 468 (defn generate-top-finger [tip-flexor tip-extensor tip
rlm@298 469 joint-2-3
rlm@298 470 mid-flexor mid-extensor mid
rlm@298 471 joint-1-2]
rlm@298 472 ["("
rlm@298 473 "-size" "113x357" "xc:transparent"
rlm@298 474 (prepare-muscle tip-flexor) "-geometry" "+0+7" "-composite"
rlm@298 475 (prepare-muscle tip-extensor) "-geometry" "+98+7" "-composite"
rlm@298 476 (prepare-touch tip) "-geometry" "+18+0" "-composite"
rlm@298 477
rlm@298 478 joint-2-3 "-geometry" "+32+79" "-composite"
rlm@298 479
rlm@298 480 (prepare-muscle mid-flexor) "-geometry" "+19+131" "-composite"
rlm@298 481 (prepare-muscle mid-extensor) "-geometry" "+80+131" "-composite"
rlm@298 482 (prepare-touch mid) "-geometry" "+39+133" "-composite"
rlm@298 483
rlm@298 484 joint-1-2 "-geometry" "+32+193" "-composite"
rlm@298 485 ")"])
rlm@298 486
rlm@298 487 (defn generate-finger
rlm@298 488 [tip-flexor tip-extensor tip
rlm@298 489 joint-2-3
rlm@298 490 mid-flexor mid-extensor mid
rlm@298 491 joint-1-2
rlm@298 492 base-flexor base-extensor base
rlm@298 493 joint-palm-1]
rlm@298 494 ["("
rlm@298 495 "-size" "113x357" "xc:transparent"
rlm@298 496 (generate-top-finger
rlm@298 497 tip-flexor tip-extensor tip
rlm@298 498 joint-2-3
rlm@298 499 mid-flexor mid-extensor mid
rlm@298 500 joint-1-2) "-geometry" "+0+0" "-composite"
rlm@298 501 (prepare-muscle base-flexor) "-geometry" "+19+245" "-composite"
rlm@298 502 (prepare-muscle base-extensor) "-geometry" "+80+245" "-composite"
rlm@298 503 (prepare-touch base) "-geometry" "+39+247" "-composite"
rlm@298 504 joint-palm-1 "-geometry" "+32+307" "-composite"
rlm@298 505 ")"])
rlm@298 506
rlm@298 507 (defn generate-thumb
rlm@298 508 [tip-flexor tip-extensor tip
rlm@298 509 joint-1-2
rlm@298 510 mid-flexor mid-extensor mid-flexor-2 mid-extensor-2 mid
rlm@298 511 joint-palm-1]
rlm@298 512 ["("
rlm@298 513 "-size" "113x357" "xc:transparent"
rlm@298 514 (generate-top-finger
rlm@298 515 tip-flexor tip-extensor tip
rlm@298 516 joint-1-2
rlm@298 517 mid-flexor mid-extensor mid
rlm@298 518 joint-palm-1) "-geometry" "+0+0" "-composite"
rlm@298 519 (prepare-muscle mid-flexor-2) "-geometry" "+2+131" "-composite"
rlm@298 520 (prepare-muscle mid-extensor-2) "-geometry" "+100+131" "-composite"
rlm@298 521 ")"])
rlm@298 522
rlm@298 523 pinky --- 0,195
rlm@298 524 ring --- 111,100
rlm@298 525 middle --- 228,0
rlm@298 526 pointer -- 436,96
rlm@298 527 thumb --- 486,420
rlm@298 528
rlm@298 529
rlm@298 530 (defn generate-hand
rlm@298 531 [pinky-pieces
rlm@298 532 ring-pieces
rlm@298 533 middle-pieces
rlm@298 534 pointer-pieces
rlm@298 535 thumb-pieces]
rlm@298 536 ["("
rlm@298 537 "-size" "688x769" "xc:transparent"
rlm@298 538 (apply generate-finger pinky-pieces)
rlm@298 539 "-geometry" "+0+195" "-composite"
rlm@298 540 (apply generate-finger ring-pieces)
rlm@298 541 "-geometry" "+111+100" "-composite"
rlm@298 542 (apply generate-finger middle-pieces)
rlm@298 543 "-geometry" "+228+0" "-composite"
rlm@298 544 "(" (apply generate-thumb thumb-pieces) "-background" "#00000000"
rlm@298 545 "-rotate" "45" ")"
rlm@298 546 "-geometry" "+300+420" "-composite"
rlm@298 547 (apply generate-finger pointer-pieces)
rlm@298 548 "-geometry" "+350+96" "-composite"
rlm@298 549 ")"])
rlm@298 550
rlm@298 551 (defn generate-vision
rlm@298 552 [all green blue red]
rlm@298 553 ["("
rlm@298 554 "-size" "204x192" "xc:transparent"
rlm@298 555 all "-geometry" "+0+0" "-composite"
rlm@298 556 green "-geometry" "+113+0" "-composite"
rlm@298 557 blue "-geometry" "+0+105" "-composite"
rlm@298 558 red "-geometry" "+113+105" "-composite"
rlm@298 559 ")"])
rlm@298 560
rlm@298 561
rlm@298 562
rlm@298 563 (def test-muscle (File. base "muscle/0/0000000.png"))
rlm@298 564 (def test-proprio (File. base "proprio/0/0000000.png"))
rlm@298 565 (def test-tip (File. base "touch/2/0000000.png"))
rlm@298 566 (def test-mid (File. base "touch/0/0000000.png"))
rlm@298 567 (def test-vision (File. base "vision/0/0000000.png"))
rlm@298 568 (def test-hearing (File. base "hearing/0/0000000.png"))
rlm@298 569 (def test-main (File. base "main/0000000.png"))
rlm@298 570
rlm@298 571
rlm@298 572 (def test-target (File. base "output.png"))
rlm@298 573
rlm@298 574 (def background (File. base "background.png"))
rlm@298 575
rlm@298 576 (use 'clojure.contrib.shell-out)
rlm@298 577 (defn final-image [muscle proprio tip mid vision hearing main]
rlm@298 578 (let [[muscle proprio tip mid vision hearing main] (map #(.getCanonicalPath %)
rlm@298 579 [muscle proprio tip mid vision
rlm@298 580 hearing main])
rlm@298 581 finger-pieces [muscle muscle tip
rlm@298 582 proprio
rlm@298 583 muscle muscle mid
rlm@298 584 proprio
rlm@298 585 muscle muscle mid
rlm@298 586 proprio]
rlm@298 587 thumb-pieces [muscle muscle tip
rlm@298 588 proprio
rlm@298 589 muscle muscle muscle muscle mid
rlm@298 590 proprio]]
rlm@298 591
rlm@298 592
rlm@298 593 (apply
rlm@298 594 sh
rlm@298 595 (flatten
rlm@298 596 ["convert"
rlm@298 597 (.getCanonicalPath background)
rlm@298 598 (generate-hand finger-pieces
rlm@298 599 finger-pieces
rlm@298 600 finger-pieces
rlm@298 601 finger-pieces
rlm@298 602 thumb-pieces)
rlm@298 603 "-geometry" "+809+22" "-composite"
rlm@298 604
rlm@298 605 (generate-vision vision vision vision vision)
rlm@298 606 "-geometry" "+974+599" "-composite"
rlm@298 607
rlm@298 608 hearing
rlm@298 609 "-geometry" "+784+819" "-composite"
rlm@298 610
rlm@298 611 main
rlm@298 612 "-geometry" "+78+202" "-composite"
rlm@298 613
rlm@298 614 (.getCanonicalPath test-target)]))))
rlm@298 615
rlm@298 616
rlm@298 617
rlm@298 618
rlm@298 619
rlm@298 620
rlm@87 621 #+end_src
rlm@83 622
rlm@282 623 #+results: integration
rlm@282 624 : #'cortex.integration/test-everything!
rlm@282 625
rlm@78 626 * COMMENT purgatory
rlm@78 627 #+begin_src clojure
rlm@77 628 (defn bullet-trans* []
rlm@77 629 (let [obj-a (box 1.5 0.5 0.5 :color ColorRGBA/Red
rlm@77 630 :position (Vector3f. 5 0 0)
rlm@77 631 :mass 90)
rlm@77 632 obj-b (sphere 0.5 :color ColorRGBA/Blue
rlm@77 633 :position (Vector3f. -5 0 0)
rlm@77 634 :mass 0)
rlm@77 635 control-a (.getControl obj-a RigidBodyControl)
rlm@77 636 control-b (.getControl obj-b RigidBodyControl)
rlm@77 637 move-up? (atom nil)
rlm@77 638 move-down? (atom nil)
rlm@77 639 move-left? (atom nil)
rlm@77 640 move-right? (atom nil)
rlm@77 641 roll-left? (atom nil)
rlm@77 642 roll-right? (atom nil)
rlm@77 643 force 100
rlm@77 644 swivel
rlm@77 645 (.toRotationMatrix
rlm@77 646 (doto (Quaternion.)
rlm@77 647 (.fromAngleAxis (/ Math/PI 2)
rlm@77 648 Vector3f/UNIT_X)))
rlm@77 649 x-move
rlm@77 650 (doto (Matrix3f.)
rlm@77 651 (.fromStartEndVectors Vector3f/UNIT_X
rlm@77 652 (.normalize (Vector3f. 1 1 0))))
rlm@77 653
rlm@77 654 timer (atom 0)]
rlm@77 655 (doto
rlm@77 656 (ConeJoint.
rlm@77 657 control-a control-b
rlm@77 658 (Vector3f. -8 0 0)
rlm@77 659 (Vector3f. 2 0 0)
rlm@77 660 ;;swivel swivel
rlm@77 661 ;;Matrix3f/IDENTITY Matrix3f/IDENTITY
rlm@77 662 x-move Matrix3f/IDENTITY
rlm@77 663 )
rlm@77 664 (.setCollisionBetweenLinkedBodys false)
rlm@77 665 (.setLimit (* 1 (/ Math/PI 4)) ;; twist
rlm@77 666 (* 1 (/ Math/PI 4)) ;; swing span in X-Y plane
rlm@77 667 (* 0 (/ Math/PI 4)))) ;; swing span in Y-Z plane
rlm@77 668 (world (nodify
rlm@77 669 [obj-a obj-b])
rlm@77 670 (merge standard-debug-controls
rlm@77 671 {"key-r" (fn [_ pressed?] (reset! move-up? pressed?))
rlm@77 672 "key-t" (fn [_ pressed?] (reset! move-down? pressed?))
rlm@77 673 "key-f" (fn [_ pressed?] (reset! move-left? pressed?))
rlm@77 674 "key-g" (fn [_ pressed?] (reset! move-right? pressed?))
rlm@77 675 "key-v" (fn [_ pressed?] (reset! roll-left? pressed?))
rlm@77 676 "key-b" (fn [_ pressed?] (reset! roll-right? pressed?))})
rlm@77 677
rlm@77 678 (fn [world]
rlm@77 679 (enable-debug world)
rlm@77 680 (set-gravity world Vector3f/ZERO)
rlm@77 681 )
rlm@77 682
rlm@77 683 (fn [world _]
rlm@77 684
rlm@77 685 (if @move-up?
rlm@77 686 (.applyForce control-a
rlm@77 687 (Vector3f. force 0 0)
rlm@77 688 (Vector3f. 0 0 0)))
rlm@77 689 (if @move-down?
rlm@77 690 (.applyForce control-a
rlm@77 691 (Vector3f. (- force) 0 0)
rlm@77 692 (Vector3f. 0 0 0)))
rlm@77 693 (if @move-left?
rlm@77 694 (.applyForce control-a
rlm@77 695 (Vector3f. 0 force 0)
rlm@77 696 (Vector3f. 0 0 0)))
rlm@77 697 (if @move-right?
rlm@77 698 (.applyForce control-a
rlm@77 699 (Vector3f. 0 (- force) 0)
rlm@77 700 (Vector3f. 0 0 0)))
rlm@77 701
rlm@77 702 (if @roll-left?
rlm@77 703 (.applyForce control-a
rlm@77 704 (Vector3f. 0 0 force)
rlm@77 705 (Vector3f. 0 0 0)))
rlm@77 706 (if @roll-right?
rlm@77 707 (.applyForce control-a
rlm@77 708 (Vector3f. 0 0 (- force))
rlm@77 709 (Vector3f. 0 0 0)))
rlm@77 710
rlm@77 711 (if (zero? (rem (swap! timer inc) 100))
rlm@77 712 (.attachChild
rlm@77 713 (.getRootNode world)
rlm@77 714 (sphere 0.05 :color ColorRGBA/Yellow
rlm@77 715 :physical? false :position
rlm@77 716 (.getWorldTranslation obj-a)))))
rlm@77 717 )
rlm@77 718 ))
rlm@77 719
rlm@106 720 (defn test-joint [joint]
rlm@106 721 (let [[origin top bottom floor] (world-setup joint)
rlm@106 722 control (.getControl top RigidBodyControl)
rlm@106 723 move-up? (atom false)
rlm@106 724 move-down? (atom false)
rlm@106 725 move-left? (atom false)
rlm@106 726 move-right? (atom false)
rlm@106 727 roll-left? (atom false)
rlm@106 728 roll-right? (atom false)
rlm@106 729 timer (atom 0)]
rlm@106 730
rlm@106 731 (world
rlm@106 732 (nodify [top bottom floor origin])
rlm@106 733 (merge standard-debug-controls
rlm@106 734 {"key-r" (fn [_ pressed?] (reset! move-up? pressed?))
rlm@106 735 "key-t" (fn [_ pressed?] (reset! move-down? pressed?))
rlm@106 736 "key-f" (fn [_ pressed?] (reset! move-left? pressed?))
rlm@106 737 "key-g" (fn [_ pressed?] (reset! move-right? pressed?))
rlm@106 738 "key-v" (fn [_ pressed?] (reset! roll-left? pressed?))
rlm@106 739 "key-b" (fn [_ pressed?] (reset! roll-right? pressed?))})
rlm@106 740
rlm@106 741 (fn [world]
rlm@106 742 (light-up-everything world)
rlm@106 743 (enable-debug world)
rlm@106 744 (set-gravity world (Vector3f. 0 0 0))
rlm@106 745 )
rlm@106 746
rlm@106 747 (fn [world _]
rlm@106 748 (if (zero? (rem (swap! timer inc) 100))
rlm@106 749 (do
rlm@106 750 ;; (println-repl @timer)
rlm@106 751 (.attachChild (.getRootNode world)
rlm@106 752 (sphere 0.05 :color ColorRGBA/Yellow
rlm@106 753 :position (.getWorldTranslation top)
rlm@106 754 :physical? false))
rlm@106 755 (.attachChild (.getRootNode world)
rlm@106 756 (sphere 0.05 :color ColorRGBA/LightGray
rlm@106 757 :position (.getWorldTranslation bottom)
rlm@106 758 :physical? false))))
rlm@106 759
rlm@106 760 (if @move-up?
rlm@106 761 (.applyTorque control
rlm@106 762 (.mult (.getPhysicsRotation control)
rlm@106 763 (Vector3f. 0 0 10))))
rlm@106 764 (if @move-down?
rlm@106 765 (.applyTorque control
rlm@106 766 (.mult (.getPhysicsRotation control)
rlm@106 767 (Vector3f. 0 0 -10))))
rlm@106 768 (if @move-left?
rlm@106 769 (.applyTorque control
rlm@106 770 (.mult (.getPhysicsRotation control)
rlm@106 771 (Vector3f. 0 10 0))))
rlm@106 772 (if @move-right?
rlm@106 773 (.applyTorque control
rlm@106 774 (.mult (.getPhysicsRotation control)
rlm@106 775 (Vector3f. 0 -10 0))))
rlm@106 776 (if @roll-left?
rlm@106 777 (.applyTorque control
rlm@106 778 (.mult (.getPhysicsRotation control)
rlm@106 779 (Vector3f. -1 0 0))))
rlm@106 780 (if @roll-right?
rlm@106 781 (.applyTorque control
rlm@106 782 (.mult (.getPhysicsRotation control)
rlm@106 783 (Vector3f. 1 0 0))))))))
rlm@99 784 #+end_src
rlm@192 785
rlm@99 786
rlm@99 787 * COMMENT generate source
rlm@192 788 #+begin_src clojure :tangle ../src/cortex/integration.clj
rlm@192 789 <<integration>>
rlm@99 790 #+end_src
rlm@99 791
rlm@99 792
rlm@94 793
rlm@94 794