annotate org/integration.org @ 289:3fad36e4b780

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