view org/integration.org @ 295:67a4e92d4628

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