view org/integration.org @ 386:ff0d8955711e

minor fix in movement.org, reviewed more journal articles.
author Robert McIntyre <rlm@mit.edu>
date Wed, 29 May 2013 17:17:08 -0400
parents 2c7fbcbd5ebb
children 4c37d39a3cf6
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 import 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
52 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.java.shell))
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.java.shell)
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/*
696 #+end_src
698 #+begin_src sh :results silent
699 cd /home/r/proj/cortex/render/hand
701 ffmpeg -r 60 -i final/%07d.png -i main-delayed.wav -b:a 128k \
702 -b:v 9000k -c:a libvorbis -c:v libtheora hand.ogg
703 #+end_src
705 * Source Listing
706 - [[../src/cortex/test/integration.clj][cortex.test.integration]]
707 - [[../src/cortex/video/magick8.clj][cortex.video.magick8]]
708 - [[../assets/Models/subtitles/hand.blend][subtitles/hand.blend]]
709 #+html: <ul> <li> <a href="../org/integration.org">This org file</a> </li> </ul>
710 - [[http://hg.bortreb.com ][source-repository]]
713 * COMMENT purgatory
714 #+begin_src clojure
715 (defn bullet-trans* []
716 (let [obj-a (box 1.5 0.5 0.5 :color ColorRGBA/Red
717 :position (Vector3f. 5 0 0)
718 :mass 90)
719 obj-b (sphere 0.5 :color ColorRGBA/Blue
720 :position (Vector3f. -5 0 0)
721 :mass 0)
722 control-a (.getControl obj-a RigidBodyControl)
723 control-b (.getControl obj-b RigidBodyControl)
724 move-up? (atom nil)
725 move-down? (atom nil)
726 move-left? (atom nil)
727 move-right? (atom nil)
728 roll-left? (atom nil)
729 roll-right? (atom nil)
730 force 100
731 swivel
732 (.toRotationMatrix
733 (doto (Quaternion.)
734 (.fromAngleAxis (/ Math/PI 2)
735 Vector3f/UNIT_X)))
736 x-move
737 (doto (Matrix3f.)
738 (.fromStartEndVectors Vector3f/UNIT_X
739 (.normalize (Vector3f. 1 1 0))))
741 timer (atom 0)]
742 (doto
743 (ConeJoint.
744 control-a control-b
745 (Vector3f. -8 0 0)
746 (Vector3f. 2 0 0)
747 ;;swivel swivel
748 ;;Matrix3f/IDENTITY Matrix3f/IDENTITY
749 x-move Matrix3f/IDENTITY
750 )
751 (.setCollisionBetweenLinkedBodys false)
752 (.setLimit (* 1 (/ Math/PI 4)) ;; twist
753 (* 1 (/ Math/PI 4)) ;; swing span in X-Y plane
754 (* 0 (/ Math/PI 4)))) ;; swing span in Y-Z plane
755 (world (nodify
756 [obj-a obj-b])
757 (merge standard-debug-controls
758 {"key-r" (fn [_ pressed?] (reset! move-up? pressed?))
759 "key-t" (fn [_ pressed?] (reset! move-down? pressed?))
760 "key-f" (fn [_ pressed?] (reset! move-left? pressed?))
761 "key-g" (fn [_ pressed?] (reset! move-right? pressed?))
762 "key-v" (fn [_ pressed?] (reset! roll-left? pressed?))
763 "key-b" (fn [_ pressed?] (reset! roll-right? pressed?))})
765 (fn [world]
766 (enable-debug world)
767 (set-gravity world Vector3f/ZERO)
768 )
770 (fn [world _]
772 (if @move-up?
773 (.applyForce control-a
774 (Vector3f. force 0 0)
775 (Vector3f. 0 0 0)))
776 (if @move-down?
777 (.applyForce control-a
778 (Vector3f. (- force) 0 0)
779 (Vector3f. 0 0 0)))
780 (if @move-left?
781 (.applyForce control-a
782 (Vector3f. 0 force 0)
783 (Vector3f. 0 0 0)))
784 (if @move-right?
785 (.applyForce control-a
786 (Vector3f. 0 (- force) 0)
787 (Vector3f. 0 0 0)))
789 (if @roll-left?
790 (.applyForce control-a
791 (Vector3f. 0 0 force)
792 (Vector3f. 0 0 0)))
793 (if @roll-right?
794 (.applyForce control-a
795 (Vector3f. 0 0 (- force))
796 (Vector3f. 0 0 0)))
798 (if (zero? (rem (swap! timer inc) 100))
799 (.attachChild
800 (.getRootNode world)
801 (sphere 0.05 :color ColorRGBA/Yellow
802 :physical? false :position
803 (.getWorldTranslation obj-a)))))
804 )
805 ))
807 (defn test-joint [joint]
808 (let [[origin top bottom floor] (world-setup joint)
809 control (.getControl top RigidBodyControl)
810 move-up? (atom false)
811 move-down? (atom false)
812 move-left? (atom false)
813 move-right? (atom false)
814 roll-left? (atom false)
815 roll-right? (atom false)
816 timer (atom 0)]
818 (world
819 (nodify [top bottom floor origin])
820 (merge standard-debug-controls
821 {"key-r" (fn [_ pressed?] (reset! move-up? pressed?))
822 "key-t" (fn [_ pressed?] (reset! move-down? pressed?))
823 "key-f" (fn [_ pressed?] (reset! move-left? pressed?))
824 "key-g" (fn [_ pressed?] (reset! move-right? pressed?))
825 "key-v" (fn [_ pressed?] (reset! roll-left? pressed?))
826 "key-b" (fn [_ pressed?] (reset! roll-right? pressed?))})
828 (fn [world]
829 (light-up-everything world)
830 (enable-debug world)
831 (set-gravity world (Vector3f. 0 0 0))
832 )
834 (fn [world _]
835 (if (zero? (rem (swap! timer inc) 100))
836 (do
837 ;; (println-repl @timer)
838 (.attachChild (.getRootNode world)
839 (sphere 0.05 :color ColorRGBA/Yellow
840 :position (.getWorldTranslation top)
841 :physical? false))
842 (.attachChild (.getRootNode world)
843 (sphere 0.05 :color ColorRGBA/LightGray
844 :position (.getWorldTranslation bottom)
845 :physical? false))))
847 (if @move-up?
848 (.applyTorque control
849 (.mult (.getPhysicsRotation control)
850 (Vector3f. 0 0 10))))
851 (if @move-down?
852 (.applyTorque control
853 (.mult (.getPhysicsRotation control)
854 (Vector3f. 0 0 -10))))
855 (if @move-left?
856 (.applyTorque control
857 (.mult (.getPhysicsRotation control)
858 (Vector3f. 0 10 0))))
859 (if @move-right?
860 (.applyTorque control
861 (.mult (.getPhysicsRotation control)
862 (Vector3f. 0 -10 0))))
863 (if @roll-left?
864 (.applyTorque control
865 (.mult (.getPhysicsRotation control)
866 (Vector3f. -1 0 0))))
867 (if @roll-right?
868 (.applyTorque control
869 (.mult (.getPhysicsRotation control)
870 (Vector3f. 1 0 0))))))))
871 #+end_src
875 * COMMENT generate source
876 #+begin_src clojure :tangle ../src/cortex/test/integration.clj
877 <<integration>>
878 <<integration-2>>
879 #+end_src
881 #+begin_src clojure :tangle ../src/cortex/video/magick8.clj
882 <<magick-8>>
883 #+end_src