# HG changeset patch # User Robert McIntyre # Date 1321404490 25200 # Node ID 8b95180f5c691cbc880f8d999c743917aa02bc5d # Parent 7bc3b22c507bf6e977b051142474dc76d417e0bf getting basic hinges to work diff -r 7bc3b22c507b -r 8b95180f5c69 org/body.org --- a/org/body.org Tue Nov 15 00:53:06 2011 -0700 +++ b/org/body.org Tue Nov 15 17:48:10 2011 -0700 @@ -119,9 +119,6 @@ ["mid2" "tail" "head" "mid1" "mid3" "mid4" "Dummy-Root" ""] ;;"mid2" "mid3" "tail" "head"] ))) - - - (.addControl node krc) (.setRagdollMode krc) ) @@ -157,7 +154,6 @@ (println (.getName b) " -- " (f b))) bones)) - (dorun (map #(.attachChild debug-node @@ -194,11 +190,8 @@ ;; 0 (Vector3f. 1 1 1)) - ) - - (println-repl "hi! <3")))) @@ -242,10 +235,53 @@ - +(defn joint-control + [joint] + (let [physics-space (ref nil) + enabled? (ref true)] + (reify PhysicsControl + (setPhysicsSpace [this space] + (dosync + (ref-set physics-space space)) + (.addJoint space joint)) + (update [this tpf]) + (setSpatial [this spatial]) + (render [this rm vp]) + (getPhysicsSpace [this] (deref physics-space)) + (isEnabled [this] (deref enabled?)) + (setEnabled [this state] + (dosync (ref-set enabled? state)))))) +(defn add-joint + "Add a joint to a particular object. When the object is added to the + PhysicsSpace of a simulation, the joint will also be added" + [object joint] + (let [control (joint-control joint)] + (.addControl object control)) + object) +(defn hinge-world + [] + (let [sphere1 (sphere) + sphere2 (sphere 1 :position (Vector3f. 3 3 3)) + joint (Point2PointJoint. + (.getControl sphere1 RigidBodyControl) + (.getControl sphere2 RigidBodyControl) + Vector3f/ZERO (Vector3f. 3 3 3))] + (add-joint sphere1 joint) + (doto (Node. "hinge-world") + (.attachChild sphere1) + (.attachChild sphere2)))) + + +(defn test-joint + [] + (.start + (world + (doto (Node.) + (.attachChild +