comparison org/test-creature.org @ 133:2ed7e60d3821

FINALLY got proprioception working
author Robert McIntyre <rlm@mit.edu>
date Wed, 01 Feb 2012 02:27:18 -0700
parents b26017d1fe9a
children ac350a0ac6b0
comparison
equal deleted inserted replaced
132:3206d5e20bee 133:2ed7e60d3821
295 (.dot (Vector3f. 1 1 1) 295 (.dot (Vector3f. 1 1 1)
296 v)) 296 v))
297 (take 2 targets)) 297 (take 2 targets))
298 (recur (float (* radius 2)))))))) 298 (recur (float (* radius 2))))))))
299 299
300
301 (defn proprio-joint [#^Node parts #^Node joint]
302 (let [[obj-a obj-b] (joint-targets parts joint)
303 joint-rot (.getWorldRotation joint)
304 x (.mult joint-rot Vector3f/UNIT_X)
305 y (.mult joint-rot Vector3f/UNIT_Y)
306 z (.mult joint-rot Vector3f/UNIT_Z)]
307 ;; this function will report proprioceptive information for the
308 ;; joint
309 (fn []
310 ;; x is the "twist" axis, y and z are the "bend" axes
311 (let [rot-a (.getWorldRotation obj-a)
312 rot-b (.getWorldRotation obj-b)
313 relative (.mult (.inverse rot-a) rot-b)
314 basis (doto (Matrix3f.)
315 (.setColumn 0 y)
316 (.setColumn 1 z)
317 (.setColumn 2 x))
318 rotation-about-joint
319 (doto (Quaternion.)
320 (.fromRotationMatrix
321 (.mult (.inverse basis)
322 (.toRotationMatrix relative))))
323
324 confirm-axes
325 (let [temp-axes (make-array Vector3f 3)]
326 (.toAxes rotation-about-joint temp-axes)
327 (seq temp-axes))
328 euler-angles
329 (seq (.toAngles rotation-about-joint nil))]
330 ;;return euler angles of the quaternion around the new basis
331 euler-angles))))
332
333
334
300 (defn world-to-local 335 (defn world-to-local
301 "Convert the world coordinates into coordinates relative to the 336 "Convert the world coordinates into coordinates relative to the
302 object (i.e. local coordinates), taking into account the rotation 337 object (i.e. local coordinates), taking into account the rotation
303 of object." 338 of object."
304 [#^Spatial object world-coordinate] 339 [#^Spatial object world-coordinate]
455 (filter #(isa? (class %) Geometry ) 490 (filter #(isa? (class %) Geometry )
456 (node-seq pieces)))) 491 (node-seq pieces))))
457 (dorun 492 (dorun
458 (map 493 (map
459 (fn [joint] 494 (fn [joint]
460 (let [[obj-a obj-b] 495 (let [[obj-a obj-b] (joint-targets pieces joint)]
461 (joint-targets pieces joint)]
462 (connect obj-a obj-b joint))) 496 (connect obj-a obj-b joint)))
463 joints)) 497 joints))
464 pieces) 498 pieces)
465 499
466 (declare blender-creature) 500 (declare blender-creature)
1186 (add-eye world 1220 (add-eye world
1187 (attach-eye creature (test-eye)) 1221 (attach-eye creature (test-eye))
1188 (comp (view-image) BufferedImage!)) 1222 (comp (view-image) BufferedImage!))
1189 1223
1190 (add-eye world (.getCamera world) no-op) 1224 (add-eye world (.getCamera world) no-op)
1191 1225 ;;(set-gravity world (Vector3f. 0 0 0))
1192 ;;(com.aurellem.capture.Capture/captureVideo 1226 ;;(com.aurellem.capture.Capture/captureVideo
1193 ;; world (file-str "/home/r/proj/ai-videos/hand")) 1227 ;; world (file-str "/home/r/proj/ai-videos/hand"))
1194 ;;(.setTimer world (RatchetTimer. 60)) 1228 ;;(.setTimer world (RatchetTimer. 60))
1195 (speed-up world) 1229 (speed-up world)
1196 ;;(set-gravity world (Vector3f. 0 0 0)) 1230 ;;(set-gravity world (Vector3f. 0 0 0))
1321 1355
1322 1356
1323 #+end_src 1357 #+end_src
1324 1358
1325 #+results: body-1 1359 #+results: body-1
1326 : #'cortex.silly/test-creature 1360 : #'cortex.silly/follow-test
1327 1361
1328 1362
1329 * COMMENT purgatory 1363 * COMMENT purgatory
1330 #+begin_src clojure 1364 #+begin_src clojure
1331 (defn bullet-trans [] 1365 (defn bullet-trans []