Mercurial > cortex
view org/integration.org @ 297:d1206b11ae2d
creating final video
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Thu, 16 Feb 2012 12:48:51 -0700 |
parents | 1eed471e2ebf |
children | 85f3ff3e3f26 |
line wrap: on
line source
1 #+title:2 #+author: Robert McIntyre3 #+email: rlm@mit.edu4 #+description:5 #+keywords: simulation, jMonkeyEngine3, clojure6 #+SETUPFILE: ../../aurellem/org/setup.org7 #+INCLUDE: ../../aurellem/org/level-0.org9 * Intro11 This is the ultimate test which features all of the senses that I've12 made so far. The blender file for the creature serves as an example of13 a fully equipped creature in terms of senses. You can find it [[../assets/Models/test-creature/hand.blend][here]].15 #+name: integration16 #+begin_src clojure17 (ns cortex.integration18 "let's play!"19 {:author "Robert McIntyre"}20 (:use (cortex world util body sense21 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"))35 ;; Let the hand fall palm-up37 ;; it curls its phalanges, starting with the pinky.39 ;; it lets these fall back down?41 ;; block falls down onto the hand, accompanied by a sound. The block42 ;; can be seen by the hand's eye.44 ;; hand FORCEFULLY catapults the block so that it hits the camera.47 (defn motor-control-program48 "Create a function which will execute the motor script"49 [muscle-positions50 script]51 (let [current-frame (atom -1)52 keyed-script (group-by first script)53 current-forces (atom {}) ]54 (fn [effectors]55 (let [indexed-effectors (vec effectors)]56 (dorun57 (for [[_ part force] (keyed-script (swap! current-frame inc))]58 (swap! current-forces (fn [m] (assoc m part force)))))59 (doall (map (fn [effector power]60 (effector (int power)))61 effectors62 (map #(@current-forces % 0) muscle-positions)))))))64 (def muscle-positions65 [:pointer-2-e66 :pointer-2-f67 :thumb-168 :thumb-169 :pointer-1-e70 :pointer-1-f71 :thumb-2-e72 :thumb-2-f73 :middle-1-e74 :middle-1-f75 :pointer-3-f76 :pointer-3-e77 :middle-2-e78 :middle-2-f79 :middle-3-f80 :middle-3-e81 :pinky-2-e82 :pinky-2-f83 :pinky-3-f84 :pinky-3-e85 :ring-3-e86 :ring-3-f87 :ring-2-f88 :ring-2-e89 :ring-1-e90 :ring-1-f91 :thumb-1-e92 :thumb-1-f93 :pinky-1-f94 :pinky-1-e])96 (def full 9001)97 ;; the systax here is [keyframe body-part force]98 (def wiggle-each-finger-tip99 [[300 :pointer-3-f 50]102 [400 :middle-3-f full]103 [401 :middle-3-f 50]105 [600 :ring-3-f full]106 [601 :ring-3-f 40]108 [800 :pinky-3-f full]109 [801 :pinky-3-f 50]111 [1300 :pointer-1-f full]112 [1300 :pointer-2-f full]113 [1300 :pointer-3-f 0]115 [1289 :middle-1-f full]116 [1289 :middle-2-f full]117 [1289 :middle-3-f 0]119 [1310 :pointer-1-f 0]120 [1310 :pointer-2-f 0]121 [1310 :pointer-3-f 0]123 [1310 :middle-1-f 0]124 [1310 :middle-2-f 0]125 [1310 :middle-3-f 0]129 ])131 (defn gen-summon-ball []132 (let [wait (atom 20)]133 (fn [world]134 (if (= 0 (swap! wait dec))135 (let [brick136 (box 0.8 0.8 0.8 :mass 0.05137 :position (Vector3f. 0 0 0.5)138 :color (ColorRGBA/Red))]140 (.addControl141 brick142 (proxy [AbstractControl] []143 (controlUpdate [tpf]144 (println-repl (.getWorldTranslation brick)))145 (controlRender [_ _])))146 (add-element world brick))))))149 (def control-list150 [151 0 ;;pointer-21 #<Vector3f (0.99999994, 0.0, 0.0)>152 0 ;;pointer-21 #<Vector3f (-0.99999994, 0.0, 0.0)>153 0 ;;thumb-11 #<Vector3f (-0.8802276, -0.39781287, -0.25873658)>154 0 ;;thumb-11 #<Vector3f (0.8485723, 0.46149826, 0.2587364)>155 0 ;;pointer-11 #<Vector3f (0.99999994, 0.0, 0.0)>156 0 ;;pointer-11 #<Vector3f (-0.99999994, 0.0, 0.0)>157 0 ;;thumb-2.0011 #<Vector3f (-0.71705645, -0.44753736, -0.5343599)>158 0 ;;thumb-2.0011 #<Vector3f (-0.10567085, 0.83862597, 0.53435963)>159 0 ;;middle-11 #<Vector3f (0.99999994, 0.0, 0.0)>160 0 ;;middle-11 #<Vector3f (-0.99999994, 0.0, 0.0)>161 1 ;;pointer-31 #<Vector3f (-0.99999994, 0.0, 0.0)>162 0 ;;pointer-31 #<Vector3f (0.99999994, 0.0, 0.0)>163 0 ;;middle-21 #<Vector3f (0.99999994, 0.0, 0.0)>164 0 ;;middle-21 #<Vector3f (-0.99999994, 0.0, 0.0)>165 0 ;;middle-31 #<Vector3f (-0.99999994, 0.0, 0.0)>166 0 ;;middle-31 #<Vector3f (0.99999994, 0.0, 0.0)>167 0 ;;pinky-21 #<Vector3f (0.99999994, 0.0, 0.0)>168 0 ;;pinky-21 #<Vector3f (-0.99999994, 0.0, 0.0)>169 0 ;;pinky-31 #<Vector3f (-1, 0.0, 0.0)>170 0 ;;pinky-31 #<Vector3f (1.0, 0.0, 0.0)>171 0 ;;ring-31 #<Vector3f (0.99999994, 0.0, 0.0)>172 0 ;;ring-31 #<Vector3f (-0.99999994, 0.0, 0.0)>173 0 ;;ring-21 #<Vector3f (-0.99999994, 0.0, 0.0)>174 0 ;;ring-21 #<Vector3f (0.99999994, 0.0, 0.0)>175 0 ;;ring-11 #<Vector3f (0.99999994, 0.0, 0.0)>176 0 ;;ring-11 #<Vector3f (-0.99999994, 0.0, 0.0)>177 0 ;;thumb-11 #<Vector3f (-0.43154645, 0.7302033, 0.5296894)>178 0 ;;thumb-11 #<Vector3f (-0.8032993, -0.2722854, -0.5296895)>179 0 ;;pinky-11 #<Vector3f (-0.99999994, 0.0, 0.0)>180 0 ;;pinky-11 #<Vector3f (0.99999994, 0.0, 0.0)>181 ])183 (defn test-everything!184 ([] (test-everything! false))185 ([record?]186 (let [me (sphere 0.5 :color ColorRGBA/Blue :physical? false)188 bell (AudioNode. (asset-manager)189 "Sounds/pure.wav" false)190 creature (doto (load-blender-model hand)191 (body!))193 summon-ball (gen-summon-ball)194 ;;;;;;;;;;;; Sensors/Effectors ;;;;;;;;;;;;;;;;;;;;;;;;;;;;195 ;;touch (touch! creature)196 ;;touch-display (view-touch)198 ;;vision (vision! creature)199 ;;vision-display (view-vision)201 ;;hearing (hearing! creature)202 ;;hearing-display (view-hearing)204 prop (proprioception! creature)205 prop-display (view-proprioception)207 control-script (motor-control-program208 muscle-positions wiggle-each-finger-tip)209 muscles (movement! creature)210 muscle-display (view-movement)211 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;213 fix-display (gen-fix-display)]214 (world215 (nodify [creature216 (box 10 2 10 :position (Vector3f. 0 -9 0)217 :color ColorRGBA/Gray :mass 0)218 me])219 (merge standard-debug-controls220 {"key-return"221 (fn [_ value]222 (if value223 (.play bell)))})225 (fn [world]226 (.setTimer world (RatchetTimer. 60))227 (position-camera228 world (Vector3f. 7.7101235, 6.3628435, -14.15047)229 (Quaternion. 0.3644328, -0.2558489, 0.104854375, 0.8892332))230 (light-up-everything world)231 (enable-debug world)232 (add-camera! world233 (add-eye! creature234 (.getChild235 (.getChild creature "eyes") "eye"))236 (comp (view-image) BufferedImage!))237 (speed-up world)238 )239 (fn [world tpf]240 ;;(prop-display (prop))241 ;;(touch-display (map #(% (.getRootNode world)) touch))242 ;;(vision-display (map #(% world) vision))243 ;;(hearing-display (map #(% world) hearing))244 (summon-ball world)245 ;;(muscle-display246 (control-script muscles)247 ;;)249 (.setLocalTranslation me (.getLocation (.getCamera world)))250 (fix-display world))))))251 #+end_src253 #+results: integration254 : #'cortex.integration/test-everything!256 * COMMENT purgatory257 #+begin_src clojure258 (defn bullet-trans* []259 (let [obj-a (box 1.5 0.5 0.5 :color ColorRGBA/Red260 :position (Vector3f. 5 0 0)261 :mass 90)262 obj-b (sphere 0.5 :color ColorRGBA/Blue263 :position (Vector3f. -5 0 0)264 :mass 0)265 control-a (.getControl obj-a RigidBodyControl)266 control-b (.getControl obj-b RigidBodyControl)267 move-up? (atom nil)268 move-down? (atom nil)269 move-left? (atom nil)270 move-right? (atom nil)271 roll-left? (atom nil)272 roll-right? (atom nil)273 force 100274 swivel275 (.toRotationMatrix276 (doto (Quaternion.)277 (.fromAngleAxis (/ Math/PI 2)278 Vector3f/UNIT_X)))279 x-move280 (doto (Matrix3f.)281 (.fromStartEndVectors Vector3f/UNIT_X282 (.normalize (Vector3f. 1 1 0))))284 timer (atom 0)]285 (doto286 (ConeJoint.287 control-a control-b288 (Vector3f. -8 0 0)289 (Vector3f. 2 0 0)290 ;;swivel swivel291 ;;Matrix3f/IDENTITY Matrix3f/IDENTITY292 x-move Matrix3f/IDENTITY293 )294 (.setCollisionBetweenLinkedBodys false)295 (.setLimit (* 1 (/ Math/PI 4)) ;; twist296 (* 1 (/ Math/PI 4)) ;; swing span in X-Y plane297 (* 0 (/ Math/PI 4)))) ;; swing span in Y-Z plane298 (world (nodify299 [obj-a obj-b])300 (merge standard-debug-controls301 {"key-r" (fn [_ pressed?] (reset! move-up? pressed?))302 "key-t" (fn [_ pressed?] (reset! move-down? pressed?))303 "key-f" (fn [_ pressed?] (reset! move-left? pressed?))304 "key-g" (fn [_ pressed?] (reset! move-right? pressed?))305 "key-v" (fn [_ pressed?] (reset! roll-left? pressed?))306 "key-b" (fn [_ pressed?] (reset! roll-right? pressed?))})308 (fn [world]309 (enable-debug world)310 (set-gravity world Vector3f/ZERO)311 )313 (fn [world _]315 (if @move-up?316 (.applyForce control-a317 (Vector3f. force 0 0)318 (Vector3f. 0 0 0)))319 (if @move-down?320 (.applyForce control-a321 (Vector3f. (- force) 0 0)322 (Vector3f. 0 0 0)))323 (if @move-left?324 (.applyForce control-a325 (Vector3f. 0 force 0)326 (Vector3f. 0 0 0)))327 (if @move-right?328 (.applyForce control-a329 (Vector3f. 0 (- force) 0)330 (Vector3f. 0 0 0)))332 (if @roll-left?333 (.applyForce control-a334 (Vector3f. 0 0 force)335 (Vector3f. 0 0 0)))336 (if @roll-right?337 (.applyForce control-a338 (Vector3f. 0 0 (- force))339 (Vector3f. 0 0 0)))341 (if (zero? (rem (swap! timer inc) 100))342 (.attachChild343 (.getRootNode world)344 (sphere 0.05 :color ColorRGBA/Yellow345 :physical? false :position346 (.getWorldTranslation obj-a)))))347 )348 ))350 (defn test-joint [joint]351 (let [[origin top bottom floor] (world-setup joint)352 control (.getControl top RigidBodyControl)353 move-up? (atom false)354 move-down? (atom false)355 move-left? (atom false)356 move-right? (atom false)357 roll-left? (atom false)358 roll-right? (atom false)359 timer (atom 0)]361 (world362 (nodify [top bottom floor origin])363 (merge standard-debug-controls364 {"key-r" (fn [_ pressed?] (reset! move-up? pressed?))365 "key-t" (fn [_ pressed?] (reset! move-down? pressed?))366 "key-f" (fn [_ pressed?] (reset! move-left? pressed?))367 "key-g" (fn [_ pressed?] (reset! move-right? pressed?))368 "key-v" (fn [_ pressed?] (reset! roll-left? pressed?))369 "key-b" (fn [_ pressed?] (reset! roll-right? pressed?))})371 (fn [world]372 (light-up-everything world)373 (enable-debug world)374 (set-gravity world (Vector3f. 0 0 0))375 )377 (fn [world _]378 (if (zero? (rem (swap! timer inc) 100))379 (do380 ;; (println-repl @timer)381 (.attachChild (.getRootNode world)382 (sphere 0.05 :color ColorRGBA/Yellow383 :position (.getWorldTranslation top)384 :physical? false))385 (.attachChild (.getRootNode world)386 (sphere 0.05 :color ColorRGBA/LightGray387 :position (.getWorldTranslation bottom)388 :physical? false))))390 (if @move-up?391 (.applyTorque control392 (.mult (.getPhysicsRotation control)393 (Vector3f. 0 0 10))))394 (if @move-down?395 (.applyTorque control396 (.mult (.getPhysicsRotation control)397 (Vector3f. 0 0 -10))))398 (if @move-left?399 (.applyTorque control400 (.mult (.getPhysicsRotation control)401 (Vector3f. 0 10 0))))402 (if @move-right?403 (.applyTorque control404 (.mult (.getPhysicsRotation control)405 (Vector3f. 0 -10 0))))406 (if @roll-left?407 (.applyTorque control408 (.mult (.getPhysicsRotation control)409 (Vector3f. -1 0 0))))410 (if @roll-right?411 (.applyTorque control412 (.mult (.getPhysicsRotation control)413 (Vector3f. 1 0 0))))))))414 #+end_src417 * COMMENT generate source418 #+begin_src clojure :tangle ../src/cortex/integration.clj419 <<integration>>420 #+end_src