comparison org/body.org @ 321:702b5c78c2de

gathered all the tests into (run-suite), which should make testing vastly easier.
author Robert McIntyre <rlm@mit.edu>
date Tue, 08 May 2012 08:22:19 -0500
parents bb3f8a4af87f
children 4f5a5d5f1613
comparison
equal deleted inserted replaced
320:52de8a36edde 321:702b5c78c2de
133 (RigidBodyControl. 133 (RigidBodyControl.
134 (HullCollisionShape. 134 (HullCollisionShape.
135 (.getMesh geom)) 135 (.getMesh geom))
136 (if-let [mass (meta-data geom "mass")] 136 (if-let [mass (meta-data geom "mass")]
137 (do 137 (do
138 (println-repl 138 ;;(println-repl
139 "setting" (.getName geom) "mass to" (float mass)) 139 ;; "setting" (.getName geom) "mass to" (float mass))
140 (float mass)) 140 (float mass))
141 (float 1)))] 141 (float 1)))]
142 (.addControl geom physics-control))) 142 (.addControl geom physics-control)))
143 (filter #(isa? (class %) Geometry ) 143 (filter #(isa? (class %) Geometry )
144 (node-seq creature))))) 144 (node-seq creature)))))
293 (fn [constraints & _] 293 (fn [constraints & _]
294 (:type constraints))) 294 (:type constraints)))
295 295
296 (defmethod joint-dispatch :point 296 (defmethod joint-dispatch :point
297 [constraints control-a control-b pivot-a pivot-b rotation] 297 [constraints control-a control-b pivot-a pivot-b rotation]
298 (println-repl "creating POINT2POINT joint") 298 ;;(println-repl "creating POINT2POINT joint")
299 ;; bullet's point2point joints are BROKEN, so we must use the 299 ;; bullet's point2point joints are BROKEN, so we must use the
300 ;; generic 6DOF joint instead of an actual Point2Point joint! 300 ;; generic 6DOF joint instead of an actual Point2Point joint!
301 301
302 ;; should be able to do this: 302 ;; should be able to do this:
303 (comment 303 (comment
306 control-b 306 control-b
307 pivot-a 307 pivot-a
308 pivot-b)) 308 pivot-b))
309 309
310 ;; but instead we must do this: 310 ;; but instead we must do this:
311 (println-repl "substituting 6DOF joint for POINT2POINT joint!") 311 ;;(println-repl "substituting 6DOF joint for POINT2POINT joint!")
312 (doto 312 (doto
313 (SixDofJoint. 313 (SixDofJoint.
314 control-a 314 control-a
315 control-b 315 control-b
316 pivot-a 316 pivot-a
319 (.setLinearLowerLimit Vector3f/ZERO) 319 (.setLinearLowerLimit Vector3f/ZERO)
320 (.setLinearUpperLimit Vector3f/ZERO))) 320 (.setLinearUpperLimit Vector3f/ZERO)))
321 321
322 (defmethod joint-dispatch :hinge 322 (defmethod joint-dispatch :hinge
323 [constraints control-a control-b pivot-a pivot-b rotation] 323 [constraints control-a control-b pivot-a pivot-b rotation]
324 (println-repl "creating HINGE joint") 324 ;;(println-repl "creating HINGE joint")
325 (let [axis 325 (let [axis
326 (if-let 326 (if-let
327 [axis (:axis constraints)] 327 [axis (:axis constraints)]
328 axis 328 axis
329 Vector3f/UNIT_X) 329 Vector3f/UNIT_X)
346 [constraints control-a control-b pivot-a pivot-b rotation] 346 [constraints control-a control-b pivot-a pivot-b rotation]
347 (let [limit-xz (:limit-xz constraints) 347 (let [limit-xz (:limit-xz constraints)
348 limit-xy (:limit-xy constraints) 348 limit-xy (:limit-xy constraints)
349 twist (:twist constraints)] 349 twist (:twist constraints)]
350 350
351 (println-repl "creating CONE joint") 351 ;;(println-repl "creating CONE joint")
352 (println-repl rotation) 352 ;;(println-repl rotation)
353 (println-repl 353 ;;(println-repl
354 "UNIT_X --> " (.mult rotation (Vector3f. 1 0 0))) 354 ;; "UNIT_X --> " (.mult rotation (Vector3f. 1 0 0)))
355 (println-repl 355 ;;(println-repl
356 "UNIT_Y --> " (.mult rotation (Vector3f. 0 1 0))) 356 ;; "UNIT_Y --> " (.mult rotation (Vector3f. 0 1 0)))
357 (println-repl 357 ;;(println-repl
358 "UNIT_Z --> " (.mult rotation (Vector3f. 0 0 1))) 358 ;; "UNIT_Z --> " (.mult rotation (Vector3f. 0 0 1)))
359 (doto 359 (doto
360 (ConeJoint. 360 (ConeJoint.
361 control-a 361 control-a
362 control-b 362 control-b
363 pivot-a 363 pivot-a
396 ;; A side-effect of creating a joint registers 396 ;; A side-effect of creating a joint registers
397 ;; it with both physics objects which in turn 397 ;; it with both physics objects which in turn
398 ;; will register the joint with the physics system 398 ;; will register the joint with the physics system
399 ;; when the simulation is started. 399 ;; when the simulation is started.
400 (do 400 (do
401 (println-repl "creating joint between" 401 ;;(println-repl "creating joint between"
402 (.getName obj-a) "and" (.getName obj-b)) 402 ;; (.getName obj-a) "and" (.getName obj-b))
403 (joint-dispatch constraints 403 (joint-dispatch constraints
404 control-a control-b 404 control-a control-b
405 pivot-a pivot-b 405 pivot-a pivot-b
406 joint-rotation)) 406 joint-rotation))
407 (println-repl "could not find joint meta-data!")))) 407 ;;(println-repl "could not find joint meta-data!")
408 )))
408 #+end_src 409 #+end_src
409 410
410 Creating joints is now a matter of applying =connect= to each joint 411 Creating joints is now a matter of applying =connect= to each joint
411 node. 412 node.
412 413
505 (defn worm [] 506 (defn worm []
506 (load-blender-model 507 (load-blender-model
507 "Models/test-creature/worm.blend")) 508 "Models/test-creature/worm.blend"))
508 509
509 (defn test-worm 510 (defn test-worm
511
512 "Testing physical bodies:
513 You should see the the worm fall onto a table. You can fire
514 physical balls at it and the worm should move upon being struck.
515
516 Keys:
517 <space> : fire cannon ball."
518
510 ([] (test-worm false)) 519 ([] (test-worm false))
511 ([record?] 520 ([record?]
512 (let [timer (RatchetTimer. 60)] 521 (let [timer (RatchetTimer. 60)]
513 (world 522 (world
514 (nodify 523 (nodify
525 (Capture/captureVideo 534 (Capture/captureVideo
526 % (File. "/home/r/proj/cortex/render/body/4")))) 535 % (File. "/home/r/proj/cortex/render/body/4"))))
527 no-op)))) 536 no-op))))
528 #+end_src 537 #+end_src
529 538
539 #+results: test-4
540 : #'cortex.test.body/test-worm
541
530 #+begin_html 542 #+begin_html
531 <div class="figure"> 543 <div class="figure">
532 <center> 544 <center>
533 <video controls="controls" width="640"> 545 <video controls="controls" width="640">
534 <source src="../video/worm-1.ogg" type="video/ogg" 546 <source src="../video/worm-1.ogg" type="video/ogg"