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