comparison org/body.org @ 205:d3a2abfac405

fixed tangling in body.org, added dialated time HUD display in cortex.util
author Robert McIntyre <rlm@mit.edu>
date Thu, 09 Feb 2012 04:15:09 -0700
parents 162b24a82712
children df46a609fed9
comparison
equal deleted inserted replaced
204:162b24a82712 205:d3a2abfac405
58 #+attr_html: width="755" 58 #+attr_html: width="755"
59 [[../images/hand-screenshot0.png]] 59 [[../images/hand-screenshot0.png]]
60 60
61 If we load it directly into jMonkeyEngine, we get this: 61 If we load it directly into jMonkeyEngine, we get this:
62 62
63 #+name: test-0 63 #+name: test-1
64 #+begin_src clojure 64 #+begin_src clojure
65 (ns cortex.test.body
66 (:use (cortex world util body))
67 (:import (com.aurellem.capture Capture RatchetTimer)
68 (com.jme3.math Quaternion Vector3f)
69 java.io.File))
70
71 (def hand-path "Models/test-creature/hand.blend") 65 (def hand-path "Models/test-creature/hand.blend")
72 66
73 (defn hand [] (load-blender-model hand-path)) 67 (defn hand [] (load-blender-model hand-path))
74 68
75 (defn setup [world] 69 (defn setup [world]
148 142
149 =(physical!)= iterates through a creature's node structure, creating 143 =(physical!)= iterates through a creature's node structure, creating
150 CollisionShapes for each geometry with the mass specified in that 144 CollisionShapes for each geometry with the mass specified in that
151 geometry's meta-data. 145 geometry's meta-data.
152 146
153 #+name: test-1 147 #+name: test-2
154 #+begin_src clojure 148 #+begin_src clojure
155 (in-ns 'cortex.test.body) 149 (in-ns 'cortex.test.body)
156 150
157 (def normal-gravity 151 (def normal-gravity
158 {"key-g" (fn [world _] 152 {"key-g" (fn [world _]
407 #+end_src 401 #+end_src
408 402
409 Creating joints is now a matter applying =(connect)= to each joint 403 Creating joints is now a matter applying =(connect)= to each joint
410 node. 404 node.
411 405
406 #+name: joints-5
412 #+begin_src clojure 407 #+begin_src clojure
413 (defn joints! 408 (defn joints!
414 "Connect the solid parts of the creature with physical joints. The 409 "Connect the solid parts of the creature with physical joints. The
415 joints are taken from the \"joints\" node in the creature." 410 joints are taken from the \"joints\" node in the creature."
416 [#^Node creature] 411 [#^Node creature]
425 420
426 ** Round 3 421 ** Round 3
427 422
428 Now we can test the hand in all its glory. 423 Now we can test the hand in all its glory.
429 424
425 #+name: test-3
430 #+begin_src clojure 426 #+begin_src clojure
431 (in-ns 'cortex.test.body) 427 (in-ns 'cortex.test.body)
432 428
433 (def debug-control 429 (def debug-control
434 {"key-h" (fn [world val] 430 {"key-h" (fn [world val]
435 (if val (enable-debug world))) 431 (if val (enable-debug world)))
436 432 "key-u" (fn [world _] (set-gravity world Vector3f/ZERO))})
437 "key-u" (fn [world _] (set-gravity world Vector3f/ZERO))
438 })
439 433
440 (defn test-three [] 434 (defn test-three []
441 (world (nodify 435 (world (nodify
442 [(doto (hand) 436 [(doto (hand)
443 (physical!) 437 (physical!)
444 (joints!) ) 438 (joints!))
445 (floor)]) 439 (floor)])
446 (merge standard-debug-controls debug-control 440 (merge standard-debug-controls debug-control
447 normal-gravity) 441 normal-gravity)
448 (comp 442 (comp
449 #(Capture/captureVideo 443 #(Capture/captureVideo
453 no-op)) 447 no-op))
454 #+end_src 448 #+end_src
455 449
456 =(physical!)= makes the hand solid, then =(joints!)= connects each 450 =(physical!)= makes the hand solid, then =(joints!)= connects each
457 piece together. 451 piece together.
458
459 452
460 #+begin_html 453 #+begin_html
461 <div class="figure"> 454 <div class="figure">
462 <center> 455 <center>
463 <video controls="controls" width="640"> 456 <video controls="controls" width="640">
476 * Wrap-Up! 469 * Wrap-Up!
477 470
478 It is convienent to combine =(physical!)= and =(joints!)= into one 471 It is convienent to combine =(physical!)= and =(joints!)= into one
479 function that completely creates the creature's physical body. 472 function that completely creates the creature's physical body.
480 473
481 #+name: joints-4 474 #+name: joints-6
482 #+begin_src clojure 475 #+begin_src clojure
483 (defn body! 476 (defn body!
484 "Endow the creature with a physical body connected with joints. The 477 "Endow the creature with a physical body connected with joints. The
485 particulars of the joints and the masses of each pody part are 478 particulars of the joints and the masses of each pody part are
486 determined in blender." 479 determined in blender."
487 [#^Node creature] 480 [#^Node creature]
488 (physical! creature) 481 (physical! creature)
489 (joints! creature)) 482 (joints! creature))
490 #+end_src 483 #+end_src
491 484
485 * The Worm
486
487 Going forward, I will use a model that is less complicated than the
488 hand. It has two segments and one joint, and I call it the worm. All
489 of the senses described in the following posts will be applied to this
490 worm.
491
492 #+name: test-4
493 #+begin_src clojure
494 (in-ns 'cortex.test.body)
495
496 (defn worm-1 []
497 (let [timer (RatchetTimer. 60)]
498 (world
499 (nodify
500 [(doto
501 (load-blender-model
502 "Models/test-creature/worm.blend")
503 (body!))
504 (floor)])
505 (merge standard-debug-controls debug-control)
506 #(do
507 (speed-up %)
508 (light-up-everything %)
509 (.setTimer % timer)
510 (cortex.util/display-dialated-time % timer)
511 (Capture/captureVideo
512 % (File. "/home/r/proj/cortex/render/body/4")))
513 no-op)))
514 #+end_src
515
516 #+begin_html
517 <div class="figure">
518 <center>
519 <video controls="controls" width="640">
520 <source src="../video/worm-1.ogg" type="video/ogg"
521 preload="none" poster="../images/aurellem-1280x480.png" />
522 </video>
523 </center>
524 <p>This worm model will be the platform onto which future senses will
525 be grafted.</p>
526 </div>
527 #+end_html
528
492 * Bookkeeping 529 * Bookkeeping
493 530
494 Header; here for completeness. 531 Header; here for completeness.
495 532
496 #+name: body-0 533 #+name: body-header
497 #+begin_src clojure 534 #+begin_src clojure
498 (ns cortex.body 535 (ns cortex.body
499 "Assemble a physical creature using the definitions found in a 536 "Assemble a physical creature using the definitions found in a
500 specially prepared blender file. Creates rigid bodies and joints so 537 specially prepared blender file. Creates rigid bodies and joints so
501 that a creature can have a physical presense in the simulation." 538 that a creature can have a physical presense in the simulation."
512 com.jme3.scene.Node 549 com.jme3.scene.Node
513 com.jme3.scene.Geometry 550 com.jme3.scene.Geometry
514 com.jme3.bullet.collision.shapes.HullCollisionShape)) 551 com.jme3.bullet.collision.shapes.HullCollisionShape))
515 #+end_src 552 #+end_src
516 553
554 #+name: test-header
555 #+begin_src clojure
556 (ns cortex.test.body
557 (:use (cortex world util body))
558 (:import
559 (com.aurellem.capture Capture RatchetTimer)
560 (com.jme3.math Quaternion Vector3f ColorRGBA)
561 java.io.File))
562 #+end_src
563
517 * Source 564 * Source
518 565
519 Dylan -- I'll fill these in later 566 Dylan -- I'll fill these in later
520 - cortex.body 567 - cortex.body
521 - cortex.test.body 568 - cortex.test.body
523 570
524 * COMMENT Examples 571 * COMMENT Examples
525 572
526 #+name: test-body 573 #+name: test-body
527 #+begin_src clojure 574 #+begin_src clojure
528 (ns cortex.test.body
529 (:use (cortex world util body))
530 (:require cortex.silly)
531 (:import
532 com.jme3.math.Vector3f
533 com.jme3.math.ColorRGBA
534 com.jme3.bullet.joints.Point2PointJoint
535 com.jme3.bullet.control.RigidBodyControl
536 com.jme3.system.NanoTimer
537 com.jme3.math.Quaternion))
538 575
539 (defn worm-segments 576 (defn worm-segments
540 "Create multiple evenly spaced box segments. They're fabulous!" 577 "Create multiple evenly spaced box segments. They're fabulous!"
541 [segment-length num-segments interstitial-space radius] 578 [segment-length num-segments interstitial-space radius]
542 (letfn [(nth-segment 579 (letfn [(nth-segment
1251 1288
1252 1289
1253 1290
1254 * COMMENT generate Source 1291 * COMMENT generate Source
1255 #+begin_src clojure :tangle ../src/cortex/body.clj 1292 #+begin_src clojure :tangle ../src/cortex/body.clj
1256 <<joints>> 1293 <<body-header>>
1294 <<body-1>>
1295 <<joints-2>>
1296 <<joints-3>>
1297 <<joints-4>>
1298 <<joints-5>>
1299 <<joints-6>>
1257 #+end_src 1300 #+end_src
1258 1301
1259 #+begin_src clojure :tangle ../src/cortex/test/body.clj 1302 #+begin_src clojure :tangle ../src/cortex/test/body.clj
1260 <<test-0>> 1303 <<test-header>>
1304 <<test-1>>
1305 <<test-2>>
1306 <<test-3>>
1307 <<test-4>>
1261 #+end_src 1308 #+end_src
1262 1309
1263 1310
1264 1311