comparison org/body.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 7b44348af538
children 7f2653ad3199
comparison
equal deleted inserted replaced
61:7b44348af538 62:2b9d81017cb7
28 (.getSkeleton 28 (.getSkeleton
29 (.getControl node SkeletonControl)) 29 (.getControl node SkeletonControl))
30 ;; this is necessary to force the skeleton to have accurate world 30 ;; this is necessary to force the skeleton to have accurate world
31 ;; transforms before it is rendered to the screen. 31 ;; transforms before it is rendered to the screen.
32 (.resetAndUpdate))) 32 (.resetAndUpdate)))
33
34 (defprotocol Textual
35 (text [something]
36 "Display a detailed textual analysis of the given object."))
37
38 (extend-type com.jme3.scene.Node
39 Textual
40 (text [node]
41 (println "Total Vertexes: " (.getVertexCount node))
42 (println "Total Triangles: " (.getTriangleCount node))
43 (println "Controls :")
44 (dorun (map #(text (.getControl node %)) (range (.getNumControls node))))
45 (println "Has " (.getQuantity node) " Children:")
46 (doall (map text (.getChildren node)))))
47
48 (extend-type com.jme3.animation.AnimControl
49 Textual
50 (text [control]
51 (let [animations (.getAnimationNames control)]
52 (println "Animation Control with " (count animations) " animation(s):")
53 (dorun (map println animations)))))
54
55 (extend-type com.jme3.animation.SkeletonControl
56 Textual
57 (text [control]
58 (println "Skeleton Control with the following skeleton:")
59 (println (.getSkeleton control))))
60
61 (extend-type com.jme3.bullet.control.KinematicRagdollControl
62 Textual
63 (text [control]
64 (println "Ragdoll Control")))
65
66
67 (extend-type com.jme3.scene.Geometry
68 Textual
69 (text [control]
70 (println "...geo...")))
71 33
72 34
73 (defn green-x-ray [] 35 (defn green-x-ray []
74 (doto (Material. (asset-manager) 36 (doto (Material. (asset-manager)
75 "Common/MatDefs/Misc/Unshaded.j3md") 37 "Common/MatDefs/Misc/Unshaded.j3md")
91 (* 2 n (+ interstitial-space segment-length)) 0 0) 53 (* 2 n (+ interstitial-space segment-length)) 0 0)
92 :name (str "worm-segment" n) 54 :name (str "worm-segment" n)
93 :color (ColorRGBA/randomColor)))] 55 :color (ColorRGBA/randomColor)))]
94 (map nth-segment (range num-segments)))) 56 (map nth-segment (range num-segments))))
95 57
96 (defn nodify
97 "take a sequence of things that can be attached to a node and return
98 a node with all of them attached"
99 ([name children]
100 (let [node (Node. name)]
101 (dorun (map #(.attachChild node %) children))
102 node))
103 ([children] (nodify "" children)))
104 58
105 (defn connect-at-midpoint 59 (defn connect-at-midpoint
106 [segmentA segmentB] 60 [segmentA segmentB]
107 (let [centerA (.getWorldTranslation segmentA) 61 (let [centerA (.getWorldTranslation segmentA)
108 centerB (.getWorldTranslation segmentB) 62 centerB (.getWorldTranslation segmentB)
151 105
152 ;; surprisingly ehough, terristerial creatures only move by using 106 ;; surprisingly ehough, terristerial creatures only move by using
153 ;; torque applied to their joints. There's not a single straight line 107 ;; torque applied to their joints. There's not a single straight line
154 ;; of force in the human body at all! (a straight line of force would 108 ;; of force in the human body at all! (a straight line of force would
155 ;; correspond to some sort of jet or rocket propulseion) 109 ;; correspond to some sort of jet or rocket propulseion)
156
157 (defn node-seq
158 "Take a node and return a seq of all its children
159 recursively. There will be no nodes left in the resulting
160 structure"
161 [#^Node node]
162 (tree-seq #(isa? (class %) Node) #(.getChildren %) node))
163
164 110
165 (defn torque-controls [control] 111 (defn torque-controls [control]
166 (let [torques 112 (let [torques
167 (concat 113 (concat
168 (map #(Vector3f. 0 (Math/sin %) (Math/cos %)) 114 (map #(Vector3f. 0 (Math/sin %) (Math/cos %))