Mercurial > cortex
view org/integration.org @ 269:bbd787e12025
added idea
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Tue, 14 Feb 2012 17:54:32 -0600 |
parents | 305439cec54d |
children | 7351c9c0c471 |
line wrap: on
line source
1 #+title: First attempt at a creature!2 #+author: Robert McIntyre3 #+email: rlm@mit.edu4 #+description:5 #+keywords: simulation, jMonkeyEngine3, clojure6 #+SETUPFILE: ../../aurellem/org/setup.org7 #+INCLUDE: ../../aurellem/org/level-0.org12 * Intro13 So far, I've made the following senses --14 - Vision15 - Hearing16 - Touch17 - Proprioception19 And one effector:20 - Movement22 However, the code so far has only enabled these senses, but has not23 actually implemented them. For example, there is still a lot of work24 to be done for vision. I need to be able to create an /eyeball/ in25 simulation that can be moved around and see the world from different26 angles. I also need to determine weather to use log-polar or cartesian27 for the visual input, and I need to determine how/wether to28 disceritise the visual input.30 I also want to be able to visualize both the sensors and the31 effectors in pretty pictures. This semi-retarted creature will be my32 first attempt at bringing everything together.34 * The creature's body36 Still going to do an eve-like body in blender, but due to problems37 importing the joints, etc into jMonkeyEngine3, I'm going to do all38 the connecting here in clojure code, using the names of the individual39 components and trial and error. Later, I'll maybe make some sort of40 creature-building modifications to blender that support whatever41 discritized senses I'm going to make.43 #+name: integration44 #+begin_src clojure45 (ns cortex.integration46 "let's play!"47 {:author "Robert McIntyre"}48 (:use (cortex world util body49 hearing touch vision sense proprioception movement))50 (:import (com.jme3.math ColorRGBA Vector3f))51 (:import com.jme3.audio.AudioNode)52 (:import com.aurellem.capture.RatchetTimer))54 (def hand "Models/creature1/one.blend")56 (def worm "Models/creature1/try-again.blend")58 (defn test-creature [thing]59 (let [x-axis60 (box 1 0.01 0.01 :physical? false :color ColorRGBA/Red)61 y-axis62 (box 0.01 1 0.01 :physical? false :color ColorRGBA/Green)63 z-axis64 (box 0.01 0.01 1 :physical? false :color ColorRGBA/Blue)66 me (sphere 0.5 :color ColorRGBA/Blue :physical? false)67 bell (AudioNode. (asset-manager)68 "Sounds/pure.wav" false)70 fix-display71 (runonce (fn [world]72 (add-camera! world (.getCamera world) no-op)))73 creature (doto (load-blender-model thing) (body!))75 ;;;;;;;;;;;; Sensors/Effectors ;;;;;;;;;;;;;;;;;;;;;;;;;;;;76 touch (touch! creature)77 touch-display (view-touch)79 vision (vision! creature)80 vision-display (view-vision)82 hearing (hearing! creature)83 hearing-display (view-hearing)85 prop (proprioception! creature)86 prop-display (view-proprioception)88 muscle-exertion (atom 0)89 muscles (movement! creature)90 muscle-display (view-movement)]92 (apply93 world94 (with-movement95 (.getChild creature "worm-21")96 ["key-r" "key-t"97 "key-f" "key-g"98 "key-v" "key-b"]99 [10 10 10 10 1 1]100 [(nodify [creature101 (box 10 2 10 :position (Vector3f. 0 -9 0)102 :color ColorRGBA/Gray :mass 0)103 x-axis y-axis z-axis104 me])105 (merge standard-debug-controls106 {"key-return"107 (fn [_ value]108 (if value109 (do110 (println-repl "play-sound")111 (.play bell))))112 "key-h"113 (fn [_ value]114 (if value115 (swap! muscle-exertion (partial + 20))))116 "key-n"117 (fn [_ value]118 (if value119 (swap! muscle-exertion (fn [v] (- v 20)))))})120 (fn [world]121 (light-up-everything world)122 (enable-debug world)123 (add-camera! world124 (add-eye! creature125 (.getChild126 (.getChild creature "eyes") "eye"))127 (comp (view-image) BufferedImage!))128 (.setTimer world (RatchetTimer. 60))129 (speed-up world)130 (set-gravity world (Vector3f. 0 0 0))131 (comment132 (com.aurellem.capture.Capture/captureVideo133 world (file-str "/home/r/proj/ai-videos/hand"))))134 (fn [world tpf]135 (prop-display (prop))136 (touch-display (map #(% (.getRootNode world)) touch))137 (vision-display (map #(% world) vision))138 (hearing-display (map #(% world) hearing))139 (muscle-display (map #(% @muscle-exertion) muscles))140 (.setLocalTranslation me (.getLocation (.getCamera world)))141 (fix-display world))]))))142 #+end_src144 #+results: body-1145 : #'cortex.silly/follow-test148 * COMMENT purgatory149 #+begin_src clojure151 (defn bullet-trans* []152 (let [obj-a (box 1.5 0.5 0.5 :color ColorRGBA/Red153 :position (Vector3f. 5 0 0)154 :mass 90)155 obj-b (sphere 0.5 :color ColorRGBA/Blue156 :position (Vector3f. -5 0 0)157 :mass 0)158 control-a (.getControl obj-a RigidBodyControl)159 control-b (.getControl obj-b RigidBodyControl)160 move-up? (atom nil)161 move-down? (atom nil)162 move-left? (atom nil)163 move-right? (atom nil)164 roll-left? (atom nil)165 roll-right? (atom nil)166 force 100167 swivel168 (.toRotationMatrix169 (doto (Quaternion.)170 (.fromAngleAxis (/ Math/PI 2)171 Vector3f/UNIT_X)))172 x-move173 (doto (Matrix3f.)174 (.fromStartEndVectors Vector3f/UNIT_X175 (.normalize (Vector3f. 1 1 0))))177 timer (atom 0)]178 (doto179 (ConeJoint.180 control-a control-b181 (Vector3f. -8 0 0)182 (Vector3f. 2 0 0)183 ;;swivel swivel184 ;;Matrix3f/IDENTITY Matrix3f/IDENTITY185 x-move Matrix3f/IDENTITY186 )187 (.setCollisionBetweenLinkedBodys false)188 (.setLimit (* 1 (/ Math/PI 4)) ;; twist189 (* 1 (/ Math/PI 4)) ;; swing span in X-Y plane190 (* 0 (/ Math/PI 4)))) ;; swing span in Y-Z plane191 (world (nodify192 [obj-a obj-b])193 (merge standard-debug-controls194 {"key-r" (fn [_ pressed?] (reset! move-up? pressed?))195 "key-t" (fn [_ pressed?] (reset! move-down? pressed?))196 "key-f" (fn [_ pressed?] (reset! move-left? pressed?))197 "key-g" (fn [_ pressed?] (reset! move-right? pressed?))198 "key-v" (fn [_ pressed?] (reset! roll-left? pressed?))199 "key-b" (fn [_ pressed?] (reset! roll-right? pressed?))})201 (fn [world]202 (enable-debug world)203 (set-gravity world Vector3f/ZERO)204 )206 (fn [world _]208 (if @move-up?209 (.applyForce control-a210 (Vector3f. force 0 0)211 (Vector3f. 0 0 0)))212 (if @move-down?213 (.applyForce control-a214 (Vector3f. (- force) 0 0)215 (Vector3f. 0 0 0)))216 (if @move-left?217 (.applyForce control-a218 (Vector3f. 0 force 0)219 (Vector3f. 0 0 0)))220 (if @move-right?221 (.applyForce control-a222 (Vector3f. 0 (- force) 0)223 (Vector3f. 0 0 0)))225 (if @roll-left?226 (.applyForce control-a227 (Vector3f. 0 0 force)228 (Vector3f. 0 0 0)))229 (if @roll-right?230 (.applyForce control-a231 (Vector3f. 0 0 (- force))232 (Vector3f. 0 0 0)))234 (if (zero? (rem (swap! timer inc) 100))235 (.attachChild236 (.getRootNode world)237 (sphere 0.05 :color ColorRGBA/Yellow238 :physical? false :position239 (.getWorldTranslation obj-a)))))240 )241 ))243 (defn test-joint [joint]244 (let [[origin top bottom floor] (world-setup joint)245 control (.getControl top RigidBodyControl)246 move-up? (atom false)247 move-down? (atom false)248 move-left? (atom false)249 move-right? (atom false)250 roll-left? (atom false)251 roll-right? (atom false)252 timer (atom 0)]254 (world255 (nodify [top bottom floor origin])256 (merge standard-debug-controls257 {"key-r" (fn [_ pressed?] (reset! move-up? pressed?))258 "key-t" (fn [_ pressed?] (reset! move-down? pressed?))259 "key-f" (fn [_ pressed?] (reset! move-left? pressed?))260 "key-g" (fn [_ pressed?] (reset! move-right? pressed?))261 "key-v" (fn [_ pressed?] (reset! roll-left? pressed?))262 "key-b" (fn [_ pressed?] (reset! roll-right? pressed?))})264 (fn [world]265 (light-up-everything world)266 (enable-debug world)267 (set-gravity world (Vector3f. 0 0 0))268 )270 (fn [world _]271 (if (zero? (rem (swap! timer inc) 100))272 (do273 ;; (println-repl @timer)274 (.attachChild (.getRootNode world)275 (sphere 0.05 :color ColorRGBA/Yellow276 :position (.getWorldTranslation top)277 :physical? false))278 (.attachChild (.getRootNode world)279 (sphere 0.05 :color ColorRGBA/LightGray280 :position (.getWorldTranslation bottom)281 :physical? false))))283 (if @move-up?284 (.applyTorque control285 (.mult (.getPhysicsRotation control)286 (Vector3f. 0 0 10))))287 (if @move-down?288 (.applyTorque control289 (.mult (.getPhysicsRotation control)290 (Vector3f. 0 0 -10))))291 (if @move-left?292 (.applyTorque control293 (.mult (.getPhysicsRotation control)294 (Vector3f. 0 10 0))))295 (if @move-right?296 (.applyTorque control297 (.mult (.getPhysicsRotation control)298 (Vector3f. 0 -10 0))))299 (if @roll-left?300 (.applyTorque control301 (.mult (.getPhysicsRotation control)302 (Vector3f. -1 0 0))))303 (if @roll-right?304 (.applyTorque control305 (.mult (.getPhysicsRotation control)306 (Vector3f. 1 0 0))))))))307 #+end_src310 * COMMENT generate source311 #+begin_src clojure :tangle ../src/cortex/integration.clj312 <<integration>>313 #+end_src