rlm@73
|
1 #+title: First attempt at a creature!
|
rlm@73
|
2 #+author: Robert McIntyre
|
rlm@73
|
3 #+email: rlm@mit.edu
|
rlm@73
|
4 #+description:
|
rlm@73
|
5 #+keywords: simulation, jMonkeyEngine3, clojure
|
rlm@73
|
6 #+SETUPFILE: ../../aurellem/org/setup.org
|
rlm@73
|
7 #+INCLUDE: ../../aurellem/org/level-0.org
|
rlm@73
|
8
|
rlm@73
|
9 * Intro
|
rlm@73
|
10 So far, I've made the following senses --
|
rlm@73
|
11 - Vision
|
rlm@73
|
12 - Hearing
|
rlm@73
|
13 - Touch
|
rlm@73
|
14 - Proprioception
|
rlm@73
|
15
|
rlm@73
|
16 And one effector:
|
rlm@73
|
17 - Movement
|
rlm@73
|
18
|
rlm@73
|
19 However, the code so far has only enabled these senses, but has not
|
rlm@73
|
20 actually implemented them. For example, there is still a lot of work
|
rlm@73
|
21 to be done for vision. I need to be able to create an /eyeball/ in
|
rlm@73
|
22 simulation that can be moved around and see the world from different
|
rlm@73
|
23 angles. I also need to determine weather to use log-polar or cartesian
|
rlm@73
|
24 for the visual input, and I need to determine how/wether to
|
rlm@73
|
25 disceritise the visual input.
|
rlm@73
|
26
|
rlm@73
|
27 I also want to be able to visualize both the sensors and the
|
rlm@73
|
28 effectors in pretty pictures. This semi-retarted creature will by my
|
rlm@73
|
29 first attempt at bringing everything together.
|
rlm@73
|
30
|
rlm@73
|
31 * The creature's body
|
rlm@73
|
32
|
rlm@73
|
33 Still going to do an eve-like body in blender, but due to problems
|
rlm@73
|
34 importing the joints, etc into jMonkeyEngine3, I',m going to do all
|
rlm@73
|
35 the connecting here in clojure code, using the names of the individual
|
rlm@73
|
36 components and trial and error. Later, I'll maybe make some sort of
|
rlm@73
|
37 creature-building modifications to blender that support whatever
|
rlm@73
|
38 discreitized senses I'm going to make.
|
rlm@73
|
39
|
rlm@73
|
40 #+name: body-1
|
rlm@73
|
41 #+begin_src clojure
|
rlm@73
|
42 (ns cortex.silly
|
rlm@73
|
43 "let's play!"
|
rlm@73
|
44 {:author "Robert McIntyre"})
|
rlm@73
|
45
|
rlm@73
|
46 ;; TODO remove this!
|
rlm@73
|
47 (require 'cortex.import)
|
rlm@73
|
48 (cortex.import/mega-import-jme3)
|
rlm@73
|
49 (use '(cortex world util body hearing touch vision))
|
rlm@73
|
50
|
rlm@73
|
51 (rlm.rlm-commands/help)
|
rlm@73
|
52
|
rlm@73
|
53 (defn load-blender-model
|
rlm@73
|
54 "Load a .blend file using an asset folder relative path."
|
rlm@73
|
55 [^String model]
|
rlm@73
|
56 (.loadModel
|
rlm@73
|
57 (doto (asset-manager)
|
rlm@73
|
58 (.registerLoader BlenderModelLoader (into-array String ["blend"])))
|
rlm@73
|
59 model))
|
rlm@73
|
60
|
rlm@74
|
61 (defn meta-data [blender-node key]
|
rlm@74
|
62 (if-let [data (.getUserData blender-node "properties")]
|
rlm@74
|
63 (.findValue data key)
|
rlm@74
|
64 nil))
|
rlm@73
|
65
|
rlm@78
|
66 (defn blender-to-jme
|
rlm@78
|
67 "Convert from Blender coordinates to JME coordinates"
|
rlm@78
|
68 [#^Vector3f in]
|
rlm@78
|
69 (Vector3f. (.getX in)
|
rlm@78
|
70 (.getZ in)
|
rlm@78
|
71 (- (.getY in))))
|
rlm@74
|
72
|
rlm@78
|
73 (defn joint-targets
|
rlm@78
|
74 "Return the two closest two objects to the joint object, ordered
|
rlm@78
|
75 from bottom to top according to the joint's rotation."
|
rlm@78
|
76 [#^Node parts #^Node joint]
|
rlm@78
|
77 ;;(println (meta-data joint "joint"))
|
rlm@78
|
78 (.getWorldRotation joint)
|
rlm@78
|
79 (loop [radius (float 0.01)]
|
rlm@78
|
80 (let [results (CollisionResults.)]
|
rlm@78
|
81 (.collideWith
|
rlm@78
|
82 parts
|
rlm@78
|
83 (BoundingBox. (.getWorldTranslation joint)
|
rlm@78
|
84 radius radius radius)
|
rlm@78
|
85 results)
|
rlm@78
|
86 (let [targets
|
rlm@78
|
87 (distinct
|
rlm@78
|
88 (map #(.getGeometry %) results))]
|
rlm@78
|
89 (if (>= (count targets) 2)
|
rlm@78
|
90 (sort-by
|
rlm@78
|
91 #(.getY
|
rlm@78
|
92 (.mult
|
rlm@78
|
93 (.inverse (.getWorldRotation joint))
|
rlm@78
|
94 (.subtract (.getWorldTranslation %)
|
rlm@78
|
95 (.getWorldTranslation joint))))
|
rlm@78
|
96 (take 2 targets))
|
rlm@78
|
97 (recur (float (* radius 2))))))))
|
rlm@74
|
98
|
rlm@78
|
99 (defn connect
|
rlm@78
|
100 "here are some examples:
|
rlm@78
|
101 {:type :point}
|
rlm@78
|
102 {:type :hinge :limit [0 (/ Math/PI 2)] :axis (Vector3f. 0 1 0)}
|
rlm@78
|
103 (:axis defaults to (Vector3f. 1 0 0) if not provided for hinge joints)
|
rlm@74
|
104
|
rlm@78
|
105 {:type :cone :limit-xz 0]
|
rlm@78
|
106 :limit-yz 0]
|
rlm@78
|
107 :twist 0]}"
|
rlm@78
|
108 ([#^Node obj-a #^Node obj-b #^Node joint]
|
rlm@78
|
109 (let [center-a (.getWorldTranslation obj-a)
|
rlm@78
|
110 center-b (.getWorldTranslation obj-b)
|
rlm@78
|
111 joint-center (.getWorldTranslation joint)
|
rlm@78
|
112 pivot-a (.subtract joint-center center-a)
|
rlm@78
|
113 pivot-b (.subtract joint-center center-b)
|
rlm@78
|
114 control-a (.getControl obj-a RigidBodyControl)
|
rlm@78
|
115 control-b (.getControl obj-b RigidBodyControl)]
|
rlm@78
|
116 ;; A side-effect of creating a joint registers
|
rlm@78
|
117 ;; it with both physics objects which in turn
|
rlm@78
|
118 ;; will register the joint with the physics system
|
rlm@78
|
119 ;; when the simulation is started.
|
rlm@78
|
120 (if-let [constraints
|
rlm@78
|
121 (map-vals
|
rlm@78
|
122 eval
|
rlm@78
|
123 (read-string
|
rlm@78
|
124 (meta-data joint "joint")))]
|
rlm@74
|
125
|
rlm@78
|
126 (let [joint-type (:type constraints)]
|
rlm@78
|
127 (println-repl "creating joint between"
|
rlm@78
|
128 (.getName obj-a) "and" (.getName obj-b))
|
rlm@78
|
129 (cond (= :point joint-type)
|
rlm@78
|
130 (do
|
rlm@78
|
131 (println-repl "creating POINT joint")
|
rlm@78
|
132 (Point2PointJoint.
|
rlm@78
|
133 control-a
|
rlm@78
|
134 control-b
|
rlm@78
|
135 pivot-a
|
rlm@78
|
136 pivot-b))
|
rlm@78
|
137 (= :hinge joint-type)
|
rlm@78
|
138 (do
|
rlm@78
|
139 (println-repl "creating HINGE joint")
|
rlm@78
|
140 (let [axis (if-let
|
rlm@78
|
141 [axis (:axis constraints)]
|
rlm@78
|
142 axis
|
rlm@78
|
143 Vector3f/UNIT_X)
|
rlm@78
|
144 [limit-1 limit-2] (:limit constraints)
|
rlm@78
|
145 hinge-axis
|
rlm@78
|
146 (.mult
|
rlm@78
|
147 (.getWorldRotation joint)
|
rlm@78
|
148 (blender-to-jme axis))]
|
rlm@78
|
149 (doto
|
rlm@78
|
150 (HingeJoint.
|
rlm@78
|
151 control-a
|
rlm@78
|
152 control-b
|
rlm@78
|
153 pivot-a
|
rlm@78
|
154 pivot-b
|
rlm@78
|
155 hinge-axis
|
rlm@78
|
156 hinge-axis)
|
rlm@78
|
157 (.setLimit limit-1 limit-2))))
|
rlm@78
|
158 (= :cone joint-type)
|
rlm@78
|
159 (do
|
rlm@78
|
160 (let [limit-xy (:limit-xz constraints)
|
rlm@78
|
161 limit-yz (:limit-yz constraints)
|
rlm@78
|
162 twist (:twist constraints)]
|
rlm@78
|
163
|
rlm@78
|
164 (println-repl "creating CONE joint")
|
rlm@78
|
165 (doto
|
rlm@78
|
166 (ConeJoint.
|
rlm@78
|
167 control-a
|
rlm@78
|
168 control-b
|
rlm@78
|
169 pivot-a
|
rlm@78
|
170 pivot-b
|
rlm@78
|
171 (doto (Matrix3f.)
|
rlm@78
|
172 (.fromStartEndVectors
|
rlm@78
|
173 Vector3f/UNIT_X
|
rlm@78
|
174 (.normalize
|
rlm@78
|
175 (.subtract (.getWorldTranslation joint)
|
rlm@78
|
176 (.getWorldTranslation obj-a)))))
|
rlm@78
|
177 (doto (Matrix3f.)
|
rlm@78
|
178 (.fromStartEndVectors
|
rlm@78
|
179 Vector3f/UNIT_X
|
rlm@78
|
180 (.normalize
|
rlm@78
|
181 (.subtract
|
rlm@78
|
182 (.getWorldTranslation obj-b)
|
rlm@78
|
183 (.getWorldTranslation joint))))))
|
rlm@78
|
184 (.setLimit (float limit-xy)
|
rlm@78
|
185 (float limit-yz)
|
rlm@78
|
186 (float twist)))))
|
rlm@78
|
187 true
|
rlm@78
|
188 (println-repl
|
rlm@78
|
189 "joint-type" joint-type "not recognized")))
|
rlm@78
|
190
|
rlm@78
|
191 (println-repl "could not find joint meta-data!")))))
|
rlm@74
|
192
|
rlm@78
|
193 (defn assemble-creature [#^Node pieces joints]
|
rlm@78
|
194 (dorun
|
rlm@78
|
195 (map
|
rlm@78
|
196 (fn [geom]
|
rlm@78
|
197 (let [physics-control
|
rlm@78
|
198 (RigidBodyControl.
|
rlm@78
|
199 (HullCollisionShape.
|
rlm@78
|
200 (.getMesh geom))
|
rlm@78
|
201 (if-let [mass (meta-data geom "mass")]
|
rlm@78
|
202 (do
|
rlm@78
|
203 (println-repl
|
rlm@78
|
204 "setting" (.getName geom) "mass to" (float mass))
|
rlm@78
|
205 (float mass))
|
rlm@78
|
206 (float 1)))]
|
rlm@78
|
207
|
rlm@78
|
208 (.addControl geom physics-control)))
|
rlm@78
|
209 (filter #(isa? (class %) Geometry )
|
rlm@78
|
210 (node-seq pieces))))
|
rlm@77
|
211
|
rlm@78
|
212 (dorun
|
rlm@78
|
213 (map
|
rlm@78
|
214 (fn [joint]
|
rlm@78
|
215 (let [[obj-a obj-b]
|
rlm@78
|
216 (joint-targets pieces joint)]
|
rlm@78
|
217 (connect obj-a obj-b joint)))
|
rlm@78
|
218 joints))
|
rlm@78
|
219 pieces)
|
rlm@74
|
220
|
rlm@78
|
221 (defn blender-creature [blender-path]
|
rlm@78
|
222 (let [model (load-blender-model blender-path)
|
rlm@78
|
223 joints
|
rlm@78
|
224 (if-let [joint-node (.getChild model "joints")]
|
rlm@78
|
225 (seq (.getChildren joint-node))
|
rlm@78
|
226 (do (println-repl "could not find joints node")
|
rlm@78
|
227 []))]
|
rlm@78
|
228 (assemble-creature model joints)))
|
rlm@74
|
229
|
rlm@78
|
230 (def hand "Models/creature1/one.blend")
|
rlm@74
|
231
|
rlm@78
|
232 (def worm "Models/creature1/try-again.blend")
|
rlm@78
|
233
|
rlm@78
|
234 (defn test-creature [thing]
|
rlm@78
|
235 (world
|
rlm@78
|
236 (nodify [(blender-creature thing)
|
rlm@78
|
237 (box 10 2 10 :position (Vector3f. 0 -5.5 0)
|
rlm@78
|
238 :color ColorRGBA/Gray :mass 0)])
|
rlm@78
|
239 standard-debug-controls
|
rlm@78
|
240 (comp light-up-everything enable-debug
|
rlm@78
|
241 (fn [world]
|
rlm@78
|
242 (.setTimer world (NanoTimer.))
|
rlm@78
|
243 ;;(set-gravity world (Vector3f. 0 0 0))
|
rlm@78
|
244 (speed-up world)
|
rlm@78
|
245 world
|
rlm@78
|
246 ))
|
rlm@78
|
247 no-op))
|
rlm@78
|
248
|
rlm@78
|
249 (defn world-setup [joint]
|
rlm@78
|
250 (let [top (doto
|
rlm@78
|
251 (sphere 0.1 :physical? false :color ColorRGBA/Yellow
|
rlm@78
|
252 :position (Vector3f. 0 7 0))
|
rlm@78
|
253 (.addControl
|
rlm@78
|
254 (RigidBodyControl.
|
rlm@78
|
255 (CapsuleCollisionShape. 0.5 1.5 1) (float 15))))
|
rlm@78
|
256 bottom (doto
|
rlm@78
|
257 (sphere 0.1 :physical? false :color ColorRGBA/DarkGray
|
rlm@78
|
258 :position (Vector3f. 0 -1 0))
|
rlm@78
|
259 (.addControl
|
rlm@78
|
260 (RigidBodyControl.
|
rlm@78
|
261 (CapsuleCollisionShape. 0.5 1.5 1) (float 0))))
|
rlm@78
|
262 table (box 10 2 10 :position (Vector3f. 0 -6 0)
|
rlm@78
|
263 :color ColorRGBA/Gray :mass 0)
|
rlm@78
|
264 a (.getControl top RigidBodyControl)
|
rlm@78
|
265 b (.getControl bottom RigidBodyControl)]
|
rlm@78
|
266 (cond
|
rlm@78
|
267 (= joint :point)
|
rlm@78
|
268 (doto
|
rlm@78
|
269 (Point2PointJoint. a b
|
rlm@78
|
270 (Vector3f. 0 -2 0)
|
rlm@78
|
271 (Vector3f. 0 2 0))
|
rlm@78
|
272 (.setCollisionBetweenLinkedBodys false))
|
rlm@78
|
273 (= joint :hinge)
|
rlm@78
|
274 (doto
|
rlm@78
|
275 (HingeJoint.
|
rlm@78
|
276 a b
|
rlm@78
|
277 (Vector3f. 0 -2 0)
|
rlm@78
|
278 (Vector3f. 0 2 0)
|
rlm@78
|
279 (Vector3f. 0 0 1)
|
rlm@78
|
280 (Vector3f. 0 0 1)
|
rlm@78
|
281
|
rlm@78
|
282 )
|
rlm@78
|
283 (.setCollisionBetweenLinkedBodys false)
|
rlm@78
|
284 ;;(.setLimit (- Math/PI) Math/PI)
|
rlm@78
|
285 )
|
rlm@78
|
286 (= joint :cone)
|
rlm@78
|
287 ;; note to self -- jbullet does NOT implement cone joints
|
rlm@78
|
288 ;; correctly. You must use plain ol' bullet for this to work.
|
rlm@78
|
289 ;; It's faster anyway, so whatever.
|
rlm@78
|
290
|
rlm@78
|
291 (doto (ConeJoint.
|
rlm@78
|
292 a b
|
rlm@78
|
293 (Vector3f. 0 -5 0)
|
rlm@78
|
294 (Vector3f. 0 2 0)
|
rlm@78
|
295
|
rlm@78
|
296 (doto (Matrix3f.)
|
rlm@78
|
297 (.fromStartEndVectors Vector3f/UNIT_X
|
rlm@78
|
298 Vector3f/UNIT_Y))
|
rlm@78
|
299 (doto (Matrix3f.)
|
rlm@78
|
300 (.fromStartEndVectors Vector3f/UNIT_X
|
rlm@78
|
301 (.normalize
|
rlm@78
|
302 (Vector3f. 5 5 0))))
|
rlm@78
|
303 )
|
rlm@78
|
304 ;;(.setAngularOnly true)
|
rlm@78
|
305
|
rlm@78
|
306 (.setCollisionBetweenLinkedBodys false)
|
rlm@78
|
307 (.setLimit (* 1 (/ Math/PI 4))
|
rlm@78
|
308 (* 1 (/ Math/PI 2))
|
rlm@78
|
309 (* 0 (/ Math/PI 4)))
|
rlm@78
|
310
|
rlm@78
|
311 )
|
rlm@78
|
312 (= joint :six)
|
rlm@78
|
313 (doto
|
rlm@78
|
314 (SixDofJoint.
|
rlm@78
|
315 a b
|
rlm@78
|
316 (Vector3f. 0 -2 0)
|
rlm@78
|
317 (Vector3f. 0 2 0)
|
rlm@78
|
318 ;;(doto (Matrix3f.)
|
rlm@78
|
319 ;; (.fromStartEndVectors Vector3f/UNIT_X
|
rlm@78
|
320 ;; Vector3f/UNIT_Y))
|
rlm@78
|
321 ;;(doto (Matrix3f.)
|
rlm@78
|
322 ;; (.fromStartEndVectors Vector3f/UNIT_X
|
rlm@78
|
323 ;; Vector3f/UNIT_Y))
|
rlm@78
|
324 true)
|
rlm@78
|
325 (.setCollisionBetweenLinkedBodys false)
|
rlm@78
|
326 (.setAngularLowerLimit (Vector3f. 0
|
rlm@78
|
327 (- (/ Math/PI 2))
|
rlm@78
|
328 0))
|
rlm@78
|
329
|
rlm@78
|
330 (.setAngularUpperLimit (Vector3f. 0
|
rlm@78
|
331 (/ Math/PI 2)
|
rlm@78
|
332 0))
|
rlm@78
|
333 (.setLinearLowerLimit (Vector3f. 0 0 0))
|
rlm@78
|
334 (.setLinearUpperLimit (Vector3f. 0 0 0))
|
rlm@78
|
335
|
rlm@78
|
336 )
|
rlm@78
|
337
|
rlm@78
|
338
|
rlm@78
|
339
|
rlm@78
|
340
|
rlm@78
|
341
|
rlm@78
|
342 )
|
rlm@78
|
343
|
rlm@78
|
344 [top bottom table]))
|
rlm@78
|
345
|
rlm@78
|
346
|
rlm@78
|
347 (defn test-joint [joint]
|
rlm@78
|
348 (let [[top bottom floor] (world-setup joint)
|
rlm@78
|
349 control (.getControl top RigidBodyControl)
|
rlm@78
|
350 move-up? (atom false)
|
rlm@78
|
351 move-down? (atom false)
|
rlm@78
|
352 move-left? (atom false)
|
rlm@78
|
353 move-right? (atom false)
|
rlm@78
|
354 roll-left? (atom false)
|
rlm@78
|
355 roll-right? (atom false)
|
rlm@78
|
356 timer (atom 0)]
|
rlm@78
|
357
|
rlm@78
|
358 (world
|
rlm@78
|
359 (nodify [top bottom floor])
|
rlm@78
|
360 (merge standard-debug-controls
|
rlm@78
|
361 {"key-r" (fn [_ pressed?] (reset! move-up? pressed?))
|
rlm@78
|
362 "key-t" (fn [_ pressed?] (reset! move-down? pressed?))
|
rlm@78
|
363 "key-f" (fn [_ pressed?] (reset! move-left? pressed?))
|
rlm@78
|
364 "key-g" (fn [_ pressed?] (reset! move-right? pressed?))
|
rlm@78
|
365 "key-v" (fn [_ pressed?] (reset! roll-left? pressed?))
|
rlm@78
|
366 "key-b" (fn [_ pressed?] (reset! roll-right? pressed?))})
|
rlm@78
|
367
|
rlm@78
|
368 (fn [world]
|
rlm@78
|
369 (light-up-everything world)
|
rlm@78
|
370 (enable-debug world)
|
rlm@78
|
371 (set-gravity world (Vector3f. 0 0 0))
|
rlm@78
|
372 )
|
rlm@78
|
373
|
rlm@78
|
374 (fn [world _]
|
rlm@78
|
375 (if (zero? (rem (swap! timer inc) 100))
|
rlm@78
|
376 (do
|
rlm@78
|
377 ;; (println-repl @timer)
|
rlm@78
|
378 (.attachChild (.getRootNode world)
|
rlm@78
|
379 (sphere 0.05 :color ColorRGBA/Yellow
|
rlm@78
|
380 :position (.getWorldTranslation top)
|
rlm@78
|
381 :physical? false))))
|
rlm@78
|
382 (if @move-up?
|
rlm@78
|
383 (.applyTorque control
|
rlm@78
|
384 (.mult (.getPhysicsRotation control)
|
rlm@78
|
385 (Vector3f. 0 0 10))))
|
rlm@78
|
386 (if @move-down?
|
rlm@78
|
387 (.applyTorque control
|
rlm@78
|
388 (.mult (.getPhysicsRotation control)
|
rlm@78
|
389 (Vector3f. 0 0 -10))))
|
rlm@78
|
390 (if @move-left?
|
rlm@78
|
391 (.applyTorque control
|
rlm@78
|
392 (.mult (.getPhysicsRotation control)
|
rlm@78
|
393 (Vector3f. 0 10 0))))
|
rlm@78
|
394 (if @move-right?
|
rlm@78
|
395 (.applyTorque control
|
rlm@78
|
396 (.mult (.getPhysicsRotation control)
|
rlm@78
|
397 (Vector3f. 0 -10 0))))
|
rlm@78
|
398 (if @roll-left?
|
rlm@78
|
399 (.applyTorque control
|
rlm@78
|
400 (.mult (.getPhysicsRotation control)
|
rlm@78
|
401 (Vector3f. -1 0 0))))
|
rlm@78
|
402 (if @roll-right?
|
rlm@78
|
403 (.applyTorque control
|
rlm@78
|
404 (.mult (.getPhysicsRotation control)
|
rlm@78
|
405 (Vector3f. 1 0 0))))))))
|
rlm@78
|
406 #+end_src
|
rlm@78
|
407
|
rlm@78
|
408
|
rlm@78
|
409 * COMMENT purgatory
|
rlm@78
|
410 #+begin_src clojure
|
rlm@77
|
411 (defn bullet-trans []
|
rlm@77
|
412 (let [obj-a (sphere 0.5 :color ColorRGBA/Red
|
rlm@77
|
413 :position (Vector3f. -10 5 0))
|
rlm@77
|
414 obj-b (sphere 0.5 :color ColorRGBA/Blue
|
rlm@77
|
415 :position (Vector3f. -10 -5 0)
|
rlm@77
|
416 :mass 0)
|
rlm@77
|
417 control-a (.getControl obj-a RigidBodyControl)
|
rlm@77
|
418 control-b (.getControl obj-b RigidBodyControl)
|
rlm@77
|
419 swivel
|
rlm@77
|
420 (.toRotationMatrix
|
rlm@77
|
421 (doto (Quaternion.)
|
rlm@77
|
422 (.fromAngleAxis (/ Math/PI 2)
|
rlm@77
|
423 Vector3f/UNIT_X)))]
|
rlm@77
|
424 (doto
|
rlm@77
|
425 (ConeJoint.
|
rlm@77
|
426 control-a control-b
|
rlm@77
|
427 (Vector3f. 0 5 0)
|
rlm@77
|
428 (Vector3f. 0 -5 0)
|
rlm@77
|
429 swivel swivel)
|
rlm@77
|
430 (.setLimit (* 0.6 (/ Math/PI 4))
|
rlm@77
|
431 (/ Math/PI 4)
|
rlm@77
|
432 (* Math/PI 0.8)))
|
rlm@77
|
433 (world (nodify
|
rlm@77
|
434 [obj-a obj-b])
|
rlm@77
|
435 standard-debug-controls
|
rlm@77
|
436 enable-debug
|
rlm@77
|
437 no-op)))
|
rlm@74
|
438
|
rlm@74
|
439
|
rlm@77
|
440 (defn bullet-trans* []
|
rlm@77
|
441 (let [obj-a (box 1.5 0.5 0.5 :color ColorRGBA/Red
|
rlm@77
|
442 :position (Vector3f. 5 0 0)
|
rlm@77
|
443 :mass 90)
|
rlm@77
|
444 obj-b (sphere 0.5 :color ColorRGBA/Blue
|
rlm@77
|
445 :position (Vector3f. -5 0 0)
|
rlm@77
|
446 :mass 0)
|
rlm@77
|
447 control-a (.getControl obj-a RigidBodyControl)
|
rlm@77
|
448 control-b (.getControl obj-b RigidBodyControl)
|
rlm@77
|
449 move-up? (atom nil)
|
rlm@77
|
450 move-down? (atom nil)
|
rlm@77
|
451 move-left? (atom nil)
|
rlm@77
|
452 move-right? (atom nil)
|
rlm@77
|
453 roll-left? (atom nil)
|
rlm@77
|
454 roll-right? (atom nil)
|
rlm@77
|
455 force 100
|
rlm@77
|
456 swivel
|
rlm@77
|
457 (.toRotationMatrix
|
rlm@77
|
458 (doto (Quaternion.)
|
rlm@77
|
459 (.fromAngleAxis (/ Math/PI 2)
|
rlm@77
|
460 Vector3f/UNIT_X)))
|
rlm@77
|
461 x-move
|
rlm@77
|
462 (doto (Matrix3f.)
|
rlm@77
|
463 (.fromStartEndVectors Vector3f/UNIT_X
|
rlm@77
|
464 (.normalize (Vector3f. 1 1 0))))
|
rlm@77
|
465
|
rlm@77
|
466 timer (atom 0)]
|
rlm@77
|
467 (doto
|
rlm@77
|
468 (ConeJoint.
|
rlm@77
|
469 control-a control-b
|
rlm@77
|
470 (Vector3f. -8 0 0)
|
rlm@77
|
471 (Vector3f. 2 0 0)
|
rlm@77
|
472 ;;swivel swivel
|
rlm@77
|
473 ;;Matrix3f/IDENTITY Matrix3f/IDENTITY
|
rlm@77
|
474 x-move Matrix3f/IDENTITY
|
rlm@77
|
475 )
|
rlm@77
|
476 (.setCollisionBetweenLinkedBodys false)
|
rlm@77
|
477 (.setLimit (* 1 (/ Math/PI 4)) ;; twist
|
rlm@77
|
478 (* 1 (/ Math/PI 4)) ;; swing span in X-Y plane
|
rlm@77
|
479 (* 0 (/ Math/PI 4)))) ;; swing span in Y-Z plane
|
rlm@77
|
480 (world (nodify
|
rlm@77
|
481 [obj-a obj-b])
|
rlm@77
|
482 (merge standard-debug-controls
|
rlm@77
|
483 {"key-r" (fn [_ pressed?] (reset! move-up? pressed?))
|
rlm@77
|
484 "key-t" (fn [_ pressed?] (reset! move-down? pressed?))
|
rlm@77
|
485 "key-f" (fn [_ pressed?] (reset! move-left? pressed?))
|
rlm@77
|
486 "key-g" (fn [_ pressed?] (reset! move-right? pressed?))
|
rlm@77
|
487 "key-v" (fn [_ pressed?] (reset! roll-left? pressed?))
|
rlm@77
|
488 "key-b" (fn [_ pressed?] (reset! roll-right? pressed?))})
|
rlm@77
|
489
|
rlm@77
|
490 (fn [world]
|
rlm@77
|
491 (enable-debug world)
|
rlm@77
|
492 (set-gravity world Vector3f/ZERO)
|
rlm@77
|
493 )
|
rlm@77
|
494
|
rlm@77
|
495 (fn [world _]
|
rlm@77
|
496
|
rlm@77
|
497 (if @move-up?
|
rlm@77
|
498 (.applyForce control-a
|
rlm@77
|
499 (Vector3f. force 0 0)
|
rlm@77
|
500 (Vector3f. 0 0 0)))
|
rlm@77
|
501 (if @move-down?
|
rlm@77
|
502 (.applyForce control-a
|
rlm@77
|
503 (Vector3f. (- force) 0 0)
|
rlm@77
|
504 (Vector3f. 0 0 0)))
|
rlm@77
|
505 (if @move-left?
|
rlm@77
|
506 (.applyForce control-a
|
rlm@77
|
507 (Vector3f. 0 force 0)
|
rlm@77
|
508 (Vector3f. 0 0 0)))
|
rlm@77
|
509 (if @move-right?
|
rlm@77
|
510 (.applyForce control-a
|
rlm@77
|
511 (Vector3f. 0 (- force) 0)
|
rlm@77
|
512 (Vector3f. 0 0 0)))
|
rlm@77
|
513
|
rlm@77
|
514 (if @roll-left?
|
rlm@77
|
515 (.applyForce control-a
|
rlm@77
|
516 (Vector3f. 0 0 force)
|
rlm@77
|
517 (Vector3f. 0 0 0)))
|
rlm@77
|
518 (if @roll-right?
|
rlm@77
|
519 (.applyForce control-a
|
rlm@77
|
520 (Vector3f. 0 0 (- force))
|
rlm@77
|
521 (Vector3f. 0 0 0)))
|
rlm@77
|
522
|
rlm@77
|
523 (if (zero? (rem (swap! timer inc) 100))
|
rlm@77
|
524 (.attachChild
|
rlm@77
|
525 (.getRootNode world)
|
rlm@77
|
526 (sphere 0.05 :color ColorRGBA/Yellow
|
rlm@77
|
527 :physical? false :position
|
rlm@77
|
528 (.getWorldTranslation obj-a)))))
|
rlm@77
|
529 )
|
rlm@77
|
530 ))
|
rlm@77
|
531
|
rlm@77
|
532
|
rlm@77
|
533
|
rlm@73
|
534 #+end_src
|
rlm@73
|
535
|
rlm@73
|
536
|
rlm@73
|
537 * COMMENT generate source
|
rlm@73
|
538 #+begin_src clojure :tangle ../src/cortex/silly.clj
|
rlm@73
|
539 <<body-1>>
|
rlm@73
|
540 #+end_src
|
rlm@73
|
541
|