view org/integration.org @ 282:2ad29b68ff22

saving before update of blender
author Robert McIntyre <rlm@mit.edu>
date Wed, 15 Feb 2012 14:09:20 -0700
parents 7351c9c0c471
children decdbb24ef7c
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)
41 creature (doto (load-blender-model hand)
42 (body!))
44 ;;;;;;;;;;;; Sensors/Effectors ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
45 touch (touch! creature)
46 touch-display (view-touch)
48 vision (vision! creature)
49 vision-display (view-vision)
51 hearing (hearing! creature)
52 hearing-display (view-hearing)
54 prop (proprioception! creature)
55 prop-display (view-proprioception)
57 muscle-exertion (atom 0)
58 muscles (movement! creature)
59 muscle-display (view-movement)
60 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
62 fix-display (gen-fix-display)]
63 (apply
64 world
65 (with-movement
66 (.getChild creature "palm")
67 ["key-r" "key-t"
68 "key-f" "key-g"
69 "key-v" "key-b"]
70 [10 10 10 10 1 1]
71 [(nodify [creature
72 (box 10 2 10 :position (Vector3f. 0 -9 0)
73 :color ColorRGBA/Gray :mass 0)
74 me])
75 (merge standard-debug-controls
76 {"key-return"
77 (fn [_ value]
78 (if value
79 (do
80 (println-repl "play-sound")
81 (.play bell))))
82 "key-h"
83 (fn [_ value]
84 (if value
85 (swap! muscle-exertion (partial + 20))))
86 "key-n"
87 (fn [_ value]
88 (if value
89 (swap! muscle-exertion (fn [v] (- v 20)))))})
90 (fn [world]
91 (.setTimer world (RatchetTimer. 60))
92 (light-up-everything world)
93 (enable-debug world)
94 (add-camera! world
95 (add-eye! creature
96 (.getChild
97 (.getChild creature "eyes") "eye"))
98 (comp (view-image) BufferedImage!))
99 (speed-up world))
100 (fn [world tpf]
101 (prop-display (prop))
102 (touch-display (map #(% (.getRootNode world)) touch))
103 (vision-display (map #(% world) vision))
104 (hearing-display (map #(% world) hearing))
105 (muscle-display (map #(% @muscle-exertion) muscles))
106 (.setLocalTranslation me (.getLocation (.getCamera world)))
107 (fix-display world))])))))
108 #+end_src
110 #+results: integration
111 : #'cortex.integration/test-everything!
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