diff org/test-creature.org @ 135:421cc43441ae

cleaned up test, moved some functions
author Robert McIntyre <rlm@mit.edu>
date Wed, 01 Feb 2012 05:43:51 -0700
parents ac350a0ac6b0
children ffbab4199c0d
line wrap: on
line diff
     1.1 --- a/org/test-creature.org	Wed Feb 01 02:44:07 2012 -0700
     1.2 +++ b/org/test-creature.org	Wed Feb 01 05:43:51 2012 -0700
     1.3 @@ -262,73 +262,7 @@
     1.4               (.getZ in)
     1.5               (- (.getY in))))
     1.6  
     1.7 -(defn jme-to-blender
     1.8 -  "Convert from JME coordinates to Blender coordinates"
     1.9 -  [#^Vector3f in]
    1.10 -  (Vector3f. (.getX in)
    1.11 -             (- (.getZ in))
    1.12 -             (.getY in)))
    1.13  
    1.14 -(defn joint-targets
    1.15 -  "Return the two closest two objects to the joint object, ordered
    1.16 -  from bottom to top according to the joint's rotation."
    1.17 -  [#^Node parts #^Node joint]
    1.18 -  (loop [radius (float 0.01)]
    1.19 -    (let [results (CollisionResults.)]
    1.20 -      (.collideWith
    1.21 -       parts
    1.22 -       (BoundingBox. (.getWorldTranslation joint)
    1.23 -                     radius radius radius)
    1.24 -       results)
    1.25 -      (let [targets
    1.26 -            (distinct
    1.27 -             (map  #(.getGeometry %) results))]
    1.28 -        (if (>= (count targets) 2)
    1.29 -          (sort-by
    1.30 -           #(let [v
    1.31 -                  (jme-to-blender
    1.32 -                   (.mult
    1.33 -                    (.inverse (.getWorldRotation joint))
    1.34 -                    (.subtract (.getWorldTranslation %)
    1.35 -                               (.getWorldTranslation joint))))]
    1.36 -              (println-repl (.getName %) ":" v)
    1.37 -              (.dot (Vector3f. 1 1 1)
    1.38 -                    v))                  
    1.39 -           (take 2 targets))
    1.40 -          (recur (float (* radius 2))))))))
    1.41 -
    1.42 -
    1.43 -(defn proprio-joint [#^Node parts #^Node joint]
    1.44 -  (let [[obj-a obj-b] (joint-targets parts joint)
    1.45 -        joint-rot (.getWorldRotation joint)
    1.46 -        x (.mult joint-rot Vector3f/UNIT_X)
    1.47 -        y (.mult joint-rot Vector3f/UNIT_Y)
    1.48 -        z (.mult joint-rot Vector3f/UNIT_Z)]
    1.49 -    ;; this function will report proprioceptive information for the
    1.50 -    ;; joint 
    1.51 -    (fn []
    1.52 -      ;; x is the "twist" axis, y and z are the "bend" axes
    1.53 -      (let [rot-a (.getWorldRotation obj-a)
    1.54 -            rot-b (.getWorldRotation obj-b)
    1.55 -            relative (.mult (.inverse rot-a) rot-b)
    1.56 -            basis (doto (Matrix3f.)
    1.57 -                    (.setColumn 0 y)
    1.58 -                    (.setColumn 1 z)
    1.59 -                    (.setColumn 2 x))
    1.60 -            rotation-about-joint
    1.61 -            (doto (Quaternion.)
    1.62 -              (.fromRotationMatrix 
    1.63 -               (.mult (.inverse basis)
    1.64 -                      (.toRotationMatrix relative))))
    1.65 -
    1.66 -            confirm-axes
    1.67 -            (let [temp-axes (make-array Vector3f 3)]
    1.68 -              (.toAxes rotation-about-joint temp-axes)
    1.69 -              (seq temp-axes))
    1.70 -            euler-angles
    1.71 -            (seq (.toAngles rotation-about-joint nil))]
    1.72 -        ;;return euler angles of the quaternion around the new basis            
    1.73 -        euler-angles))))
    1.74  
    1.75  
    1.76  
    1.77 @@ -1058,12 +992,6 @@
    1.78  ;; these are the functions that provide world i/o, chinese-room style
    1.79  
    1.80  
    1.81 -(defn creature-joints 
    1.82 -  "Return the children of the creature's \"joints\" node."
    1.83 -  [#^Node creature]
    1.84 -  (if-let [joint-node (.getChild creature "joints")]
    1.85 -    (seq (.getChildren joint-node))
    1.86 -    (do (println-repl "could not find JOINTS node") [])))
    1.87  
    1.88  
    1.89  (defn blender-creature
    1.90 @@ -1156,24 +1084,6 @@
    1.91         (.getRGB image x 0)))))
    1.92  
    1.93  
    1.94 -(defn rad->deg [rad]
    1.95 -  (* 180 (/ Math/PI) rad))
    1.96 -
    1.97 -
    1.98 -(defn debug-prop-window
    1.99 -  "create a debug view for proprioception"
   1.100 -  []
   1.101 -  (let [vi (view-image)]
   1.102 -    (fn [sensor-data]
   1.103 -      (println-repl
   1.104 -       (map
   1.105 -        (fn [[yaw pitch roll]]
   1.106 -          [(rad->deg yaw)
   1.107 -           (rad->deg pitch)
   1.108 -           (rad->deg roll)])
   1.109 -        sensor-data)))))
   1.110 -
   1.111 -
   1.112  (defn draw-sprite [image sprite x y color ]
   1.113    (dorun
   1.114     (for [[u v] sprite]
   1.115 @@ -1239,7 +1149,7 @@
   1.116          bell (AudioNode. (asset-manager)
   1.117                           "Sounds/pure.wav" false)
   1.118          prop (proprioception creature)
   1.119 -        prop-debug (debug-prop-window)
   1.120 +        prop-debug (proprioception-debug-window)
   1.121          ;; dream
   1.122  
   1.123          ]