Mercurial > cortex
diff org/test-creature.org @ 81:10f495560c59
correcting problem with joints
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Thu, 05 Jan 2012 21:31:34 -0700 |
parents | 7af5ef686539 |
children | 6b4ca076285e |
line wrap: on
line diff
1.1 --- a/org/test-creature.org Thu Jan 05 02:35:07 2012 -0700 1.2 +++ b/org/test-creature.org Thu Jan 05 21:31:34 2012 -0700 1.3 @@ -116,120 +116,128 @@ 1.4 {:type :cone :limit-xz 0] 1.5 :limit-xy 0] 1.6 :twist 0]} (use XZY rotation mode in blender!)" 1.7 - ([#^Node obj-a #^Node obj-b #^Node joint] 1.8 - (let [center-a (.getWorldTranslation obj-a) 1.9 - center-b (.getWorldTranslation obj-b) 1.10 - joint-center (.getWorldTranslation joint) 1.11 - pivot-a (.subtract joint-center center-a) 1.12 - pivot-b (.subtract joint-center center-b) 1.13 - control-a (.getControl obj-a RigidBodyControl) 1.14 - control-b (.getControl obj-b RigidBodyControl)] 1.15 - ;; A side-effect of creating a joint registers 1.16 - ;; it with both physics objects which in turn 1.17 - ;; will register the joint with the physics system 1.18 - ;; when the simulation is started. 1.19 - (if-let [constraints 1.20 - (map-vals 1.21 - eval 1.22 - (read-string 1.23 - (meta-data joint "joint")))] 1.24 + [#^Node obj-a #^Node obj-b #^Node joint] 1.25 + (let [center-a (.getWorldTranslation obj-a) 1.26 + center-b (.getWorldTranslation obj-b) 1.27 + joint-center (.getWorldTranslation joint) 1.28 + pivot-a (.subtract joint-center center-a) 1.29 + pivot-b (.subtract joint-center center-b) 1.30 + control-a (.getControl obj-a RigidBodyControl) 1.31 + control-b (.getControl obj-b RigidBodyControl)] 1.32 + ;; A side-effect of creating a joint registers 1.33 + ;; it with both physics objects which in turn 1.34 + ;; will register the joint with the physics system 1.35 + ;; when the simulation is started. 1.36 + (if-let [constraints 1.37 + (map-vals 1.38 + eval 1.39 + (read-string 1.40 + (meta-data joint "joint")))] 1.41 1.42 - (let [joint-type (:type constraints)] 1.43 - (println-repl "creating joint between" 1.44 - (.getName obj-a) "and" (.getName obj-b)) 1.45 - (cond (= :point joint-type) 1.46 - (do 1.47 - (println-repl "creating POINT joint") 1.48 - (Point2PointJoint. 1.49 - control-a 1.50 - control-b 1.51 - pivot-a 1.52 - pivot-b)) 1.53 - (= :hinge joint-type) 1.54 - (do 1.55 - (println-repl "creating HINGE joint") 1.56 - (let [axis (if-let 1.57 - [axis (:axis constraints)] 1.58 - axis 1.59 - Vector3f/UNIT_X) 1.60 - [limit-1 limit-2] (:limit constraints) 1.61 - hinge-axis 1.62 - (.mult 1.63 - (.getWorldRotation joint) 1.64 - (blender-to-jme axis))] 1.65 - (doto 1.66 - (HingeJoint. 1.67 - control-a 1.68 - control-b 1.69 - pivot-a 1.70 - pivot-b 1.71 - hinge-axis 1.72 - hinge-axis) 1.73 - (.setLimit limit-1 limit-2)))) 1.74 - (= :cone joint-type) 1.75 - (do 1.76 - (let [limit-xy (:limit-xz constraints) 1.77 - limit-yz (:limit-xy constraints) 1.78 - twist (:twist constraints)] 1.79 - 1.80 - (println-repl "creating CONE joint") 1.81 - (let [vector-1 1.82 - (.mult (.getWorldRotation joint) 1.83 - Vector3f/UNIT_X) 1.84 - vector-2 1.85 - (.normalize 1.86 - (.subtract 1.87 - (.getWorldTranslation joint) 1.88 - (.getWorldTranslation obj-a))) 1.89 - ] 1.90 - (println-repl 1.91 - "vector-1 :" vector-1) 1.92 - (println-repl 1.93 - "vector-2 :" vector-2) 1.94 - 1.95 - 1.96 - 1.97 - (doto 1.98 - (ConeJoint. 1.99 - control-a 1.100 - control-b 1.101 - pivot-a 1.102 - pivot-b 1.103 - 1.104 - ;;(doto (Matrix3f.) 1.105 - ;; (.fromStartEndVectors 1.106 - ;; Vector3f/UNIT_X 1.107 - ;; (.normalize 1.108 - ;; (.subtract 1.109 - ;; (.getWorldTranslation joint) 1.110 - ;; (.getWorldTranslation obj-a))))) 1.111 - 1.112 - (.toRotationMatrix (.getWorldRotation joint)) 1.113 + (let [joint-type (:type constraints)] 1.114 + (println-repl "creating joint between" 1.115 + (.getName obj-a) "and" (.getName obj-b)) 1.116 + (cond (= :point joint-type) 1.117 + (do 1.118 + (println-repl "creating POINT joint") 1.119 + (Point2PointJoint. 1.120 + control-a 1.121 + control-b 1.122 + pivot-a 1.123 + pivot-b)) 1.124 + (= :hinge joint-type) 1.125 + (do 1.126 + (println-repl "creating HINGE joint") 1.127 + (let [axis (if-let 1.128 + [axis (:axis constraints)] 1.129 + axis 1.130 + Vector3f/UNIT_X) 1.131 + [limit-1 limit-2] (:limit constraints) 1.132 + hinge-axis 1.133 + (.mult 1.134 + (.getWorldRotation joint) 1.135 + (blender-to-jme axis))] 1.136 + (doto 1.137 + (HingeJoint. 1.138 + control-a 1.139 + control-b 1.140 + pivot-a 1.141 + pivot-b 1.142 + hinge-axis 1.143 + hinge-axis) 1.144 + (.setLimit limit-1 limit-2)))) 1.145 + (= :cone joint-type) 1.146 + (do 1.147 + (let [limit-xz (:limit-xz constraints) 1.148 + limit-xy (:limit-xy constraints) 1.149 + twist (:twist constraints)] 1.150 + 1.151 + (println-repl "creating CONE joint") 1.152 + (let [vector-1 1.153 + (.mult (.getWorldRotation joint) 1.154 + Vector3f/UNIT_X) 1.155 + vector-2 1.156 + (.normalize 1.157 + (.subtract 1.158 + (.getWorldTranslation joint) 1.159 + (.getWorldTranslation obj-a))) 1.160 + ] 1.161 + (println-repl 1.162 + "vector-1 :" vector-1) 1.163 + (println-repl 1.164 + "vector-2 :" vector-2) 1.165 + 1.166 + 1.167 + 1.168 + (doto 1.169 + (ConeJoint. 1.170 + control-a 1.171 + control-b 1.172 + pivot-a 1.173 + pivot-b 1.174 + 1.175 + ;;(doto (Matrix3f.) 1.176 + ;; (.fromStartEndVectors 1.177 + ;; Vector3f/UNIT_X 1.178 + ;; (.normalize 1.179 + ;; (.subtract 1.180 + ;; (.getWorldTranslation joint) 1.181 + ;; (.getWorldTranslation obj-a))))) 1.182 1.183 - (.toRotationMatrix 1.184 - (.fromAngleAxis (Quaternion.) 1.185 - (.angleBetween Vector3f/UNIT_X pivot-a) 1.186 - (.cross Vector3f/UNIT_X pivot-a))) 1.187 - 1.188 - ;; (doto (Matrix3f.) 1.189 - ;; (.fromStartEndVectors 1.190 - ;; Vector3f/UNIT_X 1.191 - ;; (.normalize 1.192 - ;; vector-1))) 1.193 - 1.194 - ;; (doto (Matrix3f.) 1.195 - ;; (.fromStartEndVectors 1.196 - ;; Vector3f/UNIT_X 1.197 - ;; vector-2)) 1.198 - ) 1.199 - (.setLimit (float limit-xy) 1.200 - (float limit-yz) 1.201 - (float twist)))))) 1.202 - true 1.203 - (println-repl 1.204 - "joint-type" joint-type "not recognized"))) 1.205 - 1.206 - (println-repl "could not find joint meta-data!"))))) 1.207 + 1.208 + (.toRotationMatrix 1.209 + (.getWorldRotation joint)) 1.210 + 1.211 + 1.212 + 1.213 + (.toRotationMatrix 1.214 + (.fromAngleAxis 1.215 + (Quaternion.) 1.216 + (.angleBetween Vector3f/UNIT_X pivot-a) 1.217 + (.cross Vector3f/UNIT_X pivot-a))) 1.218 + 1.219 + 1.220 + 1.221 + 1.222 + ;; (doto (Matrix3f.) 1.223 + ;; (.fromStartEndVectors 1.224 + ;; Vector3f/UNIT_X 1.225 + ;; (.normalize 1.226 + ;; vector-1))) 1.227 + 1.228 + ;; (doto (Matrix3f.) 1.229 + ;; (.fromStartEndVectors 1.230 + ;; Vector3f/UNIT_X 1.231 + ;; vector-2)) 1.232 + ) 1.233 + (.setLimit (float limit-xz) 1.234 + (float limit-xy) 1.235 + (float twist)))))) 1.236 + true 1.237 + (println-repl 1.238 + "joint-type" joint-type "not recognized"))) 1.239 + 1.240 + (println-repl "could not find joint meta-data!")))) 1.241 1.242 (defn assemble-creature [#^Node pieces joints] 1.243 (dorun 1.244 @@ -288,7 +296,7 @@ 1.245 (box 0.01 0.01 1 :physical? false :color ColorRGBA/Blue)] 1.246 (world 1.247 (nodify [(blender-creature thing) 1.248 - (box 10 2 10 :position (Vector3f. 0 -5.5 0) 1.249 + (box 10 2 10 :position (Vector3f. 0 -9 0) 1.250 :color ColorRGBA/Gray :mass 0) 1.251 x-axis y-axis z-axis 1.252 ])