comparison org/util.org @ 62:2b9d81017cb7

moved utility functions out of body and into util
author Robert McIntyre <rlm@mit.edu>
date Mon, 28 Nov 2011 21:28:46 -0700
parents e5e627f50a3a
children 1381a6ebd08b
comparison
equal deleted inserted replaced
61:7b44348af538 62:2b9d81017cb7
272 ([r & {:as options}] 272 ([r & {:as options}]
273 (let [options (merge base-shape options)] 273 (let [options (merge base-shape options)]
274 (make-shape (assoc options 274 (make-shape (assoc options
275 :shape (Sphere. 32 32 (float r)))))) 275 :shape (Sphere. 32 32 (float r))))))
276 ([] (sphere 0.5))) 276 ([] (sphere 0.5)))
277
278 (defn node-seq
279 "Take a node and return a seq of all its children
280 recursively. There will be no nodes left in the resulting
281 structure"
282 [#^Node node]
283 (tree-seq #(isa? (class %) Node) #(.getChildren %) node))
284
285 (defn nodify
286 "Take a sequence of things that can be attached to a node and return
287 a node with all of them attached"
288 ([name children]
289 (let [node (Node. name)]
290 (dorun (map #(.attachChild node %) children))
291 node))
292 ([children] (nodify "" children)))
293
294
277 #+end_src 295 #+end_src
278 296
279 297
280 *** Debug Actions 298 *** Debug Actions
281 #+srcname: debug-actions 299 #+srcname: debug-actions
370 (fn [world] 388 (fn [world]
371 (enable-debug world) 389 (enable-debug world)
372 (set-gravity world Vector3f/ZERO) 390 (set-gravity world Vector3f/ZERO)
373 (light-up-everything world)) 391 (light-up-everything world))
374 no-op)))) 392 no-op))))
393
394 (extend-type com.jme3.math.ColorRGBA
395 Viewable
396 (view
397 [color]
398 (view (doto (Node.)
399 (.attachChild (box 1 1 1 :color color))))))
400
401 (defprotocol Textual
402 (text [something]
403 "Display a detailed textual analysis of the given object."))
404
405 (extend-type com.jme3.scene.Node
406 Textual
407 (text [node]
408 (println "Total Vertexes: " (.getVertexCount node))
409 (println "Total Triangles: " (.getTriangleCount node))
410 (println "Controls :")
411 (dorun (map #(text (.getControl node %)) (range (.getNumControls node))))
412 (println "Has " (.getQuantity node) " Children:")
413 (doall (map text (.getChildren node)))))
414
415 (extend-type com.jme3.animation.AnimControl
416 Textual
417 (text [control]
418 (let [animations (.getAnimationNames control)]
419 (println "Animation Control with " (count animations) " animation(s):")
420 (dorun (map println animations)))))
421
422 (extend-type com.jme3.animation.SkeletonControl
423 Textual
424 (text [control]
425 (println "Skeleton Control with the following skeleton:")
426 (println (.getSkeleton control))))
427
428 (extend-type com.jme3.bullet.control.KinematicRagdollControl
429 Textual
430 (text [control]
431 (println "Ragdoll Control")))
432
433 (extend-type com.jme3.scene.Geometry
434 Textual
435 (text [control]
436 (println "...geo...")))
375 #+end_src 437 #+end_src
376 438
377 Here I make the =Viewable= protocol and extend it to JME's types. Now 439 Here I make the =Viewable= protocol and extend it to JME's types. Now
378 JME3's =hello-world= can be written as easily as: 440 JME3's =hello-world= can be written as easily as:
379 441