# HG changeset patch # User Robert McIntyre # Date 1328165191 25200 # Node ID 39c89ae5c7d0197df2b3d95d1cf114222d4a8fcb # Parent 47a4d74761f02f87a692819f22f9f3b10df75dcb saving progress diff -r 47a4d74761f0 -r 39c89ae5c7d0 assets/Models/creature1/try-again.blend Binary file assets/Models/creature1/try-again.blend has changed diff -r 47a4d74761f0 -r 39c89ae5c7d0 org/body.org --- a/org/body.org Wed Feb 01 17:39:23 2012 -0700 +++ b/org/body.org Wed Feb 01 23:46:31 2012 -0700 @@ -66,9 +66,13 @@ (defn joint-proprioception [#^Node parts #^Node joint] (let [[obj-a obj-b] (joint-targets parts joint) joint-rot (.getWorldRotation joint) - x (.mult joint-rot Vector3f/UNIT_X) - y (.mult joint-rot Vector3f/UNIT_Y) - z (.mult joint-rot Vector3f/UNIT_Z)] + pre-inv-a (.inverse (.getWorldRotation obj-a)) + x (.mult pre-inv-a (.mult joint-rot Vector3f/UNIT_X)) + y (.mult pre-inv-a (.mult joint-rot Vector3f/UNIT_Y)) + z (.mult pre-inv-a (.mult joint-rot Vector3f/UNIT_Z))] + (println-repl "x:" x) + (println-repl "y:" y) + (println-repl "z:" z) ;; this function will report proprioceptive information for the ;; joint. (fn [] @@ -341,6 +345,64 @@ +(defmacro with-movement + [object + [up down left right roll-up roll-down :as keyboard] + forces + [world-invocation + root-node + keymap + intilization + world-loop]] + (let [add-keypress + (fn [state keymap key] + `(merge ~keymap + {~key + (fn [_ pressed?#] + (reset! ~state pressed?#))})) + move-left? (gensym "move-left?") + move-right? (gensym "move-right?") + move-up? (gensym "move-up?") + move-down? (gensym "move-down?") + roll-left? (gensym "roll-left?") + roll-right? (gensym "roll-right?") + directions + [(Vector3f. 0 1 0) + (Vector3f. 0 -1 0) + (Vector3f. 0 0 1) + (Vector3f. 0 0 -1) + (Vector3f. -1 0 0) + (Vector3f. 1 0 0)] + symbols [move-left? move-right? move-up? move-down? + roll-left? roll-right?] + + keymap* (vec (map #(add-keypress %1 keymap %2) + symbols + keyboard)) + + splice-loop (map (fn [sym force direction] + `(if (deref ~sym) + (tap ~object ~direction ~force))) + symbols directions forces) + + world-loop* `(fn [world# tpf#] + (~world-loop world# tpf#) + ~@splice-loop)] + + `(let [~move-up? (atom false) + ~move-down? (atom false) + ~move-left? (atom false) + ~move-right? (atom false) + ~roll-left? (atom false) + ~roll-right? (atom false)] + (~world-invocation + ~root-node + (reduce merge ~keymap*) + ~intilization + ~world-loop*) + ))) + + (defn test-proprioception "Testing proprioception: You should see two foating bars, and a printout of pitch, yaw, and @@ -359,23 +421,10 @@ joint (join-at-point hand finger (Vector3f. 1.2 2 0 )) creature (nodify [hand finger joint-node]) ;; ******************************************* - rot (doto (Quaternion.) - (.fromAngleAxis (/ Math/PI 4) - (Vector3f. 0 0 -1))) - hand2 (box 1 0.2 0.2 :position (Vector3f. 0 1.5 -3) - :mass 0 :color ColorRGBA/Blue :rotation rot) - finger2 (box 1 0.2 0.2 :position (Vector3f. 2.4 1.5 -3) - :mass 1 :color ColorRGBA/Magenta :rotation rot) - joint-node2 (box 0.1 0.05 0.05 :color ColorRGBA/Gray - :position (Vector3f. 1.2 1.5 -3) - :physical? false :rotation rot) - joint2 (join-at-point hand2 finger2 (Vector3f. 1.2 1.5 -3)) - creature2 (nodify [hand2 finger2 joint-node2]) - ;; ******************************************* - + floor (box 10 10 10 :position (Vector3f. 0 -15 0) :mass 0 :color ColorRGBA/Gray) - + move-up? (atom false) move-down? (atom false) move-left? (atom false) @@ -384,7 +433,7 @@ roll-right? (atom false) - root (nodify [creature creature2 floor]) + root (nodify [creature floor]) prop (joint-proprioception creature joint-node) prop-view (proprioception-debug-window)] @@ -393,48 +442,46 @@ (.setCollisionGroup (.getControl hand RigidBodyControl) PhysicsCollisionObject/COLLISION_GROUP_NONE) - (.setCollisionGroup - (.getControl hand2 RigidBodyControl) - PhysicsCollisionObject/COLLISION_GROUP_NONE) - - - - (world - root - (merge standard-debug-controls - {"key-r" (fn [_ pressed?] (reset! move-up? pressed?)) - "key-t" (fn [_ pressed?] (reset! move-down? pressed?)) - "key-f" (fn [_ pressed?] (reset! move-left? pressed?)) - "key-g" (fn [_ pressed?] (reset! move-right? pressed?)) - "key-v" (fn [_ pressed?] (reset! roll-left? pressed?)) - "key-b" (fn [_ pressed?] (reset! roll-right? pressed?))}) - (fn [world] - (.setTimer world (com.aurellem.capture.RatchetTimer. 60)) - (set-gravity world (Vector3f. 0 0 0)) - (light-up-everything world)) - (fn [_ _] - (let [force 10 - left (Vector3f. 0 1 0) - right (Vector3f. 0 -1 0) - up (Vector3f. 0 0 1) - down (Vector3f. 0 0 -1) - roll-left (Vector3f. -1 0 0) - roll-right (Vector3f. 1 0 0)] - (if @move-up? (do (tap finger up force) - (tap finger2 up force))) - (if @move-down? (do (tap finger down force) - (tap finger2 down force))) - (if @move-left? (do (tap finger left force) - (tap finger2 left force))) - (if @move-right? (do (tap finger right force) - (tap finger2 right force))) - (if @roll-left? (do (tap finger roll-left (/ force 10)) - (tap finger2 roll-left (/ force 10)))) - (if @roll-right? (do (tap finger roll-right (/ force 10)) - (tap finger2 roll-right (/ force 10))))) - (prop-view (list (prop))))))) - + (with-movement + finger + ["key-r" "key-t" "key-f" "key-g" "key-v" "key-b"] + [10 10 10 10 1 1] + (world + root + (merge standard-debug-controls + {"key-r" (fn [_ pressed?] (reset! move-up? pressed?)) + "key-t" (fn [_ pressed?] (reset! move-down? pressed?)) + "key-f" (fn [_ pressed?] (reset! move-left? pressed?)) + "key-g" (fn [_ pressed?] (reset! move-right? pressed?)) + "key-v" (fn [_ pressed?] (reset! roll-left? pressed?)) + "key-b" (fn [_ pressed?] (reset! roll-right? pressed?))}) + (fn [world] + (.setTimer world (com.aurellem.capture.RatchetTimer. 60)) + (set-gravity world (Vector3f. 0 0 0)) + (light-up-everything world)) + (fn [_ _] + (let [force 10 + left (Vector3f. 0 1 0) + right (Vector3f. 0 -1 0) + up (Vector3f. 0 0 1) + down (Vector3f. 0 0 -1) + roll-left (Vector3f. -1 0 0) + roll-right (Vector3f. 1 0 0)] + (if @move-up? (tap finger up force)) + + (if @move-down? (tap finger down force)) + + (if @move-left? (tap finger left force)) + + (if @move-right? (tap finger right force)) + + (if @roll-left? (tap finger roll-left (/ force 10))) + + (if @roll-right? (tap finger roll-right (/ force 10)))) + + (prop-view (list (prop)))))))) + #+end_src #+results: test-body