rlm@281
|
1 #+title:
|
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@281
|
9 * Intro
|
rlm@129
|
10
|
rlm@281
|
11 This is the ultimate test which features all of the senses that I've
|
rlm@281
|
12 made so far. The blender file for the creature serves as an example of
|
rlm@281
|
13 a fully equipped creature in terms of senses. You can find it [[../assets/Models/test-creature/hand.blend][here]].
|
rlm@73
|
14
|
rlm@192
|
15 #+name: integration
|
rlm@73
|
16 #+begin_src clojure
|
rlm@192
|
17 (ns cortex.integration
|
rlm@73
|
18 "let's play!"
|
rlm@192
|
19 {:author "Robert McIntyre"}
|
rlm@281
|
20 (:use (cortex world util body sense
|
rlm@281
|
21 hearing touch vision proprioception movement))
|
rlm@192
|
22 (:import (com.jme3.math ColorRGBA Vector3f))
|
rlm@281
|
23 (:import java.io.File)
|
rlm@192
|
24 (:import com.jme3.audio.AudioNode)
|
rlm@192
|
25 (:import com.aurellem.capture.RatchetTimer))
|
rlm@73
|
26
|
rlm@281
|
27 (dorun (cortex.import/mega-import-jme3))
|
rlm@281
|
28 (rlm.rlm-commands/help)
|
rlm@74
|
29
|
rlm@281
|
30 (def hand "Models/test-creature/hand.blend")
|
rlm@78
|
31
|
rlm@281
|
32 (def output-base (File. "/home/r/proj/cortex/render/hand"))
|
rlm@189
|
33
|
rlm@295
|
34 (def control-list
|
rlm@295
|
35 [
|
rlm@295
|
36 0 ;;pointer-21 #<Vector3f (0.99999994, 0.0, 0.0)>
|
rlm@295
|
37 1 ;;pointer-21 #<Vector3f (-0.99999994, 0.0, 0.0)>
|
rlm@295
|
38 0 ;;thumb-11 #<Vector3f (-0.8802276, -0.39781287, -0.25873658)>
|
rlm@295
|
39 0 ;;thumb-11 #<Vector3f (0.8485723, 0.46149826, 0.2587364)>
|
rlm@295
|
40 0 ;;pointer-11 #<Vector3f (0.99999994, 0.0, 0.0)>
|
rlm@295
|
41 0 ;;pointer-11 #<Vector3f (-0.99999994, 0.0, 0.0)>
|
rlm@295
|
42 0 ;;thumb-2.0011 #<Vector3f (-0.71705645, -0.44753736, -0.5343599)>
|
rlm@295
|
43 0 ;;thumb-2.0011 #<Vector3f (-0.10567085, 0.83862597, 0.53435963)>
|
rlm@295
|
44 0 ;;middle-11 #<Vector3f (0.99999994, 0.0, 0.0)>
|
rlm@295
|
45 0 ;;middle-11 #<Vector3f (-0.99999994, 0.0, 0.0)>
|
rlm@295
|
46 0 ;;pointer-31 #<Vector3f (-0.99999994, 0.0, 0.0)>
|
rlm@295
|
47 0 ;;pointer-31 #<Vector3f (0.99999994, 0.0, 0.0)>
|
rlm@295
|
48 0 ;;middle-21 #<Vector3f (0.99999994, 0.0, 0.0)>
|
rlm@295
|
49 0 ;;middle-21 #<Vector3f (-0.99999994, 0.0, 0.0)>
|
rlm@295
|
50 0 ;;middle-31 #<Vector3f (-0.99999994, 0.0, 0.0)>
|
rlm@295
|
51 0 ;;middle-31 #<Vector3f (0.99999994, 0.0, 0.0)>
|
rlm@295
|
52 0 ;;pinky-21 #<Vector3f (0.99999994, 0.0, 0.0)>
|
rlm@295
|
53 0 ;;pinky-21 #<Vector3f (-0.99999994, 0.0, 0.0)>
|
rlm@295
|
54 0 ;;pinky-31 #<Vector3f (0.99999994, 0.0, 0.0)>
|
rlm@295
|
55 0 ;;ring-31 #<Vector3f (0.99999994, 0.0, 0.0)>
|
rlm@295
|
56 0 ;;ring-31 #<Vector3f (-0.99999994, 0.0, 0.0)>
|
rlm@295
|
57 0 ;;ring-21 #<Vector3f (-0.99999994, 0.0, 0.0)>
|
rlm@295
|
58 0 ;;ring-21 #<Vector3f (0.99999994, 0.0, 0.0)>
|
rlm@295
|
59 0 ;;ring-11 #<Vector3f (0.99999994, 0.0, 0.0)>
|
rlm@295
|
60 0 ;;ring-11 #<Vector3f (-0.99999994, 0.0, 0.0)>
|
rlm@295
|
61 0 ;;thumb-11 #<Vector3f (-0.43154645, 0.7302033, 0.5296894)>
|
rlm@295
|
62 0 ;;thumb-11 #<Vector3f (-0.8032993, -0.2722854, -0.5296895)>
|
rlm@295
|
63 0 ;;pinky-11 #<Vector3f (-0.99999994, 0.0, 0.0)>
|
rlm@295
|
64 0 ;;pinky-11 #<Vector3f (0.99999994, 0.0, 0.0)>
|
rlm@295
|
65 ])
|
rlm@295
|
66
|
rlm@281
|
67 (defn test-everything!
|
rlm@281
|
68 ([] (test-everything! false))
|
rlm@281
|
69 ([record?]
|
rlm@281
|
70 (let [me (sphere 0.5 :color ColorRGBA/Blue :physical? false)
|
rlm@281
|
71
|
rlm@192
|
72 bell (AudioNode. (asset-manager)
|
rlm@192
|
73 "Sounds/pure.wav" false)
|
rlm@281
|
74 creature (doto (load-blender-model hand)
|
rlm@281
|
75 (body!))
|
rlm@281
|
76
|
rlm@192
|
77 ;;;;;;;;;;;; Sensors/Effectors ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
rlm@294
|
78 ;;touch (touch! creature)
|
rlm@294
|
79 ;;touch-display (view-touch)
|
rlm@189
|
80
|
rlm@294
|
81 ;;vision (vision! creature)
|
rlm@294
|
82 ;;vision-display (view-vision)
|
rlm@189
|
83
|
rlm@294
|
84 ;;hearing (hearing! creature)
|
rlm@294
|
85 ;;hearing-display (view-hearing)
|
rlm@189
|
86
|
rlm@173
|
87 prop (proprioception! creature)
|
rlm@190
|
88 prop-display (view-proprioception)
|
rlm@148
|
89
|
rlm@191
|
90 muscle-exertion (atom 0)
|
rlm@191
|
91 muscles (movement! creature)
|
rlm@281
|
92 muscle-display (view-movement)
|
rlm@281
|
93 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
rlm@189
|
94
|
rlm@281
|
95 fix-display (gen-fix-display)]
|
rlm@285
|
96 (world
|
rlm@285
|
97 (nodify [creature
|
rlm@285
|
98 (box 10 2 10 :position (Vector3f. 0 -9 0)
|
rlm@285
|
99 :color ColorRGBA/Gray :mass 0)
|
rlm@285
|
100 me])
|
rlm@285
|
101 (merge standard-debug-controls
|
rlm@285
|
102 {"key-return"
|
rlm@285
|
103 (fn [_ value]
|
rlm@285
|
104 (if value
|
rlm@285
|
105 (.play bell)))
|
rlm@285
|
106 "key-h"
|
rlm@285
|
107 (fn [_ value]
|
rlm@285
|
108 (if value
|
rlm@285
|
109 (swap! muscle-exertion (partial + 20))))
|
rlm@285
|
110 "key-n"
|
rlm@285
|
111 (fn [_ value]
|
rlm@285
|
112 (if value
|
rlm@285
|
113 (swap! muscle-exertion (fn [v] (- v 20)))))})
|
rlm@285
|
114 (fn [world]
|
rlm@285
|
115 (.setTimer world (RatchetTimer. 60))
|
rlm@285
|
116 (light-up-everything world)
|
rlm@285
|
117 (enable-debug world)
|
rlm@285
|
118 (add-camera! world
|
rlm@285
|
119 (add-eye! creature
|
rlm@285
|
120 (.getChild
|
rlm@285
|
121 (.getChild creature "eyes") "eye"))
|
rlm@285
|
122 (comp (view-image) BufferedImage!))
|
rlm@285
|
123 (speed-up world))
|
rlm@285
|
124 (fn [world tpf]
|
rlm@294
|
125 ;;(prop-display (prop))
|
rlm@294
|
126 ;;(touch-display (map #(% (.getRootNode world)) touch))
|
rlm@294
|
127 ;;(vision-display (map #(% world) vision))
|
rlm@294
|
128 ;;(hearing-display (map #(% world) hearing))
|
rlm@295
|
129
|
rlm@295
|
130 (muscle-display
|
rlm@295
|
131 (map (fn [effector control]
|
rlm@295
|
132 (effector (int (* @muscle-exertion control))))
|
rlm@295
|
133 muscles
|
rlm@295
|
134 control-list))
|
rlm@295
|
135
|
rlm@285
|
136 (.setLocalTranslation me (.getLocation (.getCamera world)))
|
rlm@285
|
137 (fix-display world))))))
|
rlm@87
|
138 #+end_src
|
rlm@83
|
139
|
rlm@282
|
140 #+results: integration
|
rlm@282
|
141 : #'cortex.integration/test-everything!
|
rlm@282
|
142
|
rlm@78
|
143 * COMMENT purgatory
|
rlm@78
|
144 #+begin_src clojure
|
rlm@77
|
145 (defn bullet-trans* []
|
rlm@77
|
146 (let [obj-a (box 1.5 0.5 0.5 :color ColorRGBA/Red
|
rlm@77
|
147 :position (Vector3f. 5 0 0)
|
rlm@77
|
148 :mass 90)
|
rlm@77
|
149 obj-b (sphere 0.5 :color ColorRGBA/Blue
|
rlm@77
|
150 :position (Vector3f. -5 0 0)
|
rlm@77
|
151 :mass 0)
|
rlm@77
|
152 control-a (.getControl obj-a RigidBodyControl)
|
rlm@77
|
153 control-b (.getControl obj-b RigidBodyControl)
|
rlm@77
|
154 move-up? (atom nil)
|
rlm@77
|
155 move-down? (atom nil)
|
rlm@77
|
156 move-left? (atom nil)
|
rlm@77
|
157 move-right? (atom nil)
|
rlm@77
|
158 roll-left? (atom nil)
|
rlm@77
|
159 roll-right? (atom nil)
|
rlm@77
|
160 force 100
|
rlm@77
|
161 swivel
|
rlm@77
|
162 (.toRotationMatrix
|
rlm@77
|
163 (doto (Quaternion.)
|
rlm@77
|
164 (.fromAngleAxis (/ Math/PI 2)
|
rlm@77
|
165 Vector3f/UNIT_X)))
|
rlm@77
|
166 x-move
|
rlm@77
|
167 (doto (Matrix3f.)
|
rlm@77
|
168 (.fromStartEndVectors Vector3f/UNIT_X
|
rlm@77
|
169 (.normalize (Vector3f. 1 1 0))))
|
rlm@77
|
170
|
rlm@77
|
171 timer (atom 0)]
|
rlm@77
|
172 (doto
|
rlm@77
|
173 (ConeJoint.
|
rlm@77
|
174 control-a control-b
|
rlm@77
|
175 (Vector3f. -8 0 0)
|
rlm@77
|
176 (Vector3f. 2 0 0)
|
rlm@77
|
177 ;;swivel swivel
|
rlm@77
|
178 ;;Matrix3f/IDENTITY Matrix3f/IDENTITY
|
rlm@77
|
179 x-move Matrix3f/IDENTITY
|
rlm@77
|
180 )
|
rlm@77
|
181 (.setCollisionBetweenLinkedBodys false)
|
rlm@77
|
182 (.setLimit (* 1 (/ Math/PI 4)) ;; twist
|
rlm@77
|
183 (* 1 (/ Math/PI 4)) ;; swing span in X-Y plane
|
rlm@77
|
184 (* 0 (/ Math/PI 4)))) ;; swing span in Y-Z plane
|
rlm@77
|
185 (world (nodify
|
rlm@77
|
186 [obj-a obj-b])
|
rlm@77
|
187 (merge standard-debug-controls
|
rlm@77
|
188 {"key-r" (fn [_ pressed?] (reset! move-up? pressed?))
|
rlm@77
|
189 "key-t" (fn [_ pressed?] (reset! move-down? pressed?))
|
rlm@77
|
190 "key-f" (fn [_ pressed?] (reset! move-left? pressed?))
|
rlm@77
|
191 "key-g" (fn [_ pressed?] (reset! move-right? pressed?))
|
rlm@77
|
192 "key-v" (fn [_ pressed?] (reset! roll-left? pressed?))
|
rlm@77
|
193 "key-b" (fn [_ pressed?] (reset! roll-right? pressed?))})
|
rlm@77
|
194
|
rlm@77
|
195 (fn [world]
|
rlm@77
|
196 (enable-debug world)
|
rlm@77
|
197 (set-gravity world Vector3f/ZERO)
|
rlm@77
|
198 )
|
rlm@77
|
199
|
rlm@77
|
200 (fn [world _]
|
rlm@77
|
201
|
rlm@77
|
202 (if @move-up?
|
rlm@77
|
203 (.applyForce control-a
|
rlm@77
|
204 (Vector3f. force 0 0)
|
rlm@77
|
205 (Vector3f. 0 0 0)))
|
rlm@77
|
206 (if @move-down?
|
rlm@77
|
207 (.applyForce control-a
|
rlm@77
|
208 (Vector3f. (- force) 0 0)
|
rlm@77
|
209 (Vector3f. 0 0 0)))
|
rlm@77
|
210 (if @move-left?
|
rlm@77
|
211 (.applyForce control-a
|
rlm@77
|
212 (Vector3f. 0 force 0)
|
rlm@77
|
213 (Vector3f. 0 0 0)))
|
rlm@77
|
214 (if @move-right?
|
rlm@77
|
215 (.applyForce control-a
|
rlm@77
|
216 (Vector3f. 0 (- force) 0)
|
rlm@77
|
217 (Vector3f. 0 0 0)))
|
rlm@77
|
218
|
rlm@77
|
219 (if @roll-left?
|
rlm@77
|
220 (.applyForce control-a
|
rlm@77
|
221 (Vector3f. 0 0 force)
|
rlm@77
|
222 (Vector3f. 0 0 0)))
|
rlm@77
|
223 (if @roll-right?
|
rlm@77
|
224 (.applyForce control-a
|
rlm@77
|
225 (Vector3f. 0 0 (- force))
|
rlm@77
|
226 (Vector3f. 0 0 0)))
|
rlm@77
|
227
|
rlm@77
|
228 (if (zero? (rem (swap! timer inc) 100))
|
rlm@77
|
229 (.attachChild
|
rlm@77
|
230 (.getRootNode world)
|
rlm@77
|
231 (sphere 0.05 :color ColorRGBA/Yellow
|
rlm@77
|
232 :physical? false :position
|
rlm@77
|
233 (.getWorldTranslation obj-a)))))
|
rlm@77
|
234 )
|
rlm@77
|
235 ))
|
rlm@77
|
236
|
rlm@106
|
237 (defn test-joint [joint]
|
rlm@106
|
238 (let [[origin top bottom floor] (world-setup joint)
|
rlm@106
|
239 control (.getControl top RigidBodyControl)
|
rlm@106
|
240 move-up? (atom false)
|
rlm@106
|
241 move-down? (atom false)
|
rlm@106
|
242 move-left? (atom false)
|
rlm@106
|
243 move-right? (atom false)
|
rlm@106
|
244 roll-left? (atom false)
|
rlm@106
|
245 roll-right? (atom false)
|
rlm@106
|
246 timer (atom 0)]
|
rlm@106
|
247
|
rlm@106
|
248 (world
|
rlm@106
|
249 (nodify [top bottom floor origin])
|
rlm@106
|
250 (merge standard-debug-controls
|
rlm@106
|
251 {"key-r" (fn [_ pressed?] (reset! move-up? pressed?))
|
rlm@106
|
252 "key-t" (fn [_ pressed?] (reset! move-down? pressed?))
|
rlm@106
|
253 "key-f" (fn [_ pressed?] (reset! move-left? pressed?))
|
rlm@106
|
254 "key-g" (fn [_ pressed?] (reset! move-right? pressed?))
|
rlm@106
|
255 "key-v" (fn [_ pressed?] (reset! roll-left? pressed?))
|
rlm@106
|
256 "key-b" (fn [_ pressed?] (reset! roll-right? pressed?))})
|
rlm@106
|
257
|
rlm@106
|
258 (fn [world]
|
rlm@106
|
259 (light-up-everything world)
|
rlm@106
|
260 (enable-debug world)
|
rlm@106
|
261 (set-gravity world (Vector3f. 0 0 0))
|
rlm@106
|
262 )
|
rlm@106
|
263
|
rlm@106
|
264 (fn [world _]
|
rlm@106
|
265 (if (zero? (rem (swap! timer inc) 100))
|
rlm@106
|
266 (do
|
rlm@106
|
267 ;; (println-repl @timer)
|
rlm@106
|
268 (.attachChild (.getRootNode world)
|
rlm@106
|
269 (sphere 0.05 :color ColorRGBA/Yellow
|
rlm@106
|
270 :position (.getWorldTranslation top)
|
rlm@106
|
271 :physical? false))
|
rlm@106
|
272 (.attachChild (.getRootNode world)
|
rlm@106
|
273 (sphere 0.05 :color ColorRGBA/LightGray
|
rlm@106
|
274 :position (.getWorldTranslation bottom)
|
rlm@106
|
275 :physical? false))))
|
rlm@106
|
276
|
rlm@106
|
277 (if @move-up?
|
rlm@106
|
278 (.applyTorque control
|
rlm@106
|
279 (.mult (.getPhysicsRotation control)
|
rlm@106
|
280 (Vector3f. 0 0 10))))
|
rlm@106
|
281 (if @move-down?
|
rlm@106
|
282 (.applyTorque control
|
rlm@106
|
283 (.mult (.getPhysicsRotation control)
|
rlm@106
|
284 (Vector3f. 0 0 -10))))
|
rlm@106
|
285 (if @move-left?
|
rlm@106
|
286 (.applyTorque control
|
rlm@106
|
287 (.mult (.getPhysicsRotation control)
|
rlm@106
|
288 (Vector3f. 0 10 0))))
|
rlm@106
|
289 (if @move-right?
|
rlm@106
|
290 (.applyTorque control
|
rlm@106
|
291 (.mult (.getPhysicsRotation control)
|
rlm@106
|
292 (Vector3f. 0 -10 0))))
|
rlm@106
|
293 (if @roll-left?
|
rlm@106
|
294 (.applyTorque control
|
rlm@106
|
295 (.mult (.getPhysicsRotation control)
|
rlm@106
|
296 (Vector3f. -1 0 0))))
|
rlm@106
|
297 (if @roll-right?
|
rlm@106
|
298 (.applyTorque control
|
rlm@106
|
299 (.mult (.getPhysicsRotation control)
|
rlm@106
|
300 (Vector3f. 1 0 0))))))))
|
rlm@99
|
301 #+end_src
|
rlm@192
|
302
|
rlm@99
|
303
|
rlm@99
|
304 * COMMENT generate source
|
rlm@192
|
305 #+begin_src clojure :tangle ../src/cortex/integration.clj
|
rlm@192
|
306 <<integration>>
|
rlm@99
|
307 #+end_src
|
rlm@99
|
308
|
rlm@99
|
309
|
rlm@94
|
310
|
rlm@94
|
311
|