Mercurial > cortex
comparison org/body.org @ 52:00d0e1639d4b
simplified world, got buggy physics ragdoll working
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Mon, 14 Nov 2011 21:30:23 -0700 |
parents | 2a6ede6d8ad8 |
children | bb24106cbd6a |
comparison
equal
deleted
inserted
replaced
51:2a6ede6d8ad8 | 52:00d0e1639d4b |
---|---|
55 | 55 |
56 (defn worm-blender | 56 (defn worm-blender |
57 [] | 57 [] |
58 (first (seq (.getChildren (load-blender-model | 58 (first (seq (.getChildren (load-blender-model |
59 "Models/anim2/worm3.blend"))))) | 59 "Models/anim2/worm3.blend"))))) |
60 | |
61 (defn skel [node] | |
62 (doto | |
63 (.getSkeleton | |
64 (.getControl node SkeletonControl)) | |
65 ;; this is necessary to force the skeleton to have accurate world | |
66 ;; transforms before it is rendered to the screen. | |
67 (.resetAndUpdate))) | |
60 | 68 |
61 (defprotocol Textual | 69 (defprotocol Textual |
62 (text [something] | 70 (text [something] |
63 "Display a detailed textual analysis of the given object.")) | 71 "Display a detailed textual analysis of the given object.")) |
64 | 72 |
74 | 82 |
75 (extend-type com.jme3.animation.AnimControl | 83 (extend-type com.jme3.animation.AnimControl |
76 Textual | 84 Textual |
77 (text [control] | 85 (text [control] |
78 (let [animations (.getAnimationNames control)] | 86 (let [animations (.getAnimationNames control)] |
79 (println "Animation Control with " (count animations) " animations:") | 87 (println "Animation Control with " (count animations) " animation(s):") |
80 (dorun (map println animations))))) | 88 (dorun (map println animations))))) |
81 | 89 |
82 (extend-type com.jme3.animation.SkeletonControl | 90 (extend-type com.jme3.animation.SkeletonControl |
83 Textual | 91 Textual |
84 (text [control] | 92 (text [control] |
85 (println "Skeleton Control with the following skeleton:") | 93 (println "Skeleton Control with the following skeleton:") |
86 (println (.getSkeleton control)))) | 94 (println (.getSkeleton control)))) |
87 | 95 |
96 (extend-type com.jme3.bullet.control.KinematicRagdollControl | |
97 Textual | |
98 (text [control] | |
99 (println "Ragdoll Control"))) | |
100 | |
101 | |
88 (extend-type com.jme3.scene.Geometry | 102 (extend-type com.jme3.scene.Geometry |
89 Textual | 103 Textual |
90 (text [control] | 104 (text [control] |
91 (println "...geo..."))) | 105 (println "...geo..."))) |
92 | 106 |
93 | 107 |
94 | 108 |
95 | 109 |
96 (defn body | 110 (defn body |
97 "given a node with a skeleton, will produce a body sutiable for AI | 111 "given a node with a SkeletonControl, will produce a body sutiable |
98 control with movement and proprioception." | 112 for AI control with movement and proprioception." |
99 [node] | 113 [node] |
100 (let [skeleton-control (.getControl node SkeletonControl) | 114 (let [skeleton-control (.getControl node SkeletonControl) |
101 krc (KinematicRagdollControl. (float 0.5))] | 115 krc (KinematicRagdollControl. (float 0.5))] |
102 (dorun | 116 (dorun |
103 (map #(.addBoneName krc %) | 117 (map #(.addBoneName krc %) |
104 ["mid1" "mid2" "mid3" "tail" "head"])) | 118 ["mid1" "mid2" "mid3" "tail" "head"] |
119 ;; ["Ulna.L" | |
120 ;; "Ulna.R" | |
121 ;; "Chest" | |
122 ;; "Foot.L" | |
123 ;; "Foot.R" | |
124 ;; "Hand.R" | |
125 ;; "Hand.L" | |
126 ;; "Neck" | |
127 ;; "Root" | |
128 ;; "Stomach" | |
129 ;; "Waist" | |
130 ;; "Humerus.L" | |
131 ;; "Humerus.R" | |
132 ;; "Thigh.L" | |
133 ;; "Thigh.R" | |
134 ;; "Calf.L" | |
135 ;; "Calf.R" | |
136 ;; "Clavicle.L" | |
137 ;; "Clavicle.R"] | |
138 )) | |
139 | |
140 | |
141 | |
105 (.addControl node krc) | 142 (.addControl node krc) |
106 (.setRagdollMode krc)) | 143 (.setRagdollMode krc) |
144 ) | |
107 node | 145 node |
108 ) | 146 ) |
109 | 147 |
110 (defn | 148 (defn green-x-ray [] |
111 green-x-ray [] | |
112 (doto (Material. (asset-manager) | 149 (doto (Material. (asset-manager) |
113 "Common/MatDefs/Misc/Unshaded.j3md") | 150 "Common/MatDefs/Misc/Unshaded.j3md") |
114 (.setColor "Color" ColorRGBA/Green) | 151 (.setColor "Color" ColorRGBA/Green) |
115 (-> (.getAdditionalRenderState) (.setDepthTest | 152 (-> (.getAdditionalRenderState) |
116 false)))) | 153 (.setDepthTest false)))) |
117 | 154 |
118 (defn view-skeleton [node] | 155 (defn view-skeleton [node] |
119 (let [sd | 156 (let [sd |
120 | 157 |
121 (doto | 158 (doto |
152 :physical? false) | 189 :physical? false) |
153 (.setMaterial (green-x-ray)))) | 190 (.setMaterial (green-x-ray)))) |
154 bones))) | 191 bones))) |
155 debug-node) | 192 debug-node) |
156 | 193 |
157 (defn skel [node] | 194 (import jme3test.bullet.PhysicsTestHelper) |
158 (doto | |
159 (.getSkeleton | |
160 (.getControl node SkeletonControl)) | |
161 ;; this is necessary to force the skeleton to have accurate world | |
162 ;; transforms before it is rendered to the screen. | |
163 (.resetAndUpdate))) | |
164 | |
165 | |
166 | |
167 | |
168 | |
169 (view | |
170 (init-debug-skel-node | |
171 (fn [b] (.getWorldBindPosition b)) | |
172 (Node. "skel-debug") (skel (worm)))) | |
173 | |
174 | |
175 | |
176 | |
177 | 195 |
178 (defn test-ragdoll [] | 196 (defn test-ragdoll [] |
179 | 197 |
180 (let [the-worm | 198 (let [the-worm |
181 (body | 199 (body |
182 (.loadModel (asset-manager) "Models/anim2/Cube.mesh.xml") | 200 ;;(.loadModel (asset-manager) "Models/anim2/Cube.mesh.xml") |
183 ;;(worm-blender) | 201 ;;(worm-blender) |
202 (worm) | |
203 ;;(oto) | |
204 ;;(sinbad) | |
184 ) | 205 ) |
185 ] | 206 ] |
186 | 207 |
187 | 208 |
188 (.start | 209 (.start |
190 (doto (Node.) | 211 (doto (Node.) |
191 (.attachChild the-worm)) | 212 (.attachChild the-worm)) |
192 {"mouse-left" (fire-cannon-ball)} | 213 {"mouse-left" (fire-cannon-ball)} |
193 (fn [world] | 214 (fn [world] |
194 (light-up-everything world) | 215 (light-up-everything world) |
216 (PhysicsTestHelper/createPhysicsTestWorld | |
217 (.getRootNode world) | |
218 (asset-manager) | |
219 (.getPhysicsSpace | |
220 (.getState (.getStateManager world) BulletAppState))) | |
195 ;;(.setTimer world (NanoTimer.)) | 221 ;;(.setTimer world (NanoTimer.)) |
196 ;;(org.lwjgl.input.Mouse/setGrabbed false) | 222 ;;(org.lwjgl.input.Mouse/setGrabbed false) |
197 ) | 223 ) |
198 no-op | 224 no-op |
199 ) | 225 ) |
201 | 227 |
202 ))) | 228 ))) |
203 | 229 |
204 | 230 |
205 | 231 |
206 | |
207 | |
208 | |
209 | |
210 | |
211 | |
212 | |
213 | |
214 | |
215 | |
216 | |
217 | |
218 | |
219 | |
220 | |
221 (defn test-worm-anim [] | |
222 | |
223 (let [the-worm | |
224 ;; (oto) | |
225 (worm-blender) | |
226 anim-control (.getControl the-worm AnimControl) | |
227 channel (doto (.createChannel anim-control) | |
228 ;; (.setAnim "Walk") | |
229 (.setAnim "moveHead") | |
230 ) | |
231 | |
232 play-anim | |
233 no-op | |
234 ;; (fn [world pressed] | |
235 ;; (if (not pressed) | |
236 ;; (do | |
237 ;; (println-repl "space") | |
238 ;; ;; (.setAnim channel "moveHead") | |
239 ;; (.setAnim channel "Walk" (float 0.5)) | |
240 ;; ))) | |
241 | |
242 ] | |
243 | |
244 (.start | |
245 (world | |
246 (doto (Node.) | |
247 (.attachChild the-worm)) | |
248 {"key-space" play-anim | |
249 "mouse-left" (fire-cannon-ball)} | |
250 (fn [world] | |
251 (light-up-everything world) | |
252 ;;(.setTimer world (NanoTimer.)) | |
253 (org.lwjgl.input.Mouse/setGrabbed false) | |
254 ) | |
255 no-op | |
256 ) | |
257 | |
258 | |
259 ))) | |
260 | 232 |
261 | 233 |
262 | 234 |
263 | 235 |
264 | 236 |