view org/integration.org @ 294:76a5edd6507d

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