rlm@281: #+title: rlm@73: #+author: Robert McIntyre rlm@73: #+email: rlm@mit.edu rlm@73: #+description: rlm@73: #+keywords: simulation, jMonkeyEngine3, clojure rlm@73: #+SETUPFILE: ../../aurellem/org/setup.org rlm@73: #+INCLUDE: ../../aurellem/org/level-0.org rlm@73: rlm@281: * Intro rlm@129: rlm@281: This is the ultimate test which features all of the senses that I've rlm@281: made so far. The blender file for the creature serves as an example of rlm@281: a fully equipped creature in terms of senses. You can find it [[../assets/Models/test-creature/hand.blend][here]]. rlm@73: rlm@192: #+name: integration rlm@73: #+begin_src clojure rlm@192: (ns cortex.integration rlm@73: "let's play!" rlm@192: {:author "Robert McIntyre"} rlm@281: (:use (cortex world util body sense rlm@281: hearing touch vision proprioception movement)) rlm@192: (:import (com.jme3.math ColorRGBA Vector3f)) rlm@281: (:import java.io.File) rlm@192: (:import com.jme3.audio.AudioNode) rlm@192: (:import com.aurellem.capture.RatchetTimer)) rlm@73: rlm@281: (dorun (cortex.import/mega-import-jme3)) rlm@281: (rlm.rlm-commands/help) rlm@74: rlm@281: (def hand "Models/test-creature/hand.blend") rlm@78: rlm@281: (def output-base (File. "/home/r/proj/cortex/render/hand")) rlm@189: rlm@295: (def control-list rlm@295: [ rlm@295: 0 ;;pointer-21 # rlm@295: 1 ;;pointer-21 # rlm@295: 0 ;;thumb-11 # rlm@295: 0 ;;thumb-11 # rlm@295: 0 ;;pointer-11 # rlm@295: 0 ;;pointer-11 # rlm@295: 0 ;;thumb-2.0011 # rlm@295: 0 ;;thumb-2.0011 # rlm@295: 0 ;;middle-11 # rlm@295: 0 ;;middle-11 # rlm@295: 0 ;;pointer-31 # rlm@295: 0 ;;pointer-31 # rlm@295: 0 ;;middle-21 # rlm@295: 0 ;;middle-21 # rlm@295: 0 ;;middle-31 # rlm@295: 0 ;;middle-31 # rlm@295: 0 ;;pinky-21 # rlm@295: 0 ;;pinky-21 # rlm@295: 0 ;;pinky-31 # rlm@295: 0 ;;ring-31 # rlm@295: 0 ;;ring-31 # rlm@295: 0 ;;ring-21 # rlm@295: 0 ;;ring-21 # rlm@295: 0 ;;ring-11 # rlm@295: 0 ;;ring-11 # rlm@295: 0 ;;thumb-11 # rlm@295: 0 ;;thumb-11 # rlm@295: 0 ;;pinky-11 # rlm@295: 0 ;;pinky-11 # rlm@295: ]) rlm@295: rlm@281: (defn test-everything! rlm@281: ([] (test-everything! false)) rlm@281: ([record?] rlm@281: (let [me (sphere 0.5 :color ColorRGBA/Blue :physical? false) rlm@281: rlm@192: bell (AudioNode. (asset-manager) rlm@192: "Sounds/pure.wav" false) rlm@281: creature (doto (load-blender-model hand) rlm@281: (body!)) rlm@281: rlm@192: ;;;;;;;;;;;; Sensors/Effectors ;;;;;;;;;;;;;;;;;;;;;;;;;;;; rlm@294: ;;touch (touch! creature) rlm@294: ;;touch-display (view-touch) rlm@189: rlm@294: ;;vision (vision! creature) rlm@294: ;;vision-display (view-vision) rlm@189: rlm@294: ;;hearing (hearing! creature) rlm@294: ;;hearing-display (view-hearing) rlm@189: rlm@173: prop (proprioception! creature) rlm@190: prop-display (view-proprioception) rlm@148: rlm@191: muscle-exertion (atom 0) rlm@191: muscles (movement! creature) rlm@281: muscle-display (view-movement) rlm@281: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; rlm@189: rlm@281: fix-display (gen-fix-display)] rlm@285: (world rlm@285: (nodify [creature rlm@285: (box 10 2 10 :position (Vector3f. 0 -9 0) rlm@285: :color ColorRGBA/Gray :mass 0) rlm@285: me]) rlm@285: (merge standard-debug-controls rlm@285: {"key-return" rlm@285: (fn [_ value] rlm@285: (if value rlm@285: (.play bell))) rlm@285: "key-h" rlm@285: (fn [_ value] rlm@285: (if value rlm@285: (swap! muscle-exertion (partial + 20)))) rlm@285: "key-n" rlm@285: (fn [_ value] rlm@285: (if value rlm@285: (swap! muscle-exertion (fn [v] (- v 20)))))}) rlm@285: (fn [world] rlm@285: (.setTimer world (RatchetTimer. 60)) rlm@285: (light-up-everything world) rlm@285: (enable-debug world) rlm@285: (add-camera! world rlm@285: (add-eye! creature rlm@285: (.getChild rlm@285: (.getChild creature "eyes") "eye")) rlm@285: (comp (view-image) BufferedImage!)) rlm@285: (speed-up world)) rlm@285: (fn [world tpf] rlm@294: ;;(prop-display (prop)) rlm@294: ;;(touch-display (map #(% (.getRootNode world)) touch)) rlm@294: ;;(vision-display (map #(% world) vision)) rlm@294: ;;(hearing-display (map #(% world) hearing)) rlm@295: rlm@295: (muscle-display rlm@295: (map (fn [effector control] rlm@295: (effector (int (* @muscle-exertion control)))) rlm@295: muscles rlm@295: control-list)) rlm@295: rlm@285: (.setLocalTranslation me (.getLocation (.getCamera world))) rlm@285: (fix-display world)))))) rlm@87: #+end_src rlm@83: rlm@282: #+results: integration rlm@282: : #'cortex.integration/test-everything! rlm@282: rlm@78: * COMMENT purgatory rlm@78: #+begin_src clojure rlm@77: (defn bullet-trans* [] rlm@77: (let [obj-a (box 1.5 0.5 0.5 :color ColorRGBA/Red rlm@77: :position (Vector3f. 5 0 0) rlm@77: :mass 90) rlm@77: obj-b (sphere 0.5 :color ColorRGBA/Blue rlm@77: :position (Vector3f. -5 0 0) rlm@77: :mass 0) rlm@77: control-a (.getControl obj-a RigidBodyControl) rlm@77: control-b (.getControl obj-b RigidBodyControl) rlm@77: move-up? (atom nil) rlm@77: move-down? (atom nil) rlm@77: move-left? (atom nil) rlm@77: move-right? (atom nil) rlm@77: roll-left? (atom nil) rlm@77: roll-right? (atom nil) rlm@77: force 100 rlm@77: swivel rlm@77: (.toRotationMatrix rlm@77: (doto (Quaternion.) rlm@77: (.fromAngleAxis (/ Math/PI 2) rlm@77: Vector3f/UNIT_X))) rlm@77: x-move rlm@77: (doto (Matrix3f.) rlm@77: (.fromStartEndVectors Vector3f/UNIT_X rlm@77: (.normalize (Vector3f. 1 1 0)))) rlm@77: rlm@77: timer (atom 0)] rlm@77: (doto rlm@77: (ConeJoint. rlm@77: control-a control-b rlm@77: (Vector3f. -8 0 0) rlm@77: (Vector3f. 2 0 0) rlm@77: ;;swivel swivel rlm@77: ;;Matrix3f/IDENTITY Matrix3f/IDENTITY rlm@77: x-move Matrix3f/IDENTITY rlm@77: ) rlm@77: (.setCollisionBetweenLinkedBodys false) rlm@77: (.setLimit (* 1 (/ Math/PI 4)) ;; twist rlm@77: (* 1 (/ Math/PI 4)) ;; swing span in X-Y plane rlm@77: (* 0 (/ Math/PI 4)))) ;; swing span in Y-Z plane rlm@77: (world (nodify rlm@77: [obj-a obj-b]) rlm@77: (merge standard-debug-controls rlm@77: {"key-r" (fn [_ pressed?] (reset! move-up? pressed?)) rlm@77: "key-t" (fn [_ pressed?] (reset! move-down? pressed?)) rlm@77: "key-f" (fn [_ pressed?] (reset! move-left? pressed?)) rlm@77: "key-g" (fn [_ pressed?] (reset! move-right? pressed?)) rlm@77: "key-v" (fn [_ pressed?] (reset! roll-left? pressed?)) rlm@77: "key-b" (fn [_ pressed?] (reset! roll-right? pressed?))}) rlm@77: rlm@77: (fn [world] rlm@77: (enable-debug world) rlm@77: (set-gravity world Vector3f/ZERO) rlm@77: ) rlm@77: rlm@77: (fn [world _] rlm@77: rlm@77: (if @move-up? rlm@77: (.applyForce control-a rlm@77: (Vector3f. force 0 0) rlm@77: (Vector3f. 0 0 0))) rlm@77: (if @move-down? rlm@77: (.applyForce control-a rlm@77: (Vector3f. (- force) 0 0) rlm@77: (Vector3f. 0 0 0))) rlm@77: (if @move-left? rlm@77: (.applyForce control-a rlm@77: (Vector3f. 0 force 0) rlm@77: (Vector3f. 0 0 0))) rlm@77: (if @move-right? rlm@77: (.applyForce control-a rlm@77: (Vector3f. 0 (- force) 0) rlm@77: (Vector3f. 0 0 0))) rlm@77: rlm@77: (if @roll-left? rlm@77: (.applyForce control-a rlm@77: (Vector3f. 0 0 force) rlm@77: (Vector3f. 0 0 0))) rlm@77: (if @roll-right? rlm@77: (.applyForce control-a rlm@77: (Vector3f. 0 0 (- force)) rlm@77: (Vector3f. 0 0 0))) rlm@77: rlm@77: (if (zero? (rem (swap! timer inc) 100)) rlm@77: (.attachChild rlm@77: (.getRootNode world) rlm@77: (sphere 0.05 :color ColorRGBA/Yellow rlm@77: :physical? false :position rlm@77: (.getWorldTranslation obj-a))))) rlm@77: ) rlm@77: )) rlm@77: rlm@106: (defn test-joint [joint] rlm@106: (let [[origin top bottom floor] (world-setup joint) rlm@106: control (.getControl top RigidBodyControl) rlm@106: move-up? (atom false) rlm@106: move-down? (atom false) rlm@106: move-left? (atom false) rlm@106: move-right? (atom false) rlm@106: roll-left? (atom false) rlm@106: roll-right? (atom false) rlm@106: timer (atom 0)] rlm@106: rlm@106: (world rlm@106: (nodify [top bottom floor origin]) rlm@106: (merge standard-debug-controls rlm@106: {"key-r" (fn [_ pressed?] (reset! move-up? pressed?)) rlm@106: "key-t" (fn [_ pressed?] (reset! move-down? pressed?)) rlm@106: "key-f" (fn [_ pressed?] (reset! move-left? pressed?)) rlm@106: "key-g" (fn [_ pressed?] (reset! move-right? pressed?)) rlm@106: "key-v" (fn [_ pressed?] (reset! roll-left? pressed?)) rlm@106: "key-b" (fn [_ pressed?] (reset! roll-right? pressed?))}) rlm@106: rlm@106: (fn [world] rlm@106: (light-up-everything world) rlm@106: (enable-debug world) rlm@106: (set-gravity world (Vector3f. 0 0 0)) rlm@106: ) rlm@106: rlm@106: (fn [world _] rlm@106: (if (zero? (rem (swap! timer inc) 100)) rlm@106: (do rlm@106: ;; (println-repl @timer) rlm@106: (.attachChild (.getRootNode world) rlm@106: (sphere 0.05 :color ColorRGBA/Yellow rlm@106: :position (.getWorldTranslation top) rlm@106: :physical? false)) rlm@106: (.attachChild (.getRootNode world) rlm@106: (sphere 0.05 :color ColorRGBA/LightGray rlm@106: :position (.getWorldTranslation bottom) rlm@106: :physical? false)))) rlm@106: rlm@106: (if @move-up? rlm@106: (.applyTorque control rlm@106: (.mult (.getPhysicsRotation control) rlm@106: (Vector3f. 0 0 10)))) rlm@106: (if @move-down? rlm@106: (.applyTorque control rlm@106: (.mult (.getPhysicsRotation control) rlm@106: (Vector3f. 0 0 -10)))) rlm@106: (if @move-left? rlm@106: (.applyTorque control rlm@106: (.mult (.getPhysicsRotation control) rlm@106: (Vector3f. 0 10 0)))) rlm@106: (if @move-right? rlm@106: (.applyTorque control rlm@106: (.mult (.getPhysicsRotation control) rlm@106: (Vector3f. 0 -10 0)))) rlm@106: (if @roll-left? rlm@106: (.applyTorque control rlm@106: (.mult (.getPhysicsRotation control) rlm@106: (Vector3f. -1 0 0)))) rlm@106: (if @roll-right? rlm@106: (.applyTorque control rlm@106: (.mult (.getPhysicsRotation control) rlm@106: (Vector3f. 1 0 0)))))))) rlm@99: #+end_src rlm@192: rlm@99: rlm@99: * COMMENT generate source rlm@192: #+begin_src clojure :tangle ../src/cortex/integration.clj rlm@192: <> rlm@99: #+end_src rlm@99: rlm@99: rlm@94: rlm@94: