Mercurial > cortex
view org/integration.org @ 285:decdbb24ef7c
adding touch to the hand
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Thu, 16 Feb 2012 06:39:34 -0700 |
parents | 2ad29b68ff22 |
children | 76a5edd6507d |
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 (world64 (nodify [creature65 (box 10 2 10 :position (Vector3f. 0 -9 0)66 :color ColorRGBA/Gray :mass 0)67 me])68 (merge standard-debug-controls69 {"key-return"70 (fn [_ value]71 (if value72 (.play bell)))73 "key-h"74 (fn [_ value]75 (if value76 (swap! muscle-exertion (partial + 20))))77 "key-n"78 (fn [_ value]79 (if value80 (swap! muscle-exertion (fn [v] (- v 20)))))})81 (fn [world]82 (.setTimer world (RatchetTimer. 60))83 (light-up-everything world)84 (enable-debug world)85 (add-camera! world86 (add-eye! creature87 (.getChild88 (.getChild creature "eyes") "eye"))89 (comp (view-image) BufferedImage!))90 (speed-up world))91 (fn [world tpf]92 (prop-display (prop))93 (touch-display (map #(% (.getRootNode world)) touch))94 (vision-display (map #(% world) vision))95 (hearing-display (map #(% world) hearing))96 (muscle-display (map #(% @muscle-exertion) muscles))97 (.setLocalTranslation me (.getLocation (.getCamera world)))98 (fix-display world))))))99 #+end_src101 #+results: integration102 : #'cortex.integration/test-everything!104 * COMMENT purgatory105 #+begin_src clojure106 (defn bullet-trans* []107 (let [obj-a (box 1.5 0.5 0.5 :color ColorRGBA/Red108 :position (Vector3f. 5 0 0)109 :mass 90)110 obj-b (sphere 0.5 :color ColorRGBA/Blue111 :position (Vector3f. -5 0 0)112 :mass 0)113 control-a (.getControl obj-a RigidBodyControl)114 control-b (.getControl obj-b RigidBodyControl)115 move-up? (atom nil)116 move-down? (atom nil)117 move-left? (atom nil)118 move-right? (atom nil)119 roll-left? (atom nil)120 roll-right? (atom nil)121 force 100122 swivel123 (.toRotationMatrix124 (doto (Quaternion.)125 (.fromAngleAxis (/ Math/PI 2)126 Vector3f/UNIT_X)))127 x-move128 (doto (Matrix3f.)129 (.fromStartEndVectors Vector3f/UNIT_X130 (.normalize (Vector3f. 1 1 0))))132 timer (atom 0)]133 (doto134 (ConeJoint.135 control-a control-b136 (Vector3f. -8 0 0)137 (Vector3f. 2 0 0)138 ;;swivel swivel139 ;;Matrix3f/IDENTITY Matrix3f/IDENTITY140 x-move Matrix3f/IDENTITY141 )142 (.setCollisionBetweenLinkedBodys false)143 (.setLimit (* 1 (/ Math/PI 4)) ;; twist144 (* 1 (/ Math/PI 4)) ;; swing span in X-Y plane145 (* 0 (/ Math/PI 4)))) ;; swing span in Y-Z plane146 (world (nodify147 [obj-a obj-b])148 (merge standard-debug-controls149 {"key-r" (fn [_ pressed?] (reset! move-up? pressed?))150 "key-t" (fn [_ pressed?] (reset! move-down? pressed?))151 "key-f" (fn [_ pressed?] (reset! move-left? pressed?))152 "key-g" (fn [_ pressed?] (reset! move-right? pressed?))153 "key-v" (fn [_ pressed?] (reset! roll-left? pressed?))154 "key-b" (fn [_ pressed?] (reset! roll-right? pressed?))})156 (fn [world]157 (enable-debug world)158 (set-gravity world Vector3f/ZERO)159 )161 (fn [world _]163 (if @move-up?164 (.applyForce control-a165 (Vector3f. force 0 0)166 (Vector3f. 0 0 0)))167 (if @move-down?168 (.applyForce control-a169 (Vector3f. (- force) 0 0)170 (Vector3f. 0 0 0)))171 (if @move-left?172 (.applyForce control-a173 (Vector3f. 0 force 0)174 (Vector3f. 0 0 0)))175 (if @move-right?176 (.applyForce control-a177 (Vector3f. 0 (- force) 0)178 (Vector3f. 0 0 0)))180 (if @roll-left?181 (.applyForce control-a182 (Vector3f. 0 0 force)183 (Vector3f. 0 0 0)))184 (if @roll-right?185 (.applyForce control-a186 (Vector3f. 0 0 (- force))187 (Vector3f. 0 0 0)))189 (if (zero? (rem (swap! timer inc) 100))190 (.attachChild191 (.getRootNode world)192 (sphere 0.05 :color ColorRGBA/Yellow193 :physical? false :position194 (.getWorldTranslation obj-a)))))195 )196 ))198 (defn test-joint [joint]199 (let [[origin top bottom floor] (world-setup joint)200 control (.getControl top RigidBodyControl)201 move-up? (atom false)202 move-down? (atom false)203 move-left? (atom false)204 move-right? (atom false)205 roll-left? (atom false)206 roll-right? (atom false)207 timer (atom 0)]209 (world210 (nodify [top bottom floor origin])211 (merge standard-debug-controls212 {"key-r" (fn [_ pressed?] (reset! move-up? pressed?))213 "key-t" (fn [_ pressed?] (reset! move-down? pressed?))214 "key-f" (fn [_ pressed?] (reset! move-left? pressed?))215 "key-g" (fn [_ pressed?] (reset! move-right? pressed?))216 "key-v" (fn [_ pressed?] (reset! roll-left? pressed?))217 "key-b" (fn [_ pressed?] (reset! roll-right? pressed?))})219 (fn [world]220 (light-up-everything world)221 (enable-debug world)222 (set-gravity world (Vector3f. 0 0 0))223 )225 (fn [world _]226 (if (zero? (rem (swap! timer inc) 100))227 (do228 ;; (println-repl @timer)229 (.attachChild (.getRootNode world)230 (sphere 0.05 :color ColorRGBA/Yellow231 :position (.getWorldTranslation top)232 :physical? false))233 (.attachChild (.getRootNode world)234 (sphere 0.05 :color ColorRGBA/LightGray235 :position (.getWorldTranslation bottom)236 :physical? false))))238 (if @move-up?239 (.applyTorque control240 (.mult (.getPhysicsRotation control)241 (Vector3f. 0 0 10))))242 (if @move-down?243 (.applyTorque control244 (.mult (.getPhysicsRotation control)245 (Vector3f. 0 0 -10))))246 (if @move-left?247 (.applyTorque control248 (.mult (.getPhysicsRotation control)249 (Vector3f. 0 10 0))))250 (if @move-right?251 (.applyTorque control252 (.mult (.getPhysicsRotation control)253 (Vector3f. 0 -10 0))))254 (if @roll-left?255 (.applyTorque control256 (.mult (.getPhysicsRotation control)257 (Vector3f. -1 0 0))))258 (if @roll-right?259 (.applyTorque control260 (.mult (.getPhysicsRotation control)261 (Vector3f. 1 0 0))))))))262 #+end_src265 * COMMENT generate source266 #+begin_src clojure :tangle ../src/cortex/integration.clj267 <<integration>>268 #+end_src