Mercurial > cortex
view org/integration.org @ 282:2ad29b68ff22
saving before update of blender
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Wed, 15 Feb 2012 14:09:20 -0700 |
parents | 7351c9c0c471 |
children | decdbb24ef7c |
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)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 (apply64 world65 (with-movement66 (.getChild creature "palm")67 ["key-r" "key-t"68 "key-f" "key-g"69 "key-v" "key-b"]70 [10 10 10 10 1 1]71 [(nodify [creature72 (box 10 2 10 :position (Vector3f. 0 -9 0)73 :color ColorRGBA/Gray :mass 0)74 me])75 (merge standard-debug-controls76 {"key-return"77 (fn [_ value]78 (if value79 (do80 (println-repl "play-sound")81 (.play bell))))82 "key-h"83 (fn [_ value]84 (if value85 (swap! muscle-exertion (partial + 20))))86 "key-n"87 (fn [_ value]88 (if value89 (swap! muscle-exertion (fn [v] (- v 20)))))})90 (fn [world]91 (.setTimer world (RatchetTimer. 60))92 (light-up-everything world)93 (enable-debug world)94 (add-camera! world95 (add-eye! creature96 (.getChild97 (.getChild creature "eyes") "eye"))98 (comp (view-image) BufferedImage!))99 (speed-up world))100 (fn [world tpf]101 (prop-display (prop))102 (touch-display (map #(% (.getRootNode world)) touch))103 (vision-display (map #(% world) vision))104 (hearing-display (map #(% world) hearing))105 (muscle-display (map #(% @muscle-exertion) muscles))106 (.setLocalTranslation me (.getLocation (.getCamera world)))107 (fix-display world))])))))108 #+end_src110 #+results: integration111 : #'cortex.integration/test-everything!113 * 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