diff org/test-creature.org @ 79:01dbdb0d5500

offset cone joints achieved!
author Robert McIntyre <rlm@mit.edu>
date Wed, 04 Jan 2012 21:03:25 -0700
parents 77b506ac64f3
children 7af5ef686539
line wrap: on
line diff
     1.1 --- a/org/test-creature.org	Wed Jan 04 20:34:00 2012 -0700
     1.2 +++ b/org/test-creature.org	Wed Jan 04 21:03:25 2012 -0700
     1.3 @@ -70,6 +70,13 @@
     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 @@ -88,11 +95,15 @@
    1.18               (map  #(.getGeometry %) results))]
    1.19          (if (>= (count targets) 2)
    1.20            (sort-by
    1.21 -           #(.getY
    1.22 -             (.mult
    1.23 -              (.inverse (.getWorldRotation joint))
    1.24 -              (.subtract (.getWorldTranslation %)
    1.25 -                         (.getWorldTranslation joint))))
    1.26 +           #(let [v
    1.27 +                  (jme-to-blender
    1.28 +                   (.mult
    1.29 +                    (.inverse (.getWorldRotation joint))
    1.30 +                    (.subtract (.getWorldTranslation %)
    1.31 +                               (.getWorldTranslation joint))))]
    1.32 +              (println-repl (.getName %) ":" v)
    1.33 +              (.dot (Vector3f. 1 1 1)
    1.34 +                    v))                  
    1.35             (take 2 targets))
    1.36            (recur (float (* radius 2))))))))
    1.37  
    1.38 @@ -103,8 +114,8 @@
    1.39     (:axis defaults to (Vector3f. 1 0 0) if not provided for hinge joints)
    1.40  
    1.41     {:type :cone   :limit-xz 0]
    1.42 -                  :limit-yz 0]
    1.43 -                  :twist 0]}"
    1.44 +                  :limit-xy 0]
    1.45 +                  :twist 0]}   (use XZY rotation mode in blender!)"
    1.46    ([#^Node obj-a #^Node obj-b #^Node joint]
    1.47       (let [center-a (.getWorldTranslation obj-a)
    1.48             center-b (.getWorldTranslation obj-b)
    1.49 @@ -158,7 +169,7 @@
    1.50                   (= :cone joint-type)
    1.51                   (do
    1.52                     (let [limit-xy (:limit-xz constraints)
    1.53 -                         limit-yz (:limit-yz constraints)
    1.54 +                         limit-yz (:limit-xy constraints)
    1.55                           twist    (:twist constraints)]
    1.56                       
    1.57                       (println-repl "creating CONE joint")
    1.58 @@ -168,19 +179,18 @@
    1.59                            control-b
    1.60                            pivot-a
    1.61                            pivot-b
    1.62 -                          (doto (Matrix3f.)
    1.63 -                            (.fromStartEndVectors
    1.64 -                             Vector3f/UNIT_X
    1.65 -                             (.normalize
    1.66 -                              (.subtract (.getWorldTranslation joint)
    1.67 -                                         (.getWorldTranslation obj-a)))))
    1.68 +                          
    1.69                            (doto (Matrix3f.)
    1.70                              (.fromStartEndVectors
    1.71                               Vector3f/UNIT_X
    1.72                               (.normalize
    1.73                                (.subtract
    1.74 -                               (.getWorldTranslation obj-b)
    1.75 -                               (.getWorldTranslation joint))))))
    1.76 +                               (.getWorldTranslation joint)
    1.77 +                               (.getWorldTranslation obj-a)))))
    1.78 +                          (doto (Matrix3f.)
    1.79 +                            (.set (.getWorldRotation joint)))
    1.80 +                          
    1.81 +                          )
    1.82                         (.setLimit (float limit-xy)
    1.83                                    (float limit-yz)
    1.84                                    (float twist)))))