comparison org/test-creature.org @ 89:cd5151b5e7c3

starting automatic touch for blender models
author Robert McIntyre <rlm@mit.edu>
date Sat, 07 Jan 2012 10:49:49 -0700
parents 3e929630a25f
children 6d7c17c847a3
comparison
equal deleted inserted replaced
88:3e929630a25f 89:cd5151b5e7c3
160 pivot-b 160 pivot-b
161 hinge-axis 161 hinge-axis
162 hinge-axis) 162 hinge-axis)
163 (.setLimit limit-1 limit-2)))) 163 (.setLimit limit-1 limit-2))))
164 164
165
166 (defmethod joint-dispatch :cone 165 (defmethod joint-dispatch :cone
167 [constraints control-a control-b pivot-a pivot-b rotation] 166 [constraints control-a control-b pivot-a pivot-b rotation]
168 (let [limit-xz (:limit-xz constraints) 167 (let [limit-xz (:limit-xz constraints)
169 limit-xy (:limit-xy constraints) 168 limit-xy (:limit-xy constraints)
170 twist (:twist constraints)] 169 twist (:twist constraints)]
171
172 170
173 (println-repl "creating CONE joint") 171 (println-repl "creating CONE joint")
174 (println-repl rotation) 172 (println-repl rotation)
175 (println-repl 173 (println-repl
176 "UNIT_X --> " (.mult rotation (Vector3f. 1 0 0))) 174 "UNIT_X --> " (.mult rotation (Vector3f. 1 0 0)))
188 rotation) 186 rotation)
189 (.setLimit (float limit-xz) 187 (.setLimit (float limit-xz)
190 (float limit-xy) 188 (float limit-xy)
191 (float twist))))) 189 (float twist)))))
192 190
193
194
195 (defn connect 191 (defn connect
196 "here are some examples: 192 "here are some examples:
197 {:type :point} 193 {:type :point}
198 {:type :hinge :limit [0 (/ Math/PI 2)] :axis (Vector3f. 0 1 0)} 194 {:type :hinge :limit [0 (/ Math/PI 2)] :axis (Vector3f. 0 1 0)}
199 (:axis defaults to (Vector3f. 1 0 0) if not provided for hinge joints) 195 (:axis defaults to (Vector3f. 1 0 0) if not provided for hinge joints)
200 196
201 {:type :cone :limit-xz 0] 197 {:type :cone :limit-xz 0]
202 :limit-xy 0] 198 :limit-xy 0]
203 :twist 0]} (use XZY rotation mode in blender!)" 199 :twist 0]} (use XZY rotation mode in blender!)"
204 [#^Node obj-a #^Node obj-b #^Node joint] 200 [#^Node obj-a #^Node obj-b #^Node joint]
205 (let [control-a (.getControl obj-a RigidBodyControl) 201 (let [control-a (.getControl obj-a RigidBodyControl)
206 control-b (.getControl obj-b RigidBodyControl) 202 control-b (.getControl obj-b RigidBodyControl)
207 joint-center (.getWorldTranslation joint) 203 joint-center (.getWorldTranslation joint)
208 joint-rotation (.toRotationMatrix (.getWorldRotation joint)) 204 joint-rotation (.toRotationMatrix (.getWorldRotation joint))
209 pivot-a (world-to-local obj-a joint-center) 205 pivot-a (world-to-local obj-a joint-center)
210 pivot-b (world-to-local obj-b joint-center)] 206 pivot-b (world-to-local obj-b joint-center)]
211 ;; A side-effect of creating a joint registers 207
212 ;; it with both physics objects which in turn
213 ;; will register the joint with the physics system
214 ;; when the simulation is started.
215 (if-let [constraints 208 (if-let [constraints
216 (map-vals 209 (map-vals
217 eval 210 eval
218 (read-string 211 (read-string
219 (meta-data joint "joint")))] 212 (meta-data joint "joint")))]
213 ;; A side-effect of creating a joint registers
214 ;; it with both physics objects which in turn
215 ;; will register the joint with the physics system
216 ;; when the simulation is started.
220 (do 217 (do
221 (println-repl "creating joint between" 218 (println-repl "creating joint between"
222 (.getName obj-a) "and" (.getName obj-b)) 219 (.getName obj-a) "and" (.getName obj-b))
223 (joint-dispatch constraints 220 (joint-dispatch constraints
224 control-a control-b 221 control-a control-b
225 pivot-a pivot-b 222 pivot-a pivot-b
226 joint-rotation)) 223 joint-rotation))
227
228 (println-repl "could not find joint meta-data!")))) 224 (println-repl "could not find joint meta-data!"))))
229 225
230 (defn assemble-creature [#^Node pieces joints] 226 (defn assemble-creature [#^Node pieces joints]
231 (dorun 227 (dorun
232 (map 228 (map
351 (.setLimit (* (/ 10) Math/PI) 347 (.setLimit (* (/ 10) Math/PI)
352 (* (/ 4) Math/PI) 348 (* (/ 4) Math/PI)
353 0))) 349 0)))
354 [origin top bottom table])) 350 [origin top bottom table]))
355 351
356
357
358 (defn test-joint [joint] 352 (defn test-joint [joint]
359 (let [[origin top bottom floor] (world-setup joint) 353 (let [[origin top bottom floor] (world-setup joint)
360 control (.getControl top RigidBodyControl) 354 control (.getControl top RigidBodyControl)
361 move-up? (atom false) 355 move-up? (atom false)
362 move-down? (atom false) 356 move-down? (atom false)