changeset 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
files assets/Models/creature1/one.blend assets/Models/creature1/try-again.blend org/test-creature.org
diffstat 3 files changed, 26 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
     1.1 Binary file assets/Models/creature1/one.blend has changed
     2.1 Binary file assets/Models/creature1/try-again.blend has changed
     3.1 --- a/org/test-creature.org	Wed Jan 04 20:34:00 2012 -0700
     3.2 +++ b/org/test-creature.org	Wed Jan 04 21:03:25 2012 -0700
     3.3 @@ -70,6 +70,13 @@
     3.4               (.getZ in)
     3.5               (- (.getY in))))
     3.6  
     3.7 +(defn jme-to-blender
     3.8 +  "Convert from JME coordinates to Blender coordinates"
     3.9 +  [#^Vector3f in]
    3.10 +  (Vector3f. (.getX in)
    3.11 +             (- (.getZ in))
    3.12 +             (.getY in)))
    3.13 +
    3.14  (defn joint-targets
    3.15    "Return the two closest two objects to the joint object, ordered
    3.16    from bottom to top according to the joint's rotation."
    3.17 @@ -88,11 +95,15 @@
    3.18               (map  #(.getGeometry %) results))]
    3.19          (if (>= (count targets) 2)
    3.20            (sort-by
    3.21 -           #(.getY
    3.22 -             (.mult
    3.23 -              (.inverse (.getWorldRotation joint))
    3.24 -              (.subtract (.getWorldTranslation %)
    3.25 -                         (.getWorldTranslation joint))))
    3.26 +           #(let [v
    3.27 +                  (jme-to-blender
    3.28 +                   (.mult
    3.29 +                    (.inverse (.getWorldRotation joint))
    3.30 +                    (.subtract (.getWorldTranslation %)
    3.31 +                               (.getWorldTranslation joint))))]
    3.32 +              (println-repl (.getName %) ":" v)
    3.33 +              (.dot (Vector3f. 1 1 1)
    3.34 +                    v))                  
    3.35             (take 2 targets))
    3.36            (recur (float (* radius 2))))))))
    3.37  
    3.38 @@ -103,8 +114,8 @@
    3.39     (:axis defaults to (Vector3f. 1 0 0) if not provided for hinge joints)
    3.40  
    3.41     {:type :cone   :limit-xz 0]
    3.42 -                  :limit-yz 0]
    3.43 -                  :twist 0]}"
    3.44 +                  :limit-xy 0]
    3.45 +                  :twist 0]}   (use XZY rotation mode in blender!)"
    3.46    ([#^Node obj-a #^Node obj-b #^Node joint]
    3.47       (let [center-a (.getWorldTranslation obj-a)
    3.48             center-b (.getWorldTranslation obj-b)
    3.49 @@ -158,7 +169,7 @@
    3.50                   (= :cone joint-type)
    3.51                   (do
    3.52                     (let [limit-xy (:limit-xz constraints)
    3.53 -                         limit-yz (:limit-yz constraints)
    3.54 +                         limit-yz (:limit-xy constraints)
    3.55                           twist    (:twist constraints)]
    3.56                       
    3.57                       (println-repl "creating CONE joint")
    3.58 @@ -168,19 +179,18 @@
    3.59                            control-b
    3.60                            pivot-a
    3.61                            pivot-b
    3.62 -                          (doto (Matrix3f.)
    3.63 -                            (.fromStartEndVectors
    3.64 -                             Vector3f/UNIT_X
    3.65 -                             (.normalize
    3.66 -                              (.subtract (.getWorldTranslation joint)
    3.67 -                                         (.getWorldTranslation obj-a)))))
    3.68 +                          
    3.69                            (doto (Matrix3f.)
    3.70                              (.fromStartEndVectors
    3.71                               Vector3f/UNIT_X
    3.72                               (.normalize
    3.73                                (.subtract
    3.74 -                               (.getWorldTranslation obj-b)
    3.75 -                               (.getWorldTranslation joint))))))
    3.76 +                               (.getWorldTranslation joint)
    3.77 +                               (.getWorldTranslation obj-a)))))
    3.78 +                          (doto (Matrix3f.)
    3.79 +                            (.set (.getWorldRotation joint)))
    3.80 +                          
    3.81 +                          )
    3.82                         (.setLimit (float limit-xy)
    3.83                                    (float limit-yz)
    3.84                                    (float twist)))))