Mercurial > cortex
view 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 |
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"))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)44 creature (doto (load-blender-model hand)45 (body!))47 ;;;;;;;;;;;; Sensors/Effectors ;;;;;;;;;;;;;;;;;;;;;;;;;;;;48 touch (touch! creature)49 touch-display (view-touch)51 vision (vision! creature)52 vision-display (view-vision)54 hearing (hearing! creature)55 hearing-display (view-hearing)57 prop (proprioception! creature)58 prop-display (view-proprioception)60 muscle-exertion (atom 0)61 muscles (movement! creature)62 muscle-display (view-movement)63 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;65 fix-display (gen-fix-display)]66 (apply67 world68 (with-movement69 (.getChild creature "palm")70 ["key-r" "key-t"71 "key-f" "key-g"72 "key-v" "key-b"]73 [10 10 10 10 1 1]74 [(nodify [creature75 (box 10 2 10 :position (Vector3f. 0 -9 0)76 :color ColorRGBA/Gray :mass 0)77 me])78 (merge standard-debug-controls79 {"key-return"80 (fn [_ value]81 (if value82 (do83 (println-repl "play-sound")84 (.play bell))))85 "key-h"86 (fn [_ value]87 (if value88 (swap! muscle-exertion (partial + 20))))89 "key-n"90 (fn [_ value]91 (if value92 (swap! muscle-exertion (fn [v] (- v 20)))))})93 (fn [world]94 (.setTimer world (RatchetTimer. 60))95 (light-up-everything world)96 (enable-debug world)97 (add-camera! world98 (add-eye! creature99 (.getChild100 (.getChild creature "eyes") "eye"))101 (comp (view-image) BufferedImage!))102 (speed-up world))103 (fn [world tpf]104 (prop-display (prop))105 (touch-display (map #(% (.getRootNode world)) touch))106 (vision-display (map #(% world) vision))107 (hearing-display (map #(% world) hearing))108 (muscle-display (map #(% @muscle-exertion) muscles))109 (.setLocalTranslation me (.getLocation (.getCamera world)))110 (fix-display world))])))))111 #+end_src113 * COMMENT purgatory114 #+begin_src clojure115 (defn bullet-trans* []116 (let [obj-a (box 1.5 0.5 0.5 :color ColorRGBA/Red117 :position (Vector3f. 5 0 0)118 :mass 90)119 obj-b (sphere 0.5 :color ColorRGBA/Blue120 :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 100131 swivel132 (.toRotationMatrix133 (doto (Quaternion.)134 (.fromAngleAxis (/ Math/PI 2)135 Vector3f/UNIT_X)))136 x-move137 (doto (Matrix3f.)138 (.fromStartEndVectors Vector3f/UNIT_X139 (.normalize (Vector3f. 1 1 0))))141 timer (atom 0)]142 (doto143 (ConeJoint.144 control-a control-b145 (Vector3f. -8 0 0)146 (Vector3f. 2 0 0)147 ;;swivel swivel148 ;;Matrix3f/IDENTITY Matrix3f/IDENTITY149 x-move Matrix3f/IDENTITY150 )151 (.setCollisionBetweenLinkedBodys false)152 (.setLimit (* 1 (/ Math/PI 4)) ;; twist153 (* 1 (/ Math/PI 4)) ;; swing span in X-Y plane154 (* 0 (/ Math/PI 4)))) ;; swing span in Y-Z plane155 (world (nodify156 [obj-a obj-b])157 (merge standard-debug-controls158 {"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-a174 (Vector3f. force 0 0)175 (Vector3f. 0 0 0)))176 (if @move-down?177 (.applyForce control-a178 (Vector3f. (- force) 0 0)179 (Vector3f. 0 0 0)))180 (if @move-left?181 (.applyForce control-a182 (Vector3f. 0 force 0)183 (Vector3f. 0 0 0)))184 (if @move-right?185 (.applyForce control-a186 (Vector3f. 0 (- force) 0)187 (Vector3f. 0 0 0)))189 (if @roll-left?190 (.applyForce control-a191 (Vector3f. 0 0 force)192 (Vector3f. 0 0 0)))193 (if @roll-right?194 (.applyForce control-a195 (Vector3f. 0 0 (- force))196 (Vector3f. 0 0 0)))198 (if (zero? (rem (swap! timer inc) 100))199 (.attachChild200 (.getRootNode world)201 (sphere 0.05 :color ColorRGBA/Yellow202 :physical? false :position203 (.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 (world219 (nodify [top bottom floor origin])220 (merge standard-debug-controls221 {"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 (do237 ;; (println-repl @timer)238 (.attachChild (.getRootNode world)239 (sphere 0.05 :color ColorRGBA/Yellow240 :position (.getWorldTranslation top)241 :physical? false))242 (.attachChild (.getRootNode world)243 (sphere 0.05 :color ColorRGBA/LightGray244 :position (.getWorldTranslation bottom)245 :physical? false))))247 (if @move-up?248 (.applyTorque control249 (.mult (.getPhysicsRotation control)250 (Vector3f. 0 0 10))))251 (if @move-down?252 (.applyTorque control253 (.mult (.getPhysicsRotation control)254 (Vector3f. 0 0 -10))))255 (if @move-left?256 (.applyTorque control257 (.mult (.getPhysicsRotation control)258 (Vector3f. 0 10 0))))259 (if @move-right?260 (.applyTorque control261 (.mult (.getPhysicsRotation control)262 (Vector3f. 0 -10 0))))263 (if @roll-left?264 (.applyTorque control265 (.mult (.getPhysicsRotation control)266 (Vector3f. -1 0 0))))267 (if @roll-right?268 (.applyTorque control269 (.mult (.getPhysicsRotation control)270 (Vector3f. 1 0 0))))))))271 #+end_src274 * COMMENT generate source275 #+begin_src clojure :tangle ../src/cortex/integration.clj276 <<integration>>277 #+end_src