view org/integration.org @ 281:7351c9c0c471

resurrected integration test.
author Robert McIntyre <rlm@mit.edu>
date Wed, 15 Feb 2012 11:13:12 -0700
parents 305439cec54d
children 2ad29b68ff22
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 (defn test-everything!
35 ([] (test-everything! false))
36 ([record?]
37 (let [me (sphere 0.5 :color ColorRGBA/Blue :physical? false)
39 bell (AudioNode. (asset-manager)
40 "Sounds/pure.wav" false)
44 creature (doto (load-blender-model hand)
45 (body!))
47 ;;;;;;;;;;;; Sensors/Effectors ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
48 touch (touch! creature)
49 touch-display (view-touch)
51 vision (vision! creature)
52 vision-display (view-vision)
54 hearing (hearing! creature)
55 hearing-display (view-hearing)
57 prop (proprioception! creature)
58 prop-display (view-proprioception)
60 muscle-exertion (atom 0)
61 muscles (movement! creature)
62 muscle-display (view-movement)
63 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
65 fix-display (gen-fix-display)]
66 (apply
67 world
68 (with-movement
69 (.getChild creature "palm")
70 ["key-r" "key-t"
71 "key-f" "key-g"
72 "key-v" "key-b"]
73 [10 10 10 10 1 1]
74 [(nodify [creature
75 (box 10 2 10 :position (Vector3f. 0 -9 0)
76 :color ColorRGBA/Gray :mass 0)
77 me])
78 (merge standard-debug-controls
79 {"key-return"
80 (fn [_ value]
81 (if value
82 (do
83 (println-repl "play-sound")
84 (.play bell))))
85 "key-h"
86 (fn [_ value]
87 (if value
88 (swap! muscle-exertion (partial + 20))))
89 "key-n"
90 (fn [_ value]
91 (if value
92 (swap! muscle-exertion (fn [v] (- v 20)))))})
93 (fn [world]
94 (.setTimer world (RatchetTimer. 60))
95 (light-up-everything world)
96 (enable-debug world)
97 (add-camera! world
98 (add-eye! creature
99 (.getChild
100 (.getChild creature "eyes") "eye"))
101 (comp (view-image) BufferedImage!))
102 (speed-up world))
103 (fn [world tpf]
104 (prop-display (prop))
105 (touch-display (map #(% (.getRootNode world)) touch))
106 (vision-display (map #(% world) vision))
107 (hearing-display (map #(% world) hearing))
108 (muscle-display (map #(% @muscle-exertion) muscles))
109 (.setLocalTranslation me (.getLocation (.getCamera world)))
110 (fix-display world))])))))
111 #+end_src
113 * COMMENT purgatory
114 #+begin_src clojure
115 (defn bullet-trans* []
116 (let [obj-a (box 1.5 0.5 0.5 :color ColorRGBA/Red
117 :position (Vector3f. 5 0 0)
118 :mass 90)
119 obj-b (sphere 0.5 :color ColorRGBA/Blue
120 :position (Vector3f. -5 0 0)
121 :mass 0)
122 control-a (.getControl obj-a RigidBodyControl)
123 control-b (.getControl obj-b RigidBodyControl)
124 move-up? (atom nil)
125 move-down? (atom nil)
126 move-left? (atom nil)
127 move-right? (atom nil)
128 roll-left? (atom nil)
129 roll-right? (atom nil)
130 force 100
131 swivel
132 (.toRotationMatrix
133 (doto (Quaternion.)
134 (.fromAngleAxis (/ Math/PI 2)
135 Vector3f/UNIT_X)))
136 x-move
137 (doto (Matrix3f.)
138 (.fromStartEndVectors Vector3f/UNIT_X
139 (.normalize (Vector3f. 1 1 0))))
141 timer (atom 0)]
142 (doto
143 (ConeJoint.
144 control-a control-b
145 (Vector3f. -8 0 0)
146 (Vector3f. 2 0 0)
147 ;;swivel swivel
148 ;;Matrix3f/IDENTITY Matrix3f/IDENTITY
149 x-move Matrix3f/IDENTITY
150 )
151 (.setCollisionBetweenLinkedBodys false)
152 (.setLimit (* 1 (/ Math/PI 4)) ;; twist
153 (* 1 (/ Math/PI 4)) ;; swing span in X-Y plane
154 (* 0 (/ Math/PI 4)))) ;; swing span in Y-Z plane
155 (world (nodify
156 [obj-a obj-b])
157 (merge standard-debug-controls
158 {"key-r" (fn [_ pressed?] (reset! move-up? pressed?))
159 "key-t" (fn [_ pressed?] (reset! move-down? pressed?))
160 "key-f" (fn [_ pressed?] (reset! move-left? pressed?))
161 "key-g" (fn [_ pressed?] (reset! move-right? pressed?))
162 "key-v" (fn [_ pressed?] (reset! roll-left? pressed?))
163 "key-b" (fn [_ pressed?] (reset! roll-right? pressed?))})
165 (fn [world]
166 (enable-debug world)
167 (set-gravity world Vector3f/ZERO)
168 )
170 (fn [world _]
172 (if @move-up?
173 (.applyForce control-a
174 (Vector3f. force 0 0)
175 (Vector3f. 0 0 0)))
176 (if @move-down?
177 (.applyForce control-a
178 (Vector3f. (- force) 0 0)
179 (Vector3f. 0 0 0)))
180 (if @move-left?
181 (.applyForce control-a
182 (Vector3f. 0 force 0)
183 (Vector3f. 0 0 0)))
184 (if @move-right?
185 (.applyForce control-a
186 (Vector3f. 0 (- force) 0)
187 (Vector3f. 0 0 0)))
189 (if @roll-left?
190 (.applyForce control-a
191 (Vector3f. 0 0 force)
192 (Vector3f. 0 0 0)))
193 (if @roll-right?
194 (.applyForce control-a
195 (Vector3f. 0 0 (- force))
196 (Vector3f. 0 0 0)))
198 (if (zero? (rem (swap! timer inc) 100))
199 (.attachChild
200 (.getRootNode world)
201 (sphere 0.05 :color ColorRGBA/Yellow
202 :physical? false :position
203 (.getWorldTranslation obj-a)))))
204 )
205 ))
207 (defn test-joint [joint]
208 (let [[origin top bottom floor] (world-setup joint)
209 control (.getControl top RigidBodyControl)
210 move-up? (atom false)
211 move-down? (atom false)
212 move-left? (atom false)
213 move-right? (atom false)
214 roll-left? (atom false)
215 roll-right? (atom false)
216 timer (atom 0)]
218 (world
219 (nodify [top bottom floor origin])
220 (merge standard-debug-controls
221 {"key-r" (fn [_ pressed?] (reset! move-up? pressed?))
222 "key-t" (fn [_ pressed?] (reset! move-down? pressed?))
223 "key-f" (fn [_ pressed?] (reset! move-left? pressed?))
224 "key-g" (fn [_ pressed?] (reset! move-right? pressed?))
225 "key-v" (fn [_ pressed?] (reset! roll-left? pressed?))
226 "key-b" (fn [_ pressed?] (reset! roll-right? pressed?))})
228 (fn [world]
229 (light-up-everything world)
230 (enable-debug world)
231 (set-gravity world (Vector3f. 0 0 0))
232 )
234 (fn [world _]
235 (if (zero? (rem (swap! timer inc) 100))
236 (do
237 ;; (println-repl @timer)
238 (.attachChild (.getRootNode world)
239 (sphere 0.05 :color ColorRGBA/Yellow
240 :position (.getWorldTranslation top)
241 :physical? false))
242 (.attachChild (.getRootNode world)
243 (sphere 0.05 :color ColorRGBA/LightGray
244 :position (.getWorldTranslation bottom)
245 :physical? false))))
247 (if @move-up?
248 (.applyTorque control
249 (.mult (.getPhysicsRotation control)
250 (Vector3f. 0 0 10))))
251 (if @move-down?
252 (.applyTorque control
253 (.mult (.getPhysicsRotation control)
254 (Vector3f. 0 0 -10))))
255 (if @move-left?
256 (.applyTorque control
257 (.mult (.getPhysicsRotation control)
258 (Vector3f. 0 10 0))))
259 (if @move-right?
260 (.applyTorque control
261 (.mult (.getPhysicsRotation control)
262 (Vector3f. 0 -10 0))))
263 (if @roll-left?
264 (.applyTorque control
265 (.mult (.getPhysicsRotation control)
266 (Vector3f. -1 0 0))))
267 (if @roll-right?
268 (.applyTorque control
269 (.mult (.getPhysicsRotation control)
270 (Vector3f. 1 0 0))))))))
271 #+end_src
274 * COMMENT generate source
275 #+begin_src clojure :tangle ../src/cortex/integration.clj
276 <<integration>>
277 #+end_src