Mercurial > cortex
comparison org/vision.org @ 338:d37ccb6c888f
determined that the laptop cannot support arbitray dimensions when creating cameras. will need to use desktop from here on out when doing actual simulations.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Fri, 20 Jul 2012 16:40:25 -0500 |
parents | fdc98824d69b |
children | 4f5a5d5f1613 |
comparison
equal
deleted
inserted
replaced
337:fdc98824d69b | 338:d37ccb6c888f |
---|---|
147 #+begin_src clojure | 147 #+begin_src clojure |
148 (in-ns 'cortex.vision) | 148 (in-ns 'cortex.vision) |
149 | 149 |
150 (defn add-eye! | 150 (defn add-eye! |
151 "Create a Camera centered on the current position of 'eye which | 151 "Create a Camera centered on the current position of 'eye which |
152 follows the closest physical node in 'creature and sends visual | 152 follows the closest physical node in 'creature. The camera will |
153 data to 'continuation. The camera will point in the X direction and | 153 point in the X direction and use the Z vector as up as determined |
154 use the Z vector as up as determined by the rotation of these | 154 by the rotation of these vectors in blender coordinate space. Use |
155 vectors in blender coordinate space. Use XZY rotation for the node | 155 XZY rotation for the node in blender." |
156 in blender." | |
157 [#^Node creature #^Spatial eye] | 156 [#^Node creature #^Spatial eye] |
158 (let [target (closest-node creature eye) | 157 (let [target (closest-node creature eye) |
159 [cam-width cam-height] (eye-dimensions eye) | 158 [cam-width cam-height] |
159 ;;[640 480] ;; graphics card on laptop doesn't support | |
160 ;; arbitray dimensions. | |
161 (eye-dimensions eye) | |
160 cam (Camera. cam-width cam-height) | 162 cam (Camera. cam-width cam-height) |
161 rot (.getWorldRotation eye)] | 163 rot (.getWorldRotation eye)] |
162 (.setLocation cam (.getWorldTranslation eye)) | 164 (.setLocation cam (.getWorldTranslation eye)) |
163 (.lookAtDirection | 165 (.lookAtDirection |
164 cam ; this part is not a mistake and | 166 cam ; this part is not a mistake and |
165 (.mult rot Vector3f/UNIT_X) ; is consistent with using Z in | 167 (.mult rot Vector3f/UNIT_X) ; is consistent with using Z in |
166 (.mult rot Vector3f/UNIT_Y)) ; blender as the UP vector. | 168 (.mult rot Vector3f/UNIT_Y)) ; blender as the UP vector. |
167 (.setFrustumPerspective | 169 (.setFrustumPerspective |
168 cam 45 (/ (.getWidth cam) (.getHeight cam)) 1 1000) | 170 cam (float 45) |
171 (float (/ (.getWidth cam) (.getHeight cam))) | |
172 (float 1) | |
173 (float 1000)) | |
169 (bind-sense target cam) cam)) | 174 (bind-sense target cam) cam)) |
170 #+end_src | 175 #+end_src |
176 | |
177 #+results: add-eye | |
178 : #'cortex.vision/add-eye! | |
171 | 179 |
172 Here, the camera is created based on metadata on the eye-node and | 180 Here, the camera is created based on metadata on the eye-node and |
173 attached to the nearest physical object with =bind-sense= | 181 attached to the nearest physical object with =bind-sense= |
174 ** The Retina | 182 ** The Retina |
175 | 183 |
278 Then, add the camera created by =add-eye!= to the simulation by | 286 Then, add the camera created by =add-eye!= to the simulation by |
279 creating a new viewport. | 287 creating a new viewport. |
280 | 288 |
281 #+name: add-camera | 289 #+name: add-camera |
282 #+begin_src clojure | 290 #+begin_src clojure |
291 (in-ns 'cortex.vision) | |
283 (defn add-camera! | 292 (defn add-camera! |
284 "Add a camera to the world, calling continuation on every frame | 293 "Add a camera to the world, calling continuation on every frame |
285 produced." | 294 produced." |
286 [#^Application world camera continuation] | 295 [#^Application world camera continuation] |
287 (let [width (.getWidth camera) | 296 (let [width (.getWidth camera) |
292 (.setClearFlags true true true) | 301 (.setClearFlags true true true) |
293 (.setBackgroundColor ColorRGBA/Black) | 302 (.setBackgroundColor ColorRGBA/Black) |
294 (.addProcessor (vision-pipeline continuation)) | 303 (.addProcessor (vision-pipeline continuation)) |
295 (.attachScene (.getRootNode world))))) | 304 (.attachScene (.getRootNode world))))) |
296 #+end_src | 305 #+end_src |
306 | |
307 #+results: add-camera | |
308 : #'cortex.vision/add-camera! | |
297 | 309 |
298 | 310 |
299 The eye's continuation function should register the viewport with the | 311 The eye's continuation function should register the viewport with the |
300 simulation the first time it is called, use the CPU to extract the | 312 simulation the first time it is called, use the CPU to extract the |
301 appropriate pixels from the rendered image and weight them by each | 313 appropriate pixels from the rendered image and weight them by each |
543 | 555 |
544 (defn colored-cannon-ball [color] | 556 (defn colored-cannon-ball [color] |
545 (comp #(change-color % color) | 557 (comp #(change-color % color) |
546 (fire-cannon-ball))) | 558 (fire-cannon-ball))) |
547 | 559 |
560 (defn gen-worm | |
561 "create a creature acceptable for testing as a replacement for the | |
562 worm." | |
563 [] | |
564 (nodify | |
565 "worm" | |
566 [(nodify | |
567 "eyes" | |
568 [(doto | |
569 (Node. "eye1") | |
570 (.setLocalTranslation (Vector3f. 0 -1.1 0)) | |
571 (.setUserData | |
572 | |
573 "eye" | |
574 "(let [retina | |
575 \"Models/test-creature/retina-small.png\"] | |
576 {:all retina :red retina | |
577 :green retina :blue retina})"))]) | |
578 (box | |
579 0.2 0.2 0.2 | |
580 :name "worm-segment" | |
581 :position (Vector3f. 0 0 0) | |
582 :color ColorRGBA/Orange)])) | |
583 | |
584 | |
585 | |
548 (defn test-worm-vision | 586 (defn test-worm-vision |
549 "Testing vision: | 587 "Testing vision: |
550 You should see the worm suspended in mid-air, looking down at a | 588 You should see the worm suspended in mid-air, looking down at a |
551 table. There are four small displays, one each for red, green blue, | 589 table. There are four small displays, one each for red, green blue, |
552 and gray channels. You can fire balls of various colors, and the | 590 and gray channels. You can fire balls of various colors, and the |
555 Keys: | 593 Keys: |
556 r : fire red-ball | 594 r : fire red-ball |
557 b : fire blue-ball | 595 b : fire blue-ball |
558 g : fire green-ball | 596 g : fire green-ball |
559 <space> : fire white ball" | 597 <space> : fire white ball" |
560 | 598 |
561 ([] (test-worm-vision false)) | 599 ([] (test-worm-vision false)) |
562 ([record?] | 600 ([record?] |
563 (let [the-worm (doto (worm)(body!)) | 601 (let [the-worm (doto (worm)(body!)) |
564 vision (vision! the-worm) | 602 ;;the-worm (gen-worm) |
603 ;;vision (vision! the-worm) | |
565 ;;vision-display (view-vision) | 604 ;;vision-display (view-vision) |
566 fix-display (gen-fix-display) | 605 ;;fix-display (gen-fix-display) |
567 me (sphere 0.5 :color ColorRGBA/Blue :physical? false) | 606 me (sphere 0.5 :color ColorRGBA/Blue :physical? false) |
568 x-axis | 607 x-axis |
569 (box 1 0.01 0.01 :physical? false :color ColorRGBA/Red | 608 (box 1 0.01 0.01 :physical? false :color ColorRGBA/Red |
570 :position (Vector3f. 0 -5 0)) | 609 :position (Vector3f. 0 -5 0)) |
571 y-axis | 610 y-axis |
572 (box 0.01 1 0.01 :physical? false :color ColorRGBA/Green | 611 (box 0.01 1 0.01 :physical? false :color ColorRGBA/Green |
573 :position (Vector3f. 0 -5 0)) | 612 :position (Vector3f. 0 -5 0)) |
574 z-axis | 613 z-axis |
575 (box 0.01 0.01 1 :physical? false :color ColorRGBA/Blue | 614 (box 0.01 0.01 1 :physical? false :color ColorRGBA/Blue |
576 :position (Vector3f. 0 -5 0)) | 615 :position (Vector3f. 0 -5 0)) |
577 timer (RatchetTimer. 60)] | 616 timer (RatchetTimer. 60) |
617 ] | |
578 | 618 |
579 (world | 619 (world |
580 (nodify [(floor) the-worm x-axis y-axis z-axis me]) | 620 (nodify [(floor) the-worm x-axis y-axis z-axis me]) |
581 (assoc standard-debug-controls | 621 standard-debug-controls |
582 "key-r" (colored-cannon-ball ColorRGBA/Red) | 622 ;;"key-r" (colored-cannon-ball ColorRGBA/Red) |
583 "key-b" (colored-cannon-ball ColorRGBA/Blue) | 623 ;;"key-b" (colored-cannon-ball ColorRGBA/Blue) |
584 "key-g" (colored-cannon-ball ColorRGBA/Green)) | 624 ;;"key-g" (colored-cannon-ball ColorRGBA/Green)) |
625 | |
585 (fn [world] | 626 (fn [world] |
586 (light-up-everything world) | 627 (let |
587 ;;(speed-up world) | 628 [eye-pos (Vector3f. 0 30 0) |
588 (.setTimer world timer) | 629 cam (doto |
589 ;;(display-dilated-time world timer) | 630 (.clone (.getCamera world)) |
590 ;; add a view from the worm's perspective | 631 (.setLocation eye-pos) |
591 (if record? | 632 (.lookAt Vector3f/ZERO |
592 (Capture/captureVideo | 633 Vector3f/UNIT_X)) |
634 | |
635 bad-cam (doto | |
636 ;;saved-cam | |
637 ;;(.clone (.getCamera world)) | |
638 | |
639 (com.jme3.renderer.Camera. 640 480) | |
640 (.setFrustumPerspective | |
641 (float 45) | |
642 (float (/ 640 480)) | |
643 (float 1) | |
644 (float 1000)) | |
645 | |
646 (.setLocation eye-pos) | |
647 (.lookAt Vector3f/ZERO | |
648 Vector3f/UNIT_X)) | |
649 | |
650 bad-cam (add-eye! the-worm (first (eyes the-worm))) | |
651 ] | |
652 | |
653 | |
654 (light-up-everything world) | |
655 ;;(speed-up world) | |
656 (.setTimer world timer) | |
657 ;;(display-dilated-time world timer) | |
658 ;; add a view from the worm's perspective | |
659 (if record? | |
660 (Capture/captureVideo | |
661 world | |
662 (File. | |
663 "/home/r/proj/cortex/render/worm-vision/main-view"))) | |
664 | |
665 (bind-sense (last (node-seq the-worm)) cam) | |
666 (bind-sense (last (node-seq the-worm)) bad-cam) | |
667 | |
668 (add-camera! | |
593 world | 669 world |
594 (File. | 670 bad-cam |
595 "/home/r/proj/cortex/render/worm-vision/main-view"))) | 671 (comp |
596 | 672 (view-image |
597 (add-camera! | 673 (if record? |
598 world | 674 (File. |
599 (add-eye! the-worm | 675 "/home/r/proj/cortex/render/worm-vision/worm-view"))) |
600 (.getChild | 676 BufferedImage!)) |
601 (.getChild the-worm "eyes") "eye")) | 677 |
602 (comp | 678 |
603 (view-image | 679 |
604 (if record? | 680 (add-camera! |
605 (File. | 681 world cam |
606 "/home/r/proj/cortex/render/worm-vision/worm-view"))) | 682 (comp |
607 BufferedImage!)) | 683 (view-image |
608 (set-gravity world Vector3f/ZERO)) | 684 (if record? |
685 (File. | |
686 "/home/r/proj/cortex/render/worm-vision/worm-view"))) | |
687 BufferedImage!)) | |
688 (set-gravity world Vector3f/ZERO) | |
689 (add-camera! world (.getCamera world) no-op) | |
690 | |
691 (println-repl cam "\n" bad-cam) | |
692 | |
693 )) | |
609 | 694 |
610 (fn [world _ ] | 695 (fn [world _ ] |
611 (.setLocalTranslation me (.getLocation (.getCamera world))) | 696 (.setLocalTranslation me (.getLocation (.getCamera world))) |
612 ;; (vision-display | 697 ;; (vision-display |
613 ;; (map #(% world) vision) | 698 ;; (map #(% world) vision) |
614 ;; (if record? | 699 ;; (if record? |
615 ;; (File. "/home/r/proj/cortex/render/worm-vision"))) | 700 ;; (File. "/home/r/proj/cortex/render/worm-vision"))) |
616 (fix-display world) | 701 ;;(fix-display world) |
617 ))))) | 702 ))))) |
618 #+end_src | 703 #+end_src |
619 | 704 |
620 #+RESULTS: test-2 | 705 #+RESULTS: test-2 |
621 : #'cortex.test.vision/test-worm-vision | 706 : #'cortex.test.vision/test-worm-vision |