view org/integration.org @ 272:12e6231eae8e

Revised the RenderManager diagram.
author Dylan Holmes <ocsenave@gmail.com>
date Tue, 14 Feb 2012 23:12:56 -0600
parents 305439cec54d
children 7351c9c0c471
line wrap: on
line source
1 #+title: First attempt at a creature!
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
12 * Intro
13 So far, I've made the following senses --
14 - Vision
15 - Hearing
16 - Touch
17 - Proprioception
19 And one effector:
20 - Movement
22 However, the code so far has only enabled these senses, but has not
23 actually implemented them. For example, there is still a lot of work
24 to be done for vision. I need to be able to create an /eyeball/ in
25 simulation that can be moved around and see the world from different
26 angles. I also need to determine weather to use log-polar or cartesian
27 for the visual input, and I need to determine how/wether to
28 disceritise the visual input.
30 I also want to be able to visualize both the sensors and the
31 effectors in pretty pictures. This semi-retarted creature will be my
32 first attempt at bringing everything together.
34 * The creature's body
36 Still going to do an eve-like body in blender, but due to problems
37 importing the joints, etc into jMonkeyEngine3, I'm going to do all
38 the connecting here in clojure code, using the names of the individual
39 components and trial and error. Later, I'll maybe make some sort of
40 creature-building modifications to blender that support whatever
41 discritized senses I'm going to make.
43 #+name: integration
44 #+begin_src clojure
45 (ns cortex.integration
46 "let's play!"
47 {:author "Robert McIntyre"}
48 (:use (cortex world util body
49 hearing touch vision sense proprioception movement))
50 (:import (com.jme3.math ColorRGBA Vector3f))
51 (:import com.jme3.audio.AudioNode)
52 (:import com.aurellem.capture.RatchetTimer))
54 (def hand "Models/creature1/one.blend")
56 (def worm "Models/creature1/try-again.blend")
58 (defn test-creature [thing]
59 (let [x-axis
60 (box 1 0.01 0.01 :physical? false :color ColorRGBA/Red)
61 y-axis
62 (box 0.01 1 0.01 :physical? false :color ColorRGBA/Green)
63 z-axis
64 (box 0.01 0.01 1 :physical? false :color ColorRGBA/Blue)
66 me (sphere 0.5 :color ColorRGBA/Blue :physical? false)
67 bell (AudioNode. (asset-manager)
68 "Sounds/pure.wav" false)
70 fix-display
71 (runonce (fn [world]
72 (add-camera! world (.getCamera world) no-op)))
73 creature (doto (load-blender-model thing) (body!))
75 ;;;;;;;;;;;; Sensors/Effectors ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
76 touch (touch! creature)
77 touch-display (view-touch)
79 vision (vision! creature)
80 vision-display (view-vision)
82 hearing (hearing! creature)
83 hearing-display (view-hearing)
85 prop (proprioception! creature)
86 prop-display (view-proprioception)
88 muscle-exertion (atom 0)
89 muscles (movement! creature)
90 muscle-display (view-movement)]
92 (apply
93 world
94 (with-movement
95 (.getChild creature "worm-21")
96 ["key-r" "key-t"
97 "key-f" "key-g"
98 "key-v" "key-b"]
99 [10 10 10 10 1 1]
100 [(nodify [creature
101 (box 10 2 10 :position (Vector3f. 0 -9 0)
102 :color ColorRGBA/Gray :mass 0)
103 x-axis y-axis z-axis
104 me])
105 (merge standard-debug-controls
106 {"key-return"
107 (fn [_ value]
108 (if value
109 (do
110 (println-repl "play-sound")
111 (.play bell))))
112 "key-h"
113 (fn [_ value]
114 (if value
115 (swap! muscle-exertion (partial + 20))))
116 "key-n"
117 (fn [_ value]
118 (if value
119 (swap! muscle-exertion (fn [v] (- v 20)))))})
120 (fn [world]
121 (light-up-everything world)
122 (enable-debug world)
123 (add-camera! world
124 (add-eye! creature
125 (.getChild
126 (.getChild creature "eyes") "eye"))
127 (comp (view-image) BufferedImage!))
128 (.setTimer world (RatchetTimer. 60))
129 (speed-up world)
130 (set-gravity world (Vector3f. 0 0 0))
131 (comment
132 (com.aurellem.capture.Capture/captureVideo
133 world (file-str "/home/r/proj/ai-videos/hand"))))
134 (fn [world tpf]
135 (prop-display (prop))
136 (touch-display (map #(% (.getRootNode world)) touch))
137 (vision-display (map #(% world) vision))
138 (hearing-display (map #(% world) hearing))
139 (muscle-display (map #(% @muscle-exertion) muscles))
140 (.setLocalTranslation me (.getLocation (.getCamera world)))
141 (fix-display world))]))))
142 #+end_src
144 #+results: body-1
145 : #'cortex.silly/follow-test
148 * COMMENT purgatory
149 #+begin_src clojure
151 (defn bullet-trans* []
152 (let [obj-a (box 1.5 0.5 0.5 :color ColorRGBA/Red
153 :position (Vector3f. 5 0 0)
154 :mass 90)
155 obj-b (sphere 0.5 :color ColorRGBA/Blue
156 :position (Vector3f. -5 0 0)
157 :mass 0)
158 control-a (.getControl obj-a RigidBodyControl)
159 control-b (.getControl obj-b RigidBodyControl)
160 move-up? (atom nil)
161 move-down? (atom nil)
162 move-left? (atom nil)
163 move-right? (atom nil)
164 roll-left? (atom nil)
165 roll-right? (atom nil)
166 force 100
167 swivel
168 (.toRotationMatrix
169 (doto (Quaternion.)
170 (.fromAngleAxis (/ Math/PI 2)
171 Vector3f/UNIT_X)))
172 x-move
173 (doto (Matrix3f.)
174 (.fromStartEndVectors Vector3f/UNIT_X
175 (.normalize (Vector3f. 1 1 0))))
177 timer (atom 0)]
178 (doto
179 (ConeJoint.
180 control-a control-b
181 (Vector3f. -8 0 0)
182 (Vector3f. 2 0 0)
183 ;;swivel swivel
184 ;;Matrix3f/IDENTITY Matrix3f/IDENTITY
185 x-move Matrix3f/IDENTITY
186 )
187 (.setCollisionBetweenLinkedBodys false)
188 (.setLimit (* 1 (/ Math/PI 4)) ;; twist
189 (* 1 (/ Math/PI 4)) ;; swing span in X-Y plane
190 (* 0 (/ Math/PI 4)))) ;; swing span in Y-Z plane
191 (world (nodify
192 [obj-a obj-b])
193 (merge standard-debug-controls
194 {"key-r" (fn [_ pressed?] (reset! move-up? pressed?))
195 "key-t" (fn [_ pressed?] (reset! move-down? pressed?))
196 "key-f" (fn [_ pressed?] (reset! move-left? pressed?))
197 "key-g" (fn [_ pressed?] (reset! move-right? pressed?))
198 "key-v" (fn [_ pressed?] (reset! roll-left? pressed?))
199 "key-b" (fn [_ pressed?] (reset! roll-right? pressed?))})
201 (fn [world]
202 (enable-debug world)
203 (set-gravity world Vector3f/ZERO)
204 )
206 (fn [world _]
208 (if @move-up?
209 (.applyForce control-a
210 (Vector3f. force 0 0)
211 (Vector3f. 0 0 0)))
212 (if @move-down?
213 (.applyForce control-a
214 (Vector3f. (- force) 0 0)
215 (Vector3f. 0 0 0)))
216 (if @move-left?
217 (.applyForce control-a
218 (Vector3f. 0 force 0)
219 (Vector3f. 0 0 0)))
220 (if @move-right?
221 (.applyForce control-a
222 (Vector3f. 0 (- force) 0)
223 (Vector3f. 0 0 0)))
225 (if @roll-left?
226 (.applyForce control-a
227 (Vector3f. 0 0 force)
228 (Vector3f. 0 0 0)))
229 (if @roll-right?
230 (.applyForce control-a
231 (Vector3f. 0 0 (- force))
232 (Vector3f. 0 0 0)))
234 (if (zero? (rem (swap! timer inc) 100))
235 (.attachChild
236 (.getRootNode world)
237 (sphere 0.05 :color ColorRGBA/Yellow
238 :physical? false :position
239 (.getWorldTranslation obj-a)))))
240 )
241 ))
243 (defn test-joint [joint]
244 (let [[origin top bottom floor] (world-setup joint)
245 control (.getControl top RigidBodyControl)
246 move-up? (atom false)
247 move-down? (atom false)
248 move-left? (atom false)
249 move-right? (atom false)
250 roll-left? (atom false)
251 roll-right? (atom false)
252 timer (atom 0)]
254 (world
255 (nodify [top bottom floor origin])
256 (merge standard-debug-controls
257 {"key-r" (fn [_ pressed?] (reset! move-up? pressed?))
258 "key-t" (fn [_ pressed?] (reset! move-down? pressed?))
259 "key-f" (fn [_ pressed?] (reset! move-left? pressed?))
260 "key-g" (fn [_ pressed?] (reset! move-right? pressed?))
261 "key-v" (fn [_ pressed?] (reset! roll-left? pressed?))
262 "key-b" (fn [_ pressed?] (reset! roll-right? pressed?))})
264 (fn [world]
265 (light-up-everything world)
266 (enable-debug world)
267 (set-gravity world (Vector3f. 0 0 0))
268 )
270 (fn [world _]
271 (if (zero? (rem (swap! timer inc) 100))
272 (do
273 ;; (println-repl @timer)
274 (.attachChild (.getRootNode world)
275 (sphere 0.05 :color ColorRGBA/Yellow
276 :position (.getWorldTranslation top)
277 :physical? false))
278 (.attachChild (.getRootNode world)
279 (sphere 0.05 :color ColorRGBA/LightGray
280 :position (.getWorldTranslation bottom)
281 :physical? false))))
283 (if @move-up?
284 (.applyTorque control
285 (.mult (.getPhysicsRotation control)
286 (Vector3f. 0 0 10))))
287 (if @move-down?
288 (.applyTorque control
289 (.mult (.getPhysicsRotation control)
290 (Vector3f. 0 0 -10))))
291 (if @move-left?
292 (.applyTorque control
293 (.mult (.getPhysicsRotation control)
294 (Vector3f. 0 10 0))))
295 (if @move-right?
296 (.applyTorque control
297 (.mult (.getPhysicsRotation control)
298 (Vector3f. 0 -10 0))))
299 (if @roll-left?
300 (.applyTorque control
301 (.mult (.getPhysicsRotation control)
302 (Vector3f. -1 0 0))))
303 (if @roll-right?
304 (.applyTorque control
305 (.mult (.getPhysicsRotation control)
306 (Vector3f. 1 0 0))))))))
307 #+end_src
310 * COMMENT generate source
311 #+begin_src clojure :tangle ../src/cortex/integration.clj
312 <<integration>>
313 #+end_src