view org/integration.org @ 310:71946ec07be9

sending draft letter for review
author Robert McIntyre <rlm@mit.edu>
date Sat, 18 Feb 2012 11:51:45 -0700
parents 5d448182c807
children e0e1561cbd22
line wrap: on
line source
1 #+title: Integration
2 #+author: Robert McIntyre
3 #+email: rlm@mit.edu
4 #+description:
5 #+keywords: simulation, jMonkeyEngine3, clojure
6 #+SETUPFILE: ../../aurellem/org/setup.org
7 #+INCLUDE: ../../aurellem/org/level-0.org
9 * Integration
11 This is the ultimate test which features all of the senses that I've
12 made so far. The blender file for the creature serves as an example of
13 a fully equipped creature in terms of senses. You can find it [[../assets/Models/test-creature/hand.blend][here]].
16 #+begin_html
17 <div class="figure">
18 <video controls="controls" width="755">
19 <source src="../video/hand.ogg" type="video/ogg"
20 preload="none" poster="../images/aurellem-1280x480.png" />
21 </video>
22 <br> <a href="http://youtu.be/ZgkWFIoHNuU"> YouTube </a>
23 <p>Simulated Senses in a Virtual Environment</p>
24 </div>
25 #+end_html
27 * Generating the Video
29 #+name: integration
30 #+begin_src clojure
31 (ns cortex.test.integration
32 "let's play!"
33 {:author "Robert McIntyre"}
34 (:use (cortex world util body sense
35 hearing touch vision proprioception movement))
36 (:import (com.jme3.math ColorRGBA Vector3f))
37 (:import java.io.File)
38 (:import com.jme3.audio.AudioNode)
39 (:import com.aurellem.capture.RatchetTimer))
41 (dorun (cortex.import/mega-import-jme3))
42 (rlm.rlm-commands/help)
44 (def hand "Models/test-creature/hand.blend")
46 (def output-base (File. "/home/r/proj/cortex/render/hand"))
47 #+end_src
49 For this demonstration I have to manually drive the muscles of the
50 hand. I do this by creating a little mini-language to describe
51 simulated muscle contraction.
53 #+name: integration-2
54 #+begin_src clojure
55 (defn motor-control-program
56 "Create a function which will execute the motor script"
57 [muscle-positions
58 script]
59 (let [current-frame (atom -1)
60 keyed-script (group-by first script)
61 current-forces (atom {}) ]
62 (fn [effectors]
63 (let [indexed-effectors (vec effectors)]
64 (dorun
65 (for [[_ part force] (keyed-script (swap! current-frame inc))]
66 (swap! current-forces (fn [m] (assoc m part force)))))
67 (doall (map (fn [effector power]
68 (effector (int power)))
69 effectors
70 (map #(@current-forces % 0) muscle-positions)))))))
72 (def muscle-positions
73 [:pointer-2-e
74 :pointer-2-f
75 :thumb-1
76 :thumb-1
77 :pointer-1-e
78 :pointer-1-f
79 :thumb-2-e
80 :thumb-2-f
81 :middle-1-e
82 :middle-1-f
83 :pointer-3-f
84 :pointer-3-e
85 :middle-2-e
86 :middle-2-f
87 :middle-3-f
88 :middle-3-e
89 :pinky-2-e
90 :pinky-2-f
91 :pinky-3-f
92 :pinky-3-e
93 :ring-3-e
94 :ring-3-f
95 :ring-2-f
96 :ring-2-e
97 :ring-1-e
98 :ring-1-f
99 :thumb-1-e
100 :thumb-1-f
101 :pinky-1-f
102 :pinky-1-e])
104 (def full 9001)
107 ;; Choreography:
109 ;; Let the hand fall palm-up
111 ;; it curls its phalanges, starting with the pinky.
113 ;; it lets its phalanges fall back down.
115 ;; block falls down onto the hand, accompanied by a sound. The block
116 ;; can be seen by the hand's eye.
118 ;; hand FORCEFULLY catapults the block so that it hits the camera.
121 ;; the syntax here is [keyframe body-part force]
122 (def move-fingers
123 [[300 :pinky-3-f 50]
124 [320 :pinky-2-f 80]
125 [340 :pinky-1-f 100]
127 [310 :ring-3-f 100]
128 [330 :ring-2-f 120]
129 [350 :ring-1-f 140]
131 [330 :middle-3-f 120]
132 [340 :middle-2-f 120]
133 [360 :middle-1-f 30]
135 [350 :pointer-3-f 120]
136 [360 :pointer-2-f 120]
137 [380 :pointer-1-f 30]
139 [800 :pinky-3-f 0]
140 [800 :pinky-2-f 0]
141 [800 :pinky-1-f 0]
143 [800 :ring-3-f 0]
144 [800 :ring-2-f 0]
145 [800 :ring-1-f 0]
147 [800 :middle-3-f 0]
148 [800 :middle-2-f 0]
149 [800 :middle-1-f 0]
151 [800 :pointer-3-f 0]
152 [800 :pointer-2-f 0]
153 [800 :pointer-1-f 0]
156 [800 :pinky-3-e 50]
157 [800 :pinky-2-e 80]
158 [800 :pinky-1-e 100]
160 [800 :ring-3-e 100]
161 [800 :ring-2-e 120]
162 [800 :ring-1-e 140]
164 [800 :middle-3-e 120]
165 [800 :middle-2-e 120]
166 [800 :middle-1-e 30]
168 [800 :pointer-3-e 120]
169 [800 :pointer-2-e 120]
170 [800 :pointer-1-e 30]
172 [870 :pinky-3-e 0]
173 [870 :pinky-2-e 0]
174 [870 :pinky-1-e 0]
176 [870 :ring-3-e 0]
177 [870 :ring-2-e 0]
178 [870 :ring-1-e 0]
180 [870 :middle-3-e 0]
181 [870 :middle-2-e 0]
182 [870 :middle-1-e 0]
184 [870 :pointer-3-e 0]
185 [870 :pointer-2-e 0]
186 [870 :pointer-1-e 0]
188 [1500 :pointer-1-f full]
189 [1500 :pointer-2-f full]
190 [1500 :pointer-3-f full]
192 [1500 :middle-1-f full]
193 [1500 :middle-2-f full]
194 [1500 :middle-3-f full]
196 [1510 :pointer-1-f 0]
197 [1510 :pointer-2-f 0]
198 [1510 :pointer-3-f 0]
200 [1510 :middle-1-f 0]
201 [1510 :middle-2-f 0]
202 [1510 :middle-3-f 0]
203 ])
205 (defn gen-summon-ball [debug?]
206 (let [wait (atom 1100)]
207 (fn [world]
208 (if (= 0 (swap! wait dec))
209 (let [brick
210 (box 0.8 0.8 0.8 :mass 0.05
211 :position (Vector3f. -0.5 0 0.5)
212 :color (ColorRGBA/Red))
213 bell (AudioNode. (asset-manager)
214 "Sounds/pure.wav" false)]
215 (.play bell)
216 (if debug?
217 (.addControl
218 brick
219 (proxy [AbstractControl] []
220 (controlUpdate [tpf]
221 (println-repl (.getWorldTranslation brick)))
222 (controlRender [_ _]))))
223 (add-element world brick))))))
225 (import com.aurellem.capture.Capture)
227 (defn test-everything!
228 ([] (test-everything! false))
229 ([record?]
230 (let [me (sphere 0.5 :color ColorRGBA/Blue :physical? false)
232 base (File. "/home/r/proj/cortex/render/hand")
235 creature (doto (load-blender-model hand)
236 (body!))
238 summon-ball (gen-summon-ball false)
239 ;;;;;;;;;;;; Sensors/Effectors ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
240 touch (touch! creature)
241 touch-display (view-touch)
243 vision (vision! creature)
244 vision-display (view-vision)
246 hearing (hearing! creature)
247 hearing-display (view-hearing)
249 prop (proprioception! creature)
250 prop-display (view-proprioception)
252 control-script (motor-control-program
253 muscle-positions move-fingers)
254 muscles (movement! creature)
255 muscle-display (view-movement)
256 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
258 fix-display (gen-fix-display)]
259 (world
260 (nodify [creature
261 (box 10 2 10 :position (Vector3f. 0 -9 0)
262 :color ColorRGBA/Gray :mass 0)
263 me])
264 standard-debug-controls
266 (fn [world]
267 (.setTimer world (RatchetTimer. 60))
268 (position-camera
269 world (Vector3f. -0.13217318, 5.816415, -5.3089414)
270 (Quaternion. 0.55685693, 0.0042774677, -0.0028673497, 0.83059245))
272 (light-up-everything world)
273 (enable-debug world)
274 (add-camera! world
275 (add-eye! creature
276 (.getChild
277 (.getChild creature "eyes") "eye"))
278 (comp (view-image) BufferedImage!))
280 (if record?
281 (Capture/captureVideo
282 world (File. base "main")))
283 (if record?
284 (Capture/captureAudio
285 world (File. base "main.wav"))))
286 (fn [world tpf]
287 (prop-display
288 (prop)
289 (if record? (File. base "proprio")))
290 (touch-display
291 (map #(% (.getRootNode world)) touch)
292 (if record? (File. base "touch")))
293 (vision-display
294 (map #(% world) vision)
295 (if record? (File. base "vision")))
296 (hearing-display
297 (map #(% world) hearing)
298 (if record? (File. base "hearing")))
299 (muscle-display
300 (control-script muscles)
301 (if record? (File. base "muscle")))
303 (summon-ball world)
305 (.setLocalTranslation me (.getLocation (.getCamera world)))
306 (fix-display world))))))
307 #+end_src
309 ** ImageMagick / ffmpeg
311 Just a bunch of calls to imagemagick to arrange the data that
312 =test-everything!= produces.
314 #+name: magick-8
315 #+begin_src clojure
316 (ns cortex.video.magick8
317 (:import java.io.File)
318 (:use clojure.contrib.shell-out))
320 (comment
321 ;; list of touch targets
322 0 middle-11
323 1 middle-21
324 2 middle-31
325 3 pinky-11
326 4 pinky-21
327 5 pinky-31
328 6 pointer-11
329 7 pointer-21
330 8 pointer-31
331 9 ring-11
332 10 ring-21
333 11 ring-31
334 12 thumb-11
335 13 thumb-2.0011
338 ;; list of vision targets
339 0 :all
340 1 :green
341 2 :blue
342 3 :red
344 ;; list of proprio targets
345 0 middle-11 -> middle-21
346 1 middle-21 -> middle-31
347 2 thumb-11 -> thumb-2.0011
348 3 pointer-11 -> pointer-21
349 4 pointer-21 -> pointer-31
350 5 ring-21 -> ring-31
351 6 ring-11 -> ring-21
352 7 pinky-21 -> pinky-31
353 8 pinky-11 -> pinky-21
354 9 middle-11 -> palm1
355 10 pinky-11 -> palm1
356 11 palm1 -> pointer-11
357 12 palm1 -> ring-11
358 13 palm1 -> thumb-11
361 ;; list of muscle targets
362 0 :pointer-2-e
363 1 :pointer-2-f
364 2 :thumb-1
365 3 :thumb-1
366 4 :pointer-1-e
367 5 :pointer-1-f
368 6 :thumb-2-e
369 7 :thumb-2-f
370 8 :middle-1-e
371 9 :middle-1-f
372 10 :pointer-3-f
373 11 :pointer-3-e
374 12 :middle-2-e
375 13 :middle-2-f
376 14 :middle-3-f
377 15 :middle-3-e
378 16 :pinky-2-e
379 17 :pinky-2-f
380 18 :pinky-3-f
381 19 :pinky-3-e
382 20 :ring-3-e
383 21 :ring-3-f
384 22 :ring-2-f
385 23 :ring-2-e
386 24 :ring-1-e
387 25 :ring-1-f
388 26 :thumb-1-e
389 27 :thumb-1-f
390 28 :pinky-1-f
391 29 :pinky-1-e
392 )
394 (def base (File. "/home/r/proj/cortex/render/hand"))
396 (defn prepare-muscle [muscle]
397 ["(" muscle "-rotate" "90" "-scale" "15x60!" ")"])
399 (defn prepare-touch [touch]
400 ["(" touch "-rotate" "180" ")"])
402 (defn generate-top-finger [tip-flexor tip-extensor tip
403 joint-2-3
404 mid-flexor mid-extensor mid
405 joint-1-2]
406 ["("
407 "-size" "113x357" "xc:transparent"
408 (prepare-muscle tip-flexor) "-geometry" "+0+7" "-composite"
409 (prepare-muscle tip-extensor) "-geometry" "+98+7" "-composite"
410 (prepare-touch tip) "-geometry" "+18+0" "-composite"
412 joint-2-3 "-geometry" "+32+79" "-composite"
414 (prepare-muscle mid-flexor) "-geometry" "+19+131" "-composite"
415 (prepare-muscle mid-extensor) "-geometry" "+80+131" "-composite"
416 (prepare-touch mid) "-geometry" "+39+133" "-composite"
418 joint-1-2 "-geometry" "+32+193" "-composite"
419 ")"])
421 (defn file-names [#^File dir]
422 (map #(.getCanonicalPath %) (next (sort (file-seq dir)))))
424 (defn file-groups [& paths]
425 (apply (partial map list )
426 (map (comp file-names #(File. base %))
427 paths)))
429 (defn pinky []
430 (file-groups
431 "muscle/18"
432 "muscle/19"
433 "touch/5"
434 "proprio/7"
436 "muscle/17"
437 "muscle/16"
438 "touch/4"
439 "proprio/8"
441 "muscle/28"
442 "muscle/29"
443 "touch/3"
444 "proprio/10"))
446 (defn ring []
447 (file-groups
448 "muscle/21"
449 "muscle/20"
450 "touch/11"
451 "proprio/5"
453 "muscle/22"
454 "muscle/23"
455 "touch/10"
456 "proprio/6"
458 "muscle/25"
459 "muscle/24"
460 "touch/9"
461 "proprio/12"))
463 (defn middle []
464 (file-groups
465 "muscle/14"
466 "muscle/15"
467 "touch/2"
468 "proprio/1"
470 "muscle/13"
471 "muscle/12"
472 "touch/1"
473 "proprio/0"
475 "muscle/9"
476 "muscle/8"
477 "touch/0"
478 "proprio/9"))
480 (defn pointer []
481 (file-groups
482 "muscle/10"
483 "muscle/11"
484 "touch/8"
485 "proprio/4"
487 "muscle/1"
488 "muscle/0"
489 "touch/7"
490 "proprio/3"
492 "muscle/5"
493 "muscle/4"
494 "touch/6"
495 "proprio/11"))
497 (defn thumb []
498 (file-groups
499 "muscle/7"
500 "muscle/6"
501 "touch/13"
502 "proprio/2"
504 "muscle/27"
505 "muscle/26"
506 "muscle/3"
507 "muscle/2"
508 "touch/12"
509 "proprio/13"))
511 (defn generate-finger
512 [tip-flexor tip-extensor tip
513 joint-2-3
514 mid-flexor mid-extensor mid
515 joint-1-2
516 base-flexor base-extensor base
517 joint-palm-1]
518 ["("
519 "-size" "113x357" "xc:transparent"
520 (generate-top-finger
521 tip-flexor tip-extensor tip
522 joint-2-3
523 mid-flexor mid-extensor mid
524 joint-1-2) "-geometry" "+0+0" "-composite"
525 (prepare-muscle base-flexor) "-geometry" "+19+245" "-composite"
526 (prepare-muscle base-extensor) "-geometry" "+80+245" "-composite"
527 (prepare-touch base) "-geometry" "+39+247" "-composite"
528 joint-palm-1 "-geometry" "+32+307" "-composite"
529 ")"])
531 (defn generate-thumb
532 [tip-flexor tip-extensor tip
533 joint-1-2
534 mid-flexor mid-extensor mid-flexor-2 mid-extensor-2 mid
535 joint-palm-1]
536 ["("
537 "-size" "113x357" "xc:transparent"
538 (generate-top-finger
539 tip-flexor tip-extensor tip
540 joint-1-2
541 mid-flexor mid-extensor mid
542 joint-palm-1) "-geometry" "+0+0" "-composite"
543 (prepare-muscle mid-flexor-2) "-geometry" "+2+131" "-composite"
544 (prepare-muscle mid-extensor-2) "-geometry" "+100+131" "-composite"
545 ")"])
547 (defn generate-hand
548 [pinky-pieces
549 ring-pieces
550 middle-pieces
551 pointer-pieces
552 thumb-pieces]
553 ["("
554 "-size" "688x769" "xc:transparent"
555 (apply generate-finger pinky-pieces)
556 "-geometry" "+0+195" "-composite"
557 (apply generate-finger ring-pieces)
558 "-geometry" "+111+100" "-composite"
559 (apply generate-finger middle-pieces)
560 "-geometry" "+228+0" "-composite"
561 "(" (apply generate-thumb thumb-pieces) "-background" "#00000000"
562 "-rotate" "45" ")"
563 "-geometry" "+300+420" "-composite"
564 (apply generate-finger pointer-pieces)
565 "-geometry" "+350+96" "-composite"
566 ")"])
568 (defn generate-vision
569 [all green blue red]
570 ["("
571 "-size" "204x192" "xc:transparent"
572 all "-geometry" "+0+0" "-composite"
573 green "-geometry" "+113+0" "-composite"
574 blue "-geometry" "+0+105" "-composite"
575 red "-geometry" "+113+105" "-composite"
576 ")"])
578 (def test-muscle (File. base "muscle/0/0000000.png"))
579 (def test-proprio (File. base "proprio/0/0000000.png"))
580 (def test-tip (File. base "touch/2/0000000.png"))
581 (def test-mid (File. base "touch/0/0000000.png"))
582 (def test-vision (File. base "vision/0/0000000.png"))
583 (def test-hearing (File. base "hearing/0/0000000.png"))
584 (def test-main (File. base "main/0000000.png"))
586 (def test-target (File. base "output.png"))
588 (def background (File. base "background.png"))
590 (use 'clojure.contrib.shell-out)
592 (defn vision []
593 (file-groups
594 "vision/0"
595 "vision/1"
596 "vision/2"
597 "vision/3"))
599 (defn hearing []
600 (file-names (File. base "hearing/0")))
602 (defn main []
603 (file-names (File. base "main")))
605 (defn targets [dest max]
606 (map
607 (comp #(.getCanonicalPath %)
608 #(File. (str base dest (format "%07d.png" %))))
609 (range max)))
612 (defn final-image [main [all red green blue] hearing
613 pinky ring middle pointer thumb target]
614 (println target)
615 (apply
616 sh
617 (flatten
618 ["convert"
619 (.getCanonicalPath background)
621 (generate-hand pinky ring middle pointer thumb)
622 "-geometry" "+809+22" "-composite"
624 (generate-vision all red green blue)
625 "-geometry" "+974+599" "-composite"
627 hearing
628 "-geometry" "+784+819" "-composite"
630 main
631 "-geometry" "+78+202" "-composite"
633 target])))
635 (defn combine-files []
636 (dorun
637 (pmap final-image
638 (main)
639 (vision)
640 (hearing)
641 (pinky)
642 (ring)
643 (middle)
644 (pointer)
645 (thumb)
646 (targets "/out/" (count (main))))))
648 (defn subtitles []
649 (file-names (File. base "subs")))
651 (defn outs []
652 (file-names (File. base "out")))
655 (defn mix-subtitles []
656 (let [subs (subtitles)
657 targets (targets "/out-subs/" (count subs))
658 overlay (.getCanonicalPath (File. base "output.png"))]
659 (dorun
660 (pmap
661 (fn [sub target]
662 (sh
663 "convert"
664 overlay
665 sub "-geometry" "+0+0" "-composite"
666 target))
667 subs targets))))
669 (defn out-subtitles []
670 (file-names (File. base "out-subs")))
673 (defn insert-subtitles []
674 (let [subtitles (out-subtitles)
675 outs (outs)
676 targets (targets
677 "/final/"
678 (+ (count outs) (count subtitles)))]
679 (dorun
680 (pmap
681 #(sh "cp" %1 %2)
682 (concat subtitles outs) targets))))
684 (defn generate-final []
685 (combine-files)
686 (mix-subtitles)
687 (insert-subtitles))
688 #+end_src
690 #+begin_src sh :results silent
691 cd /home/r/proj/cortex/render/hand
693 sox --ignore-length main.wav main-delayed.wav delay 24
695 mogrify -resize 755x final/*
697 ffmpeg -r 60 -i final/%07d.png -i main-delayed.wav -b:a 128k \
698 -b:v 9000k -c:a libvorbis -c:v libtheora hand.ogg
699 #+end_src
702 * Source Listing
703 - [[../src/cortex/test/integration.clj][cortex.test.integration]]
704 - [[../src/cortex/video/magick8.clj][cortex.video.magick8]]
705 - [[../assets/Models/subtitles/hand.blend][subtitles/hand.blend]]
706 #+html: <ul> <li> <a href="../org/integration.org">This org file</a> </li> </ul>
707 - [[http://hg.bortreb.com ][source-repository]]
710 * COMMENT purgatory
711 #+begin_src clojure
712 (defn bullet-trans* []
713 (let [obj-a (box 1.5 0.5 0.5 :color ColorRGBA/Red
714 :position (Vector3f. 5 0 0)
715 :mass 90)
716 obj-b (sphere 0.5 :color ColorRGBA/Blue
717 :position (Vector3f. -5 0 0)
718 :mass 0)
719 control-a (.getControl obj-a RigidBodyControl)
720 control-b (.getControl obj-b RigidBodyControl)
721 move-up? (atom nil)
722 move-down? (atom nil)
723 move-left? (atom nil)
724 move-right? (atom nil)
725 roll-left? (atom nil)
726 roll-right? (atom nil)
727 force 100
728 swivel
729 (.toRotationMatrix
730 (doto (Quaternion.)
731 (.fromAngleAxis (/ Math/PI 2)
732 Vector3f/UNIT_X)))
733 x-move
734 (doto (Matrix3f.)
735 (.fromStartEndVectors Vector3f/UNIT_X
736 (.normalize (Vector3f. 1 1 0))))
738 timer (atom 0)]
739 (doto
740 (ConeJoint.
741 control-a control-b
742 (Vector3f. -8 0 0)
743 (Vector3f. 2 0 0)
744 ;;swivel swivel
745 ;;Matrix3f/IDENTITY Matrix3f/IDENTITY
746 x-move Matrix3f/IDENTITY
747 )
748 (.setCollisionBetweenLinkedBodys false)
749 (.setLimit (* 1 (/ Math/PI 4)) ;; twist
750 (* 1 (/ Math/PI 4)) ;; swing span in X-Y plane
751 (* 0 (/ Math/PI 4)))) ;; swing span in Y-Z plane
752 (world (nodify
753 [obj-a obj-b])
754 (merge standard-debug-controls
755 {"key-r" (fn [_ pressed?] (reset! move-up? pressed?))
756 "key-t" (fn [_ pressed?] (reset! move-down? pressed?))
757 "key-f" (fn [_ pressed?] (reset! move-left? pressed?))
758 "key-g" (fn [_ pressed?] (reset! move-right? pressed?))
759 "key-v" (fn [_ pressed?] (reset! roll-left? pressed?))
760 "key-b" (fn [_ pressed?] (reset! roll-right? pressed?))})
762 (fn [world]
763 (enable-debug world)
764 (set-gravity world Vector3f/ZERO)
765 )
767 (fn [world _]
769 (if @move-up?
770 (.applyForce control-a
771 (Vector3f. force 0 0)
772 (Vector3f. 0 0 0)))
773 (if @move-down?
774 (.applyForce control-a
775 (Vector3f. (- force) 0 0)
776 (Vector3f. 0 0 0)))
777 (if @move-left?
778 (.applyForce control-a
779 (Vector3f. 0 force 0)
780 (Vector3f. 0 0 0)))
781 (if @move-right?
782 (.applyForce control-a
783 (Vector3f. 0 (- force) 0)
784 (Vector3f. 0 0 0)))
786 (if @roll-left?
787 (.applyForce control-a
788 (Vector3f. 0 0 force)
789 (Vector3f. 0 0 0)))
790 (if @roll-right?
791 (.applyForce control-a
792 (Vector3f. 0 0 (- force))
793 (Vector3f. 0 0 0)))
795 (if (zero? (rem (swap! timer inc) 100))
796 (.attachChild
797 (.getRootNode world)
798 (sphere 0.05 :color ColorRGBA/Yellow
799 :physical? false :position
800 (.getWorldTranslation obj-a)))))
801 )
802 ))
804 (defn test-joint [joint]
805 (let [[origin top bottom floor] (world-setup joint)
806 control (.getControl top RigidBodyControl)
807 move-up? (atom false)
808 move-down? (atom false)
809 move-left? (atom false)
810 move-right? (atom false)
811 roll-left? (atom false)
812 roll-right? (atom false)
813 timer (atom 0)]
815 (world
816 (nodify [top bottom floor origin])
817 (merge standard-debug-controls
818 {"key-r" (fn [_ pressed?] (reset! move-up? pressed?))
819 "key-t" (fn [_ pressed?] (reset! move-down? pressed?))
820 "key-f" (fn [_ pressed?] (reset! move-left? pressed?))
821 "key-g" (fn [_ pressed?] (reset! move-right? pressed?))
822 "key-v" (fn [_ pressed?] (reset! roll-left? pressed?))
823 "key-b" (fn [_ pressed?] (reset! roll-right? pressed?))})
825 (fn [world]
826 (light-up-everything world)
827 (enable-debug world)
828 (set-gravity world (Vector3f. 0 0 0))
829 )
831 (fn [world _]
832 (if (zero? (rem (swap! timer inc) 100))
833 (do
834 ;; (println-repl @timer)
835 (.attachChild (.getRootNode world)
836 (sphere 0.05 :color ColorRGBA/Yellow
837 :position (.getWorldTranslation top)
838 :physical? false))
839 (.attachChild (.getRootNode world)
840 (sphere 0.05 :color ColorRGBA/LightGray
841 :position (.getWorldTranslation bottom)
842 :physical? false))))
844 (if @move-up?
845 (.applyTorque control
846 (.mult (.getPhysicsRotation control)
847 (Vector3f. 0 0 10))))
848 (if @move-down?
849 (.applyTorque control
850 (.mult (.getPhysicsRotation control)
851 (Vector3f. 0 0 -10))))
852 (if @move-left?
853 (.applyTorque control
854 (.mult (.getPhysicsRotation control)
855 (Vector3f. 0 10 0))))
856 (if @move-right?
857 (.applyTorque control
858 (.mult (.getPhysicsRotation control)
859 (Vector3f. 0 -10 0))))
860 (if @roll-left?
861 (.applyTorque control
862 (.mult (.getPhysicsRotation control)
863 (Vector3f. -1 0 0))))
864 (if @roll-right?
865 (.applyTorque control
866 (.mult (.getPhysicsRotation control)
867 (Vector3f. 1 0 0))))))))
868 #+end_src
872 * COMMENT generate source
873 #+begin_src clojure :tangle ../src/cortex/test/integration.clj
874 <<integration>>
875 <<integration-2>>
876 #+end_src
878 #+begin_src clojure :tangle ../src/cortex/video/magick8.clj
879 <<magick-8>>
880 #+end_src