# HG changeset patch # User Robert McIntyre # Date 1325824294 25200 # Node ID 10f495560c5935a9616625ee93c8521d3fb1a6c9 # Parent 7af5ef6865393a4f8ef82d3825625cd549843284 correcting problem with joints diff -r 7af5ef686539 -r 10f495560c59 assets/Models/creature1/one.blend Binary file assets/Models/creature1/one.blend has changed diff -r 7af5ef686539 -r 10f495560c59 org/test-creature.org --- a/org/test-creature.org Thu Jan 05 02:35:07 2012 -0700 +++ b/org/test-creature.org Thu Jan 05 21:31:34 2012 -0700 @@ -116,120 +116,128 @@ {:type :cone :limit-xz 0] :limit-xy 0] :twist 0]} (use XZY rotation mode in blender!)" - ([#^Node obj-a #^Node obj-b #^Node joint] - (let [center-a (.getWorldTranslation obj-a) - center-b (.getWorldTranslation obj-b) - joint-center (.getWorldTranslation joint) - pivot-a (.subtract joint-center center-a) - pivot-b (.subtract joint-center center-b) - control-a (.getControl obj-a RigidBodyControl) - control-b (.getControl obj-b RigidBodyControl)] - ;; A side-effect of creating a joint registers - ;; it with both physics objects which in turn - ;; will register the joint with the physics system - ;; when the simulation is started. - (if-let [constraints - (map-vals - eval - (read-string - (meta-data joint "joint")))] + [#^Node obj-a #^Node obj-b #^Node joint] + (let [center-a (.getWorldTranslation obj-a) + center-b (.getWorldTranslation obj-b) + joint-center (.getWorldTranslation joint) + pivot-a (.subtract joint-center center-a) + pivot-b (.subtract joint-center center-b) + control-a (.getControl obj-a RigidBodyControl) + control-b (.getControl obj-b RigidBodyControl)] + ;; A side-effect of creating a joint registers + ;; it with both physics objects which in turn + ;; will register the joint with the physics system + ;; when the simulation is started. + (if-let [constraints + (map-vals + eval + (read-string + (meta-data joint "joint")))] - (let [joint-type (:type constraints)] - (println-repl "creating joint between" - (.getName obj-a) "and" (.getName obj-b)) - (cond (= :point joint-type) - (do - (println-repl "creating POINT joint") - (Point2PointJoint. - control-a - control-b - pivot-a - pivot-b)) - (= :hinge joint-type) - (do - (println-repl "creating HINGE joint") - (let [axis (if-let - [axis (:axis constraints)] - axis - Vector3f/UNIT_X) - [limit-1 limit-2] (:limit constraints) - hinge-axis - (.mult - (.getWorldRotation joint) - (blender-to-jme axis))] - (doto - (HingeJoint. - control-a - control-b - pivot-a - pivot-b - hinge-axis - hinge-axis) - (.setLimit limit-1 limit-2)))) - (= :cone joint-type) - (do - (let [limit-xy (:limit-xz constraints) - limit-yz (:limit-xy constraints) - twist (:twist constraints)] - - (println-repl "creating CONE joint") - (let [vector-1 - (.mult (.getWorldRotation joint) - Vector3f/UNIT_X) - vector-2 - (.normalize - (.subtract - (.getWorldTranslation joint) - (.getWorldTranslation obj-a))) - ] - (println-repl - "vector-1 :" vector-1) - (println-repl - "vector-2 :" vector-2) - - - - (doto - (ConeJoint. - control-a - control-b - pivot-a - pivot-b - - ;;(doto (Matrix3f.) - ;; (.fromStartEndVectors - ;; Vector3f/UNIT_X - ;; (.normalize - ;; (.subtract - ;; (.getWorldTranslation joint) - ;; (.getWorldTranslation obj-a))))) - - (.toRotationMatrix (.getWorldRotation joint)) + (let [joint-type (:type constraints)] + (println-repl "creating joint between" + (.getName obj-a) "and" (.getName obj-b)) + (cond (= :point joint-type) + (do + (println-repl "creating POINT joint") + (Point2PointJoint. + control-a + control-b + pivot-a + pivot-b)) + (= :hinge joint-type) + (do + (println-repl "creating HINGE joint") + (let [axis (if-let + [axis (:axis constraints)] + axis + Vector3f/UNIT_X) + [limit-1 limit-2] (:limit constraints) + hinge-axis + (.mult + (.getWorldRotation joint) + (blender-to-jme axis))] + (doto + (HingeJoint. + control-a + control-b + pivot-a + pivot-b + hinge-axis + hinge-axis) + (.setLimit limit-1 limit-2)))) + (= :cone joint-type) + (do + (let [limit-xz (:limit-xz constraints) + limit-xy (:limit-xy constraints) + twist (:twist constraints)] + + (println-repl "creating CONE joint") + (let [vector-1 + (.mult (.getWorldRotation joint) + Vector3f/UNIT_X) + vector-2 + (.normalize + (.subtract + (.getWorldTranslation joint) + (.getWorldTranslation obj-a))) + ] + (println-repl + "vector-1 :" vector-1) + (println-repl + "vector-2 :" vector-2) + + + + (doto + (ConeJoint. + control-a + control-b + pivot-a + pivot-b + + ;;(doto (Matrix3f.) + ;; (.fromStartEndVectors + ;; Vector3f/UNIT_X + ;; (.normalize + ;; (.subtract + ;; (.getWorldTranslation joint) + ;; (.getWorldTranslation obj-a))))) - (.toRotationMatrix - (.fromAngleAxis (Quaternion.) - (.angleBetween Vector3f/UNIT_X pivot-a) - (.cross Vector3f/UNIT_X pivot-a))) - - ;; (doto (Matrix3f.) - ;; (.fromStartEndVectors - ;; Vector3f/UNIT_X - ;; (.normalize - ;; vector-1))) - - ;; (doto (Matrix3f.) - ;; (.fromStartEndVectors - ;; Vector3f/UNIT_X - ;; vector-2)) - ) - (.setLimit (float limit-xy) - (float limit-yz) - (float twist)))))) - true - (println-repl - "joint-type" joint-type "not recognized"))) - - (println-repl "could not find joint meta-data!"))))) + + (.toRotationMatrix + (.getWorldRotation joint)) + + + + (.toRotationMatrix + (.fromAngleAxis + (Quaternion.) + (.angleBetween Vector3f/UNIT_X pivot-a) + (.cross Vector3f/UNIT_X pivot-a))) + + + + + ;; (doto (Matrix3f.) + ;; (.fromStartEndVectors + ;; Vector3f/UNIT_X + ;; (.normalize + ;; vector-1))) + + ;; (doto (Matrix3f.) + ;; (.fromStartEndVectors + ;; Vector3f/UNIT_X + ;; vector-2)) + ) + (.setLimit (float limit-xz) + (float limit-xy) + (float twist)))))) + true + (println-repl + "joint-type" joint-type "not recognized"))) + + (println-repl "could not find joint meta-data!")))) (defn assemble-creature [#^Node pieces joints] (dorun @@ -288,7 +296,7 @@ (box 0.01 0.01 1 :physical? false :color ColorRGBA/Blue)] (world (nodify [(blender-creature thing) - (box 10 2 10 :position (Vector3f. 0 -5.5 0) + (box 10 2 10 :position (Vector3f. 0 -9 0) :color ColorRGBA/Gray :mass 0) x-axis y-axis z-axis ])