# HG changeset patch # User Robert McIntyre # Date 1325939054 25200 # Node ID 3e929630a25ff14a83ccff12c3be6e9d04ee7ea0 # Parent af1bb43661f95724cfc077fc271fcea4aa894ed2 multimethod dispatch works diff -r af1bb43661f9 -r 3e929630a25f org/test-creature.org --- a/org/test-creature.org Sat Jan 07 05:06:58 2012 -0700 +++ b/org/test-creature.org Sat Jan 07 05:24:14 2012 -0700 @@ -123,18 +123,11 @@ of object." [#^Spatial object world-coordinate] (let [out (Vector3f.)] - (.worldToLocal object world-coordinate out) out)) - -(defmulti zz - (fn [a b _ _ _ _ _] - - (:type a))) -(defmethod zz :p [a b] (println "hi")) - + (.worldToLocal object world-coordinate out) out)) (defmulti joint-dispatch "Translate blender pseudo-joints into real JME joints." - (fn [constraints _ _ _ _ _] + (fn [constraints & _] (:type constraints))) (defmethod joint-dispatch :point @@ -199,7 +192,7 @@ -(defn connect* +(defn connect "here are some examples: {:type :point} {:type :hinge :limit [0 (/ Math/PI 2)] :axis (Vector3f. 0 1 0)} @@ -234,101 +227,6 @@ (println-repl "could not find joint meta-data!")))) - - - -(defn connect - "here are some examples: - {:type :point} - {:type :hinge :limit [0 (/ Math/PI 2)] :axis (Vector3f. 0 1 0)} - (:axis defaults to (Vector3f. 1 0 0) if not provided for hinge joints) - - {: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 [control-a (.getControl obj-a RigidBodyControl) - control-b (.getControl obj-b RigidBodyControl) - joint-center (.getWorldTranslation joint) - joint-rotation (.toRotationMatrix (.getWorldRotation joint)) - pivot-a (world-to-local obj-a joint-center) - pivot-b (world-to-local obj-b joint-center)] - ;; 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-xz (:limit-xz constraints) - limit-xy (:limit-xy constraints) - twist (:twist constraints)] - - - (println-repl "creating CONE joint") - (println-repl joint-rotation) - (println-repl - "UNIT_X --> " (.mult joint-rotation (Vector3f. 1 0 0))) - (println-repl - "UNIT_Y --> " (.mult joint-rotation (Vector3f. 0 1 0))) - (println-repl - "UNIT_Z --> " (.mult joint-rotation (Vector3f. 0 0 1))) - (doto - (ConeJoint. - control-a - control-b - pivot-a - pivot-b - joint-rotation - joint-rotation - ) - (.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 (map @@ -353,7 +251,7 @@ (fn [joint] (let [[obj-a obj-b] (joint-targets pieces joint)] - (connect* obj-a obj-b joint))) + (connect obj-a obj-b joint))) joints)) pieces)