Mercurial > cortex
changeset 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 | 7b44348af538 |
children | 7f2653ad3199 |
files | org/body.org org/util.org |
diffstat | 2 files changed, 62 insertions(+), 54 deletions(-) [+] |
line wrap: on
line diff
1.1 --- a/org/body.org Mon Nov 28 21:22:35 2011 -0700 1.2 +++ b/org/body.org Mon Nov 28 21:28:46 2011 -0700 1.3 @@ -31,44 +31,6 @@ 1.4 ;; transforms before it is rendered to the screen. 1.5 (.resetAndUpdate))) 1.6 1.7 -(defprotocol Textual 1.8 - (text [something] 1.9 - "Display a detailed textual analysis of the given object.")) 1.10 - 1.11 -(extend-type com.jme3.scene.Node 1.12 - Textual 1.13 - (text [node] 1.14 - (println "Total Vertexes: " (.getVertexCount node)) 1.15 - (println "Total Triangles: " (.getTriangleCount node)) 1.16 - (println "Controls :") 1.17 - (dorun (map #(text (.getControl node %)) (range (.getNumControls node)))) 1.18 - (println "Has " (.getQuantity node) " Children:") 1.19 - (doall (map text (.getChildren node))))) 1.20 - 1.21 -(extend-type com.jme3.animation.AnimControl 1.22 - Textual 1.23 - (text [control] 1.24 - (let [animations (.getAnimationNames control)] 1.25 - (println "Animation Control with " (count animations) " animation(s):") 1.26 - (dorun (map println animations))))) 1.27 - 1.28 -(extend-type com.jme3.animation.SkeletonControl 1.29 - Textual 1.30 - (text [control] 1.31 - (println "Skeleton Control with the following skeleton:") 1.32 - (println (.getSkeleton control)))) 1.33 - 1.34 -(extend-type com.jme3.bullet.control.KinematicRagdollControl 1.35 - Textual 1.36 - (text [control] 1.37 - (println "Ragdoll Control"))) 1.38 - 1.39 - 1.40 -(extend-type com.jme3.scene.Geometry 1.41 - Textual 1.42 - (text [control] 1.43 - (println "...geo..."))) 1.44 - 1.45 1.46 (defn green-x-ray [] 1.47 (doto (Material. (asset-manager) 1.48 @@ -93,14 +55,6 @@ 1.49 :color (ColorRGBA/randomColor)))] 1.50 (map nth-segment (range num-segments)))) 1.51 1.52 -(defn nodify 1.53 - "take a sequence of things that can be attached to a node and return 1.54 - a node with all of them attached" 1.55 - ([name children] 1.56 - (let [node (Node. name)] 1.57 - (dorun (map #(.attachChild node %) children)) 1.58 - node)) 1.59 - ([children] (nodify "" children))) 1.60 1.61 (defn connect-at-midpoint 1.62 [segmentA segmentB] 1.63 @@ -153,14 +107,6 @@ 1.64 ;; torque applied to their joints. There's not a single straight line 1.65 ;; of force in the human body at all! (a straight line of force would 1.66 ;; correspond to some sort of jet or rocket propulseion) 1.67 - 1.68 -(defn node-seq 1.69 - "Take a node and return a seq of all its children 1.70 - recursively. There will be no nodes left in the resulting 1.71 - structure" 1.72 - [#^Node node] 1.73 - (tree-seq #(isa? (class %) Node) #(.getChildren %) node)) 1.74 - 1.75 1.76 (defn torque-controls [control] 1.77 (let [torques
2.1 --- a/org/util.org Mon Nov 28 21:22:35 2011 -0700 2.2 +++ b/org/util.org Mon Nov 28 21:28:46 2011 -0700 2.3 @@ -274,6 +274,24 @@ 2.4 (make-shape (assoc options 2.5 :shape (Sphere. 32 32 (float r)))))) 2.6 ([] (sphere 0.5))) 2.7 + 2.8 +(defn node-seq 2.9 + "Take a node and return a seq of all its children 2.10 + recursively. There will be no nodes left in the resulting 2.11 + structure" 2.12 + [#^Node node] 2.13 + (tree-seq #(isa? (class %) Node) #(.getChildren %) node)) 2.14 + 2.15 +(defn nodify 2.16 + "Take a sequence of things that can be attached to a node and return 2.17 + a node with all of them attached" 2.18 + ([name children] 2.19 + (let [node (Node. name)] 2.20 + (dorun (map #(.attachChild node %) children)) 2.21 + node)) 2.22 + ([children] (nodify "" children))) 2.23 + 2.24 + 2.25 #+end_src 2.26 2.27 2.28 @@ -372,6 +390,50 @@ 2.29 (set-gravity world Vector3f/ZERO) 2.30 (light-up-everything world)) 2.31 no-op)))) 2.32 + 2.33 +(extend-type com.jme3.math.ColorRGBA 2.34 + Viewable 2.35 + (view 2.36 + [color] 2.37 + (view (doto (Node.) 2.38 + (.attachChild (box 1 1 1 :color color)))))) 2.39 + 2.40 +(defprotocol Textual 2.41 + (text [something] 2.42 + "Display a detailed textual analysis of the given object.")) 2.43 + 2.44 +(extend-type com.jme3.scene.Node 2.45 + Textual 2.46 + (text [node] 2.47 + (println "Total Vertexes: " (.getVertexCount node)) 2.48 + (println "Total Triangles: " (.getTriangleCount node)) 2.49 + (println "Controls :") 2.50 + (dorun (map #(text (.getControl node %)) (range (.getNumControls node)))) 2.51 + (println "Has " (.getQuantity node) " Children:") 2.52 + (doall (map text (.getChildren node))))) 2.53 + 2.54 +(extend-type com.jme3.animation.AnimControl 2.55 + Textual 2.56 + (text [control] 2.57 + (let [animations (.getAnimationNames control)] 2.58 + (println "Animation Control with " (count animations) " animation(s):") 2.59 + (dorun (map println animations))))) 2.60 + 2.61 +(extend-type com.jme3.animation.SkeletonControl 2.62 + Textual 2.63 + (text [control] 2.64 + (println "Skeleton Control with the following skeleton:") 2.65 + (println (.getSkeleton control)))) 2.66 + 2.67 +(extend-type com.jme3.bullet.control.KinematicRagdollControl 2.68 + Textual 2.69 + (text [control] 2.70 + (println "Ragdoll Control"))) 2.71 + 2.72 +(extend-type com.jme3.scene.Geometry 2.73 + Textual 2.74 + (text [control] 2.75 + (println "...geo..."))) 2.76 #+end_src 2.77 2.78 Here I make the =Viewable= protocol and extend it to JME's types. Now