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@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@192: rlm@189: rlm@281: rlm@281: creature (doto (load-blender-model hand) rlm@281: (body!)) rlm@281: rlm@192: ;;;;;;;;;;;; Sensors/Effectors ;;;;;;;;;;;;;;;;;;;;;;;;;;;; rlm@185: touch (touch! creature) rlm@188: touch-display (view-touch) rlm@189: rlm@188: vision (vision! creature) rlm@188: vision-display (view-vision) rlm@189: rlm@189: hearing (hearing! creature) rlm@189: 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@143: (apply rlm@143: world rlm@143: (with-movement rlm@281: (.getChild creature "palm") rlm@143: ["key-r" "key-t" rlm@143: "key-f" "key-g" rlm@143: "key-v" "key-b"] rlm@143: [10 10 10 10 1 1] rlm@143: [(nodify [creature rlm@143: (box 10 2 10 :position (Vector3f. 0 -9 0) rlm@143: :color ColorRGBA/Gray :mass 0) rlm@192: me]) rlm@143: (merge standard-debug-controls rlm@143: {"key-return" rlm@143: (fn [_ value] rlm@143: (if value rlm@143: (do rlm@143: (println-repl "play-sound") rlm@148: (.play bell)))) rlm@148: "key-h" rlm@148: (fn [_ value] rlm@148: (if value rlm@191: (swap! muscle-exertion (partial + 20)))) rlm@191: "key-n" rlm@191: (fn [_ value] rlm@191: (if value rlm@192: (swap! muscle-exertion (fn [v] (- v 20)))))}) rlm@143: (fn [world] rlm@281: (.setTimer world (RatchetTimer. 60)) rlm@143: (light-up-everything world) rlm@143: (enable-debug world) rlm@169: (add-camera! world rlm@192: (add-eye! creature rlm@192: (.getChild rlm@192: (.getChild creature "eyes") "eye")) rlm@143: (comp (view-image) BufferedImage!)) rlm@281: (speed-up world)) rlm@143: (fn [world tpf] rlm@190: (prop-display (prop)) rlm@188: (touch-display (map #(% (.getRootNode world)) touch)) rlm@188: (vision-display (map #(% world) vision)) rlm@189: (hearing-display (map #(% world) hearing)) rlm@191: (muscle-display (map #(% @muscle-exertion) muscles)) rlm@143: (.setLocalTranslation me (.getLocation (.getCamera world))) rlm@281: (fix-display world))]))))) rlm@87: #+end_src rlm@83: 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: