comparison org/body.org @ 55:8b95180f5c69

getting basic hinges to work
author Robert McIntyre <rlm@mit.edu>
date Tue, 15 Nov 2011 17:48:10 -0700
parents 7bc3b22c507b
children 8b571c137f81
comparison
equal deleted inserted replaced
54:7bc3b22c507b 55:8b95180f5c69
117 (dorun 117 (dorun
118 (map #(.addBoneName krc %) 118 (map #(.addBoneName krc %)
119 ["mid2" "tail" "head" "mid1" "mid3" "mid4" "Dummy-Root" ""] 119 ["mid2" "tail" "head" "mid1" "mid3" "mid4" "Dummy-Root" ""]
120 ;;"mid2" "mid3" "tail" "head"] 120 ;;"mid2" "mid3" "tail" "head"]
121 ))) 121 )))
122
123
124
125 (.addControl node krc) 122 (.addControl node krc)
126 (.setRagdollMode krc) 123 (.setRagdollMode krc)
127 ) 124 )
128 node 125 node
129 ) 126 )
155 (dorun (map #(.setUserControl % true) bones)) 152 (dorun (map #(.setUserControl % true) bones))
156 (dorun (map (fn [b] 153 (dorun (map (fn [b]
157 (println (.getName b) 154 (println (.getName b)
158 " -- " (f b))) 155 " -- " (f b)))
159 bones)) 156 bones))
160
161 (dorun 157 (dorun
162 (map #(.attachChild 158 (map #(.attachChild
163 debug-node 159 debug-node
164 (doto 160 (doto
165 (sphere 0.1 161 (sphere 0.1
192 ;; (.fromAngles (/ Math/PI 2) 188 ;; (.fromAngles (/ Math/PI 2)
193 ;; 0 189 ;; 0
194 ;; 0 190 ;; 0
195 191
196 (Vector3f. 1 1 1)) 192 (Vector3f. 1 1 1))
197
198 ) 193 )
199
200
201 194
202 (println-repl "hi! <3")))) 195 (println-repl "hi! <3"))))
203 196
204 197
205 (defn test-ragdoll [] 198 (defn test-ragdoll []
240 233
241 ))) 234 )))
242 235
243 236
244 237
245 238
246 239 (defn joint-control
247 240 [joint]
248 241 (let [physics-space (ref nil)
242 enabled? (ref true)]
243 (reify PhysicsControl
244 (setPhysicsSpace [this space]
245 (dosync
246 (ref-set physics-space space))
247 (.addJoint space joint))
248 (update [this tpf])
249 (setSpatial [this spatial])
250 (render [this rm vp])
251 (getPhysicsSpace [this] (deref physics-space))
252 (isEnabled [this] (deref enabled?))
253 (setEnabled [this state]
254 (dosync (ref-set enabled? state))))))
255
256 (defn add-joint
257 "Add a joint to a particular object. When the object is added to the
258 PhysicsSpace of a simulation, the joint will also be added"
259 [object joint]
260 (let [control (joint-control joint)]
261 (.addControl object control))
262 object)
263
264 (defn hinge-world
265 []
266 (let [sphere1 (sphere)
267 sphere2 (sphere 1 :position (Vector3f. 3 3 3))
268 joint (Point2PointJoint.
269 (.getControl sphere1 RigidBodyControl)
270 (.getControl sphere2 RigidBodyControl)
271 Vector3f/ZERO (Vector3f. 3 3 3))]
272 (add-joint sphere1 joint)
273 (doto (Node. "hinge-world")
274 (.attachChild sphere1)
275 (.attachChild sphere2))))
276
277
278 (defn test-joint
279 []
280 (.start
281 (world
282 (doto (Node.)
283 (.attachChild
284
249 285
250 286
251 287
252 #+end_src 288 #+end_src
253 289