Mercurial > cortex
changeset 55:8b95180f5c69
getting basic hinges to work
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Tue, 15 Nov 2011 17:48:10 -0700 |
parents | 7bc3b22c507b |
children | 8b571c137f81 |
files | org/body.org |
diffstat | 1 files changed, 44 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
1.1 --- a/org/body.org Tue Nov 15 00:53:06 2011 -0700 1.2 +++ b/org/body.org Tue Nov 15 17:48:10 2011 -0700 1.3 @@ -119,9 +119,6 @@ 1.4 ["mid2" "tail" "head" "mid1" "mid3" "mid4" "Dummy-Root" ""] 1.5 ;;"mid2" "mid3" "tail" "head"] 1.6 ))) 1.7 - 1.8 - 1.9 - 1.10 (.addControl node krc) 1.11 (.setRagdollMode krc) 1.12 ) 1.13 @@ -157,7 +154,6 @@ 1.14 (println (.getName b) 1.15 " -- " (f b))) 1.16 bones)) 1.17 - 1.18 (dorun 1.19 (map #(.attachChild 1.20 debug-node 1.21 @@ -194,11 +190,8 @@ 1.22 ;; 0 1.23 1.24 (Vector3f. 1 1 1)) 1.25 - 1.26 ) 1.27 1.28 - 1.29 - 1.30 (println-repl "hi! <3")))) 1.31 1.32 1.33 @@ -242,10 +235,53 @@ 1.34 1.35 1.36 1.37 - 1.38 1.39 +(defn joint-control 1.40 + [joint] 1.41 + (let [physics-space (ref nil) 1.42 + enabled? (ref true)] 1.43 + (reify PhysicsControl 1.44 + (setPhysicsSpace [this space] 1.45 + (dosync 1.46 + (ref-set physics-space space)) 1.47 + (.addJoint space joint)) 1.48 + (update [this tpf]) 1.49 + (setSpatial [this spatial]) 1.50 + (render [this rm vp]) 1.51 + (getPhysicsSpace [this] (deref physics-space)) 1.52 + (isEnabled [this] (deref enabled?)) 1.53 + (setEnabled [this state] 1.54 + (dosync (ref-set enabled? state)))))) 1.55 1.56 +(defn add-joint 1.57 + "Add a joint to a particular object. When the object is added to the 1.58 + PhysicsSpace of a simulation, the joint will also be added" 1.59 + [object joint] 1.60 + (let [control (joint-control joint)] 1.61 + (.addControl object control)) 1.62 + object) 1.63 1.64 +(defn hinge-world 1.65 + [] 1.66 + (let [sphere1 (sphere) 1.67 + sphere2 (sphere 1 :position (Vector3f. 3 3 3)) 1.68 + joint (Point2PointJoint. 1.69 + (.getControl sphere1 RigidBodyControl) 1.70 + (.getControl sphere2 RigidBodyControl) 1.71 + Vector3f/ZERO (Vector3f. 3 3 3))] 1.72 + (add-joint sphere1 joint) 1.73 + (doto (Node. "hinge-world") 1.74 + (.attachChild sphere1) 1.75 + (.attachChild sphere2)))) 1.76 + 1.77 + 1.78 +(defn test-joint 1.79 + [] 1.80 + (.start 1.81 + (world 1.82 + (doto (Node.) 1.83 + (.attachChild 1.84 + 1.85 1.86 1.87