Mercurial > cortex
changeset 192:deac7b708750
cleaned up test-creature.org and renamed to integreation.org.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 04 Feb 2012 11:29:45 -0700 |
parents | 66fbab414d45 |
children | 197294aff96e |
files | org/integration.org org/test-creature.org org/util.org |
diffstat | 3 files changed, 365 insertions(+), 464 deletions(-) [+] |
line wrap: on
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/org/integration.org Sat Feb 04 11:29:45 2012 -0700 1.3 @@ -0,0 +1,347 @@ 1.4 +#+title: First attempt at a creature! 1.5 +#+author: Robert McIntyre 1.6 +#+email: rlm@mit.edu 1.7 +#+description: 1.8 +#+keywords: simulation, jMonkeyEngine3, clojure 1.9 +#+SETUPFILE: ../../aurellem/org/setup.org 1.10 +#+INCLUDE: ../../aurellem/org/level-0.org 1.11 + 1.12 + 1.13 + 1.14 + 1.15 +* Intro 1.16 +So far, I've made the following senses -- 1.17 + - Vision 1.18 + - Hearing 1.19 + - Touch 1.20 + - Proprioception 1.21 + 1.22 +And one effector: 1.23 + - Movement 1.24 + 1.25 +However, the code so far has only enabled these senses, but has not 1.26 +actually implemented them. For example, there is still a lot of work 1.27 +to be done for vision. I need to be able to create an /eyeball/ in 1.28 +simulation that can be moved around and see the world from different 1.29 +angles. I also need to determine weather to use log-polar or cartesian 1.30 +for the visual input, and I need to determine how/wether to 1.31 +disceritise the visual input. 1.32 + 1.33 +I also want to be able to visualize both the sensors and the 1.34 +effectors in pretty pictures. This semi-retarted creature will be my 1.35 +first attempt at bringing everything together. 1.36 + 1.37 +* The creature's body 1.38 + 1.39 +Still going to do an eve-like body in blender, but due to problems 1.40 +importing the joints, etc into jMonkeyEngine3, I'm going to do all 1.41 +the connecting here in clojure code, using the names of the individual 1.42 +components and trial and error. Later, I'll maybe make some sort of 1.43 +creature-building modifications to blender that support whatever 1.44 +discritized senses I'm going to make. 1.45 + 1.46 +#+name: integration 1.47 +#+begin_src clojure 1.48 +(ns cortex.integration 1.49 + "let's play!" 1.50 + {:author "Robert McIntyre"} 1.51 + (:use (cortex world util body 1.52 + hearing touch vision sense proprioception movement)) 1.53 + (:import (com.jme3.math ColorRGBA Vector3f)) 1.54 + (:import com.jme3.audio.AudioNode) 1.55 + (:import com.aurellem.capture.RatchetTimer)) 1.56 + 1.57 +(def hand "Models/creature1/one.blend") 1.58 + 1.59 +(def worm "Models/creature1/try-again.blend") 1.60 + 1.61 +(defn test-creature [thing] 1.62 + (let [x-axis 1.63 + (box 1 0.01 0.01 :physical? false :color ColorRGBA/Red) 1.64 + y-axis 1.65 + (box 0.01 1 0.01 :physical? false :color ColorRGBA/Green) 1.66 + z-axis 1.67 + (box 0.01 0.01 1 :physical? false :color ColorRGBA/Blue) 1.68 + 1.69 + me (sphere 0.5 :color ColorRGBA/Blue :physical? false) 1.70 + bell (AudioNode. (asset-manager) 1.71 + "Sounds/pure.wav" false) 1.72 + 1.73 + fix-display 1.74 + (runonce (fn [world] 1.75 + (add-camera! world (.getCamera world) no-op))) 1.76 + creature (doto (load-blender-model thing) (body!)) 1.77 + 1.78 + ;;;;;;;;;;;; Sensors/Effectors ;;;;;;;;;;;;;;;;;;;;;;;;;;;; 1.79 + touch (touch! creature) 1.80 + touch-display (view-touch) 1.81 + 1.82 + vision (vision! creature) 1.83 + vision-display (view-vision) 1.84 + 1.85 + hearing (hearing! creature) 1.86 + hearing-display (view-hearing) 1.87 + 1.88 + prop (proprioception! creature) 1.89 + prop-display (view-proprioception) 1.90 + 1.91 + muscle-exertion (atom 0) 1.92 + muscles (movement! creature) 1.93 + muscle-display (view-movement)] 1.94 + 1.95 + (apply 1.96 + world 1.97 + (with-movement 1.98 + (.getChild creature "worm-21") 1.99 + ["key-r" "key-t" 1.100 + "key-f" "key-g" 1.101 + "key-v" "key-b"] 1.102 + [10 10 10 10 1 1] 1.103 + [(nodify [creature 1.104 + (box 10 2 10 :position (Vector3f. 0 -9 0) 1.105 + :color ColorRGBA/Gray :mass 0) 1.106 + x-axis y-axis z-axis 1.107 + me]) 1.108 + (merge standard-debug-controls 1.109 + {"key-return" 1.110 + (fn [_ value] 1.111 + (if value 1.112 + (do 1.113 + (println-repl "play-sound") 1.114 + (.play bell)))) 1.115 + "key-h" 1.116 + (fn [_ value] 1.117 + (if value 1.118 + (swap! muscle-exertion (partial + 20)))) 1.119 + "key-n" 1.120 + (fn [_ value] 1.121 + (if value 1.122 + (swap! muscle-exertion (fn [v] (- v 20)))))}) 1.123 + (fn [world] 1.124 + (light-up-everything world) 1.125 + (enable-debug world) 1.126 + (add-camera! world 1.127 + (add-eye! creature 1.128 + (.getChild 1.129 + (.getChild creature "eyes") "eye")) 1.130 + (comp (view-image) BufferedImage!)) 1.131 + (.setTimer world (RatchetTimer. 60)) 1.132 + (speed-up world) 1.133 + (set-gravity world (Vector3f. 0 0 0)) 1.134 + (comment 1.135 + (com.aurellem.capture.Capture/captureVideo 1.136 + world (file-str "/home/r/proj/ai-videos/hand")))) 1.137 + (fn [world tpf] 1.138 + (prop-display (prop)) 1.139 + (touch-display (map #(% (.getRootNode world)) touch)) 1.140 + (vision-display (map #(% world) vision)) 1.141 + (hearing-display (map #(% world) hearing)) 1.142 + (muscle-display (map #(% @muscle-exertion) muscles)) 1.143 + (.setLocalTranslation me (.getLocation (.getCamera world))) 1.144 + (fix-display world))])))) 1.145 +#+end_src 1.146 + 1.147 +#+results: body-1 1.148 +: #'cortex.silly/follow-test 1.149 + 1.150 + 1.151 +* COMMENT purgatory 1.152 +#+begin_src clojure 1.153 + 1.154 +(defn bullet-trans* [] 1.155 + (let [obj-a (box 1.5 0.5 0.5 :color ColorRGBA/Red 1.156 + :position (Vector3f. 5 0 0) 1.157 + :mass 90) 1.158 + obj-b (sphere 0.5 :color ColorRGBA/Blue 1.159 + :position (Vector3f. -5 0 0) 1.160 + :mass 0) 1.161 + control-a (.getControl obj-a RigidBodyControl) 1.162 + control-b (.getControl obj-b RigidBodyControl) 1.163 + move-up? (atom nil) 1.164 + move-down? (atom nil) 1.165 + move-left? (atom nil) 1.166 + move-right? (atom nil) 1.167 + roll-left? (atom nil) 1.168 + roll-right? (atom nil) 1.169 + force 100 1.170 + swivel 1.171 + (.toRotationMatrix 1.172 + (doto (Quaternion.) 1.173 + (.fromAngleAxis (/ Math/PI 2) 1.174 + Vector3f/UNIT_X))) 1.175 + x-move 1.176 + (doto (Matrix3f.) 1.177 + (.fromStartEndVectors Vector3f/UNIT_X 1.178 + (.normalize (Vector3f. 1 1 0)))) 1.179 + 1.180 + timer (atom 0)] 1.181 + (doto 1.182 + (ConeJoint. 1.183 + control-a control-b 1.184 + (Vector3f. -8 0 0) 1.185 + (Vector3f. 2 0 0) 1.186 + ;;swivel swivel 1.187 + ;;Matrix3f/IDENTITY Matrix3f/IDENTITY 1.188 + x-move Matrix3f/IDENTITY 1.189 + ) 1.190 + (.setCollisionBetweenLinkedBodys false) 1.191 + (.setLimit (* 1 (/ Math/PI 4)) ;; twist 1.192 + (* 1 (/ Math/PI 4)) ;; swing span in X-Y plane 1.193 + (* 0 (/ Math/PI 4)))) ;; swing span in Y-Z plane 1.194 + (world (nodify 1.195 + [obj-a obj-b]) 1.196 + (merge standard-debug-controls 1.197 + {"key-r" (fn [_ pressed?] (reset! move-up? pressed?)) 1.198 + "key-t" (fn [_ pressed?] (reset! move-down? pressed?)) 1.199 + "key-f" (fn [_ pressed?] (reset! move-left? pressed?)) 1.200 + "key-g" (fn [_ pressed?] (reset! move-right? pressed?)) 1.201 + "key-v" (fn [_ pressed?] (reset! roll-left? pressed?)) 1.202 + "key-b" (fn [_ pressed?] (reset! roll-right? pressed?))}) 1.203 + 1.204 + (fn [world] 1.205 + (enable-debug world) 1.206 + (set-gravity world Vector3f/ZERO) 1.207 + ) 1.208 + 1.209 + (fn [world _] 1.210 + 1.211 + (if @move-up? 1.212 + (.applyForce control-a 1.213 + (Vector3f. force 0 0) 1.214 + (Vector3f. 0 0 0))) 1.215 + (if @move-down? 1.216 + (.applyForce control-a 1.217 + (Vector3f. (- force) 0 0) 1.218 + (Vector3f. 0 0 0))) 1.219 + (if @move-left? 1.220 + (.applyForce control-a 1.221 + (Vector3f. 0 force 0) 1.222 + (Vector3f. 0 0 0))) 1.223 + (if @move-right? 1.224 + (.applyForce control-a 1.225 + (Vector3f. 0 (- force) 0) 1.226 + (Vector3f. 0 0 0))) 1.227 + 1.228 + (if @roll-left? 1.229 + (.applyForce control-a 1.230 + (Vector3f. 0 0 force) 1.231 + (Vector3f. 0 0 0))) 1.232 + (if @roll-right? 1.233 + (.applyForce control-a 1.234 + (Vector3f. 0 0 (- force)) 1.235 + (Vector3f. 0 0 0))) 1.236 + 1.237 + (if (zero? (rem (swap! timer inc) 100)) 1.238 + (.attachChild 1.239 + (.getRootNode world) 1.240 + (sphere 0.05 :color ColorRGBA/Yellow 1.241 + :physical? false :position 1.242 + (.getWorldTranslation obj-a))))) 1.243 + ) 1.244 + )) 1.245 + 1.246 +(defn test-joint [joint] 1.247 + (let [[origin top bottom floor] (world-setup joint) 1.248 + control (.getControl top RigidBodyControl) 1.249 + move-up? (atom false) 1.250 + move-down? (atom false) 1.251 + move-left? (atom false) 1.252 + move-right? (atom false) 1.253 + roll-left? (atom false) 1.254 + roll-right? (atom false) 1.255 + timer (atom 0)] 1.256 + 1.257 + (world 1.258 + (nodify [top bottom floor origin]) 1.259 + (merge standard-debug-controls 1.260 + {"key-r" (fn [_ pressed?] (reset! move-up? pressed?)) 1.261 + "key-t" (fn [_ pressed?] (reset! move-down? pressed?)) 1.262 + "key-f" (fn [_ pressed?] (reset! move-left? pressed?)) 1.263 + "key-g" (fn [_ pressed?] (reset! move-right? pressed?)) 1.264 + "key-v" (fn [_ pressed?] (reset! roll-left? pressed?)) 1.265 + "key-b" (fn [_ pressed?] (reset! roll-right? pressed?))}) 1.266 + 1.267 + (fn [world] 1.268 + (light-up-everything world) 1.269 + (enable-debug world) 1.270 + (set-gravity world (Vector3f. 0 0 0)) 1.271 + ) 1.272 + 1.273 + (fn [world _] 1.274 + (if (zero? (rem (swap! timer inc) 100)) 1.275 + (do 1.276 + ;; (println-repl @timer) 1.277 + (.attachChild (.getRootNode world) 1.278 + (sphere 0.05 :color ColorRGBA/Yellow 1.279 + :position (.getWorldTranslation top) 1.280 + :physical? false)) 1.281 + (.attachChild (.getRootNode world) 1.282 + (sphere 0.05 :color ColorRGBA/LightGray 1.283 + :position (.getWorldTranslation bottom) 1.284 + :physical? false)))) 1.285 + 1.286 + (if @move-up? 1.287 + (.applyTorque control 1.288 + (.mult (.getPhysicsRotation control) 1.289 + (Vector3f. 0 0 10)))) 1.290 + (if @move-down? 1.291 + (.applyTorque control 1.292 + (.mult (.getPhysicsRotation control) 1.293 + (Vector3f. 0 0 -10)))) 1.294 + (if @move-left? 1.295 + (.applyTorque control 1.296 + (.mult (.getPhysicsRotation control) 1.297 + (Vector3f. 0 10 0)))) 1.298 + (if @move-right? 1.299 + (.applyTorque control 1.300 + (.mult (.getPhysicsRotation control) 1.301 + (Vector3f. 0 -10 0)))) 1.302 + (if @roll-left? 1.303 + (.applyTorque control 1.304 + (.mult (.getPhysicsRotation control) 1.305 + (Vector3f. -1 0 0)))) 1.306 + (if @roll-right? 1.307 + (.applyTorque control 1.308 + (.mult (.getPhysicsRotation control) 1.309 + (Vector3f. 1 0 0)))))))) 1.310 + 1.311 +(defn follow-test 1.312 + "Show a camera that stays in the same relative position to a blue cube." 1.313 + [] 1.314 + (let [camera-pos (Vector3f. 0 30 0) 1.315 + rock (box 1 1 1 :color ColorRGBA/Blue 1.316 + :position (Vector3f. 0 10 0) 1.317 + :mass 30 1.318 + ) 1.319 + rot (.getWorldRotation rock) 1.320 + 1.321 + table (box 3 1 10 :color ColorRGBA/Gray :mass 0 1.322 + :position (Vector3f. 0 -3 0))] 1.323 + 1.324 + (world 1.325 + (nodify [rock table]) 1.326 + standard-debug-controls 1.327 + (fn [world] 1.328 + (let 1.329 + [cam (doto (.clone (.getCamera world)) 1.330 + (.setLocation camera-pos) 1.331 + (.lookAt Vector3f/ZERO 1.332 + Vector3f/UNIT_X))] 1.333 + (bind-sense rock cam) 1.334 + 1.335 + (.setTimer world (RatchetTimer. 60)) 1.336 + (add-camera! world cam (comp (view-image) BufferedImage!)) 1.337 + (add-camera! world (.getCamera world) no-op)) 1.338 + ) 1.339 + (fn [_ _] (println-repl rot))))) 1.340 +#+end_src 1.341 + 1.342 + 1.343 +* COMMENT generate source 1.344 +#+begin_src clojure :tangle ../src/cortex/integration.clj 1.345 +<<integration>> 1.346 +#+end_src 1.347 + 1.348 + 1.349 + 1.350 +
2.1 --- a/org/test-creature.org Sat Feb 04 11:02:19 2012 -0700 2.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 2.3 @@ -1,454 +0,0 @@ 2.4 -#+title: First attempt at a creature! 2.5 -#+author: Robert McIntyre 2.6 -#+email: rlm@mit.edu 2.7 -#+description: 2.8 -#+keywords: simulation, jMonkeyEngine3, clojure 2.9 -#+SETUPFILE: ../../aurellem/org/setup.org 2.10 -#+INCLUDE: ../../aurellem/org/level-0.org 2.11 - 2.12 - 2.13 - 2.14 - 2.15 -* Intro 2.16 -So far, I've made the following senses -- 2.17 - - Vision 2.18 - - Hearing 2.19 - - Touch 2.20 - - Proprioception 2.21 - 2.22 -And one effector: 2.23 - - Movement 2.24 - 2.25 -However, the code so far has only enabled these senses, but has not 2.26 -actually implemented them. For example, there is still a lot of work 2.27 -to be done for vision. I need to be able to create an /eyeball/ in 2.28 -simulation that can be moved around and see the world from different 2.29 -angles. I also need to determine weather to use log-polar or cartesian 2.30 -for the visual input, and I need to determine how/wether to 2.31 -disceritise the visual input. 2.32 - 2.33 -I also want to be able to visualize both the sensors and the 2.34 -effectors in pretty pictures. This semi-retarted creature will be my 2.35 -first attempt at bringing everything together. 2.36 - 2.37 -* The creature's body 2.38 - 2.39 -Still going to do an eve-like body in blender, but due to problems 2.40 -importing the joints, etc into jMonkeyEngine3, I'm going to do all 2.41 -the connecting here in clojure code, using the names of the individual 2.42 -components and trial and error. Later, I'll maybe make some sort of 2.43 -creature-building modifications to blender that support whatever 2.44 -discritized senses I'm going to make. 2.45 - 2.46 -#+name: body-1 2.47 -#+begin_src clojure 2.48 -(ns cortex.silly 2.49 - "let's play!" 2.50 - {:author "Robert McIntyre"}) 2.51 - 2.52 -;; TODO remove this! 2.53 -(require 'cortex.import) 2.54 -(cortex.import/mega-import-jme3) 2.55 -(use '(cortex world util body hearing touch vision sense 2.56 - proprioception movement)) 2.57 - 2.58 -(rlm.rlm-commands/help) 2.59 -(import java.awt.image.BufferedImage) 2.60 -(import javax.swing.JPanel) 2.61 -(import javax.swing.SwingUtilities) 2.62 -(import java.awt.Dimension) 2.63 -(import javax.swing.JFrame) 2.64 -(import java.awt.Dimension) 2.65 -(import com.aurellem.capture.RatchetTimer) 2.66 - 2.67 -(use 'clojure.contrib.def) 2.68 - 2.69 -(defn load-blender-model 2.70 - "Load a .blend file using an asset folder relative path." 2.71 - [^String model] 2.72 - (.loadModel 2.73 - (doto (asset-manager) 2.74 - (.registerLoader BlenderModelLoader (into-array String ["blend"]))) 2.75 - model)) 2.76 - 2.77 -(def hand "Models/creature1/one.blend") 2.78 - 2.79 -(def worm "Models/creature1/try-again.blend") 2.80 - 2.81 -(defn worm-model [] (load-blender-model worm)) 2.82 - 2.83 -(defn x-ray [#^ColorRGBA color] 2.84 - (doto (Material. (asset-manager) 2.85 - "Common/MatDefs/Misc/Unshaded.j3md") 2.86 - (.setColor "Color" color) 2.87 - (-> (.getAdditionalRenderState) 2.88 - (.setDepthTest false)))) 2.89 - 2.90 -(defn colorful [] 2.91 - (.getChild (worm-model) "worm-21")) 2.92 - 2.93 -(import jme3tools.converters.ImageToAwt) 2.94 - 2.95 -(import ij.ImagePlus) 2.96 - 2.97 - 2.98 - 2.99 -(defn test-eye [] 2.100 - (.getChild 2.101 - (.getChild (worm-model) "eyes") 2.102 - "eye")) 2.103 - 2.104 - 2.105 - 2.106 -;; lower level --- nodes 2.107 -;; closest-node "parse/compile-x" -> makes organ, which is spatial, fn pair 2.108 - 2.109 -;; higher level -- organs 2.110 -;; 2.111 - 2.112 -;; higher level --- sense/effector 2.113 -;; these are the functions that provide world i/o, chinese-room style 2.114 - 2.115 -(defn debug-hearing-window 2.116 - "view audio data" 2.117 - [height] 2.118 - (let [vi (view-image)] 2.119 - (fn [[coords sensor-data]] 2.120 - (let [image (BufferedImage. (count coords) height 2.121 - BufferedImage/TYPE_INT_RGB)] 2.122 - (dorun 2.123 - (for [x (range (count coords))] 2.124 - (dorun 2.125 - (for [y (range height)] 2.126 - (let [raw-sensor (sensor-data x)] 2.127 - (.setRGB image x y (gray raw-sensor))))))) 2.128 - 2.129 - (vi image))))) 2.130 - 2.131 -(defn test-creature [thing] 2.132 - (let [x-axis 2.133 - (box 1 0.01 0.01 :physical? false :color ColorRGBA/Red) 2.134 - y-axis 2.135 - (box 0.01 1 0.01 :physical? false :color ColorRGBA/Green) 2.136 - z-axis 2.137 - (box 0.01 0.01 1 :physical? false :color ColorRGBA/Blue) 2.138 - 2.139 - creature (doto (load-blender-model thing) (body!)) 2.140 - 2.141 - touch (touch! creature) 2.142 - touch-display (view-touch) 2.143 - 2.144 - vision (vision! creature) 2.145 - vision-display (view-vision) 2.146 - 2.147 - hearing (hearing! creature) 2.148 - hearing-display (view-hearing) 2.149 - 2.150 - prop (proprioception! creature) 2.151 - prop-display (view-proprioception) 2.152 - 2.153 - muscle-exertion (atom 0) 2.154 - muscles (movement! creature) 2.155 - muscle-display (view-movement) 2.156 - 2.157 - me (sphere 0.5 :color ColorRGBA/Blue :physical? false) 2.158 - bell (AudioNode. (asset-manager) 2.159 - "Sounds/pure.wav" false) 2.160 - 2.161 - fix-display (runonce 2.162 - (fn [world] (add-camera! world (.getCamera world) no-op))) 2.163 - ] 2.164 - 2.165 - 2.166 - (apply 2.167 - world 2.168 - (with-movement 2.169 - (.getChild creature "worm-21") 2.170 - ["key-r" "key-t" 2.171 - "key-f" "key-g" 2.172 - "key-v" "key-b"] 2.173 - [10 10 10 10 1 1] 2.174 - [(nodify [creature 2.175 - (box 10 2 10 :position (Vector3f. 0 -9 0) 2.176 - :color ColorRGBA/Gray :mass 0) 2.177 - x-axis y-axis z-axis 2.178 - me 2.179 - ]) 2.180 - (merge standard-debug-controls 2.181 - {"key-return" 2.182 - (fn [_ value] 2.183 - (if value 2.184 - (do 2.185 - (println-repl "play-sound") 2.186 - (.play bell)))) 2.187 - "key-h" 2.188 - (fn [_ value] 2.189 - (if value 2.190 - (swap! muscle-exertion (partial + 20)))) 2.191 - "key-n" 2.192 - (fn [_ value] 2.193 - (if value 2.194 - (swap! muscle-exertion (fn [v] (- v 20))))) 2.195 - 2.196 - }) 2.197 - (fn [world] 2.198 - (light-up-everything world) 2.199 - (enable-debug world) 2.200 - ;;(dorun (map #(% world) init-vision-fns)) 2.201 - ;;(dorun (map #(% world) init-hearing-fns)) 2.202 - 2.203 - (add-camera! world 2.204 - (add-eye! creature (test-eye)) 2.205 - (comp (view-image) BufferedImage!)) 2.206 - 2.207 - 2.208 - ;;(set-gravity world (Vector3f. 0 0 0)) 2.209 - ;;(com.aurellem.capture.Capture/captureVideo 2.210 - ;; world (file-str "/home/r/proj/ai-videos/hand")) 2.211 - ;;(.setTimer world (RatchetTimer. 60)) 2.212 - (speed-up world) 2.213 - (set-gravity world (Vector3f. 0 0 0)) 2.214 - ) 2.215 - (fn [world tpf] 2.216 - ;;(dorun 2.217 - ;; (map #(%1 %2) touch-nerves (repeat (.getRootNode world)))) 2.218 - 2.219 - (prop-display (prop)) 2.220 - 2.221 - (touch-display (map #(% (.getRootNode world)) touch)) 2.222 - 2.223 - (vision-display (map #(% world) vision)) 2.224 - 2.225 - (hearing-display (map #(% world) hearing)) 2.226 - 2.227 - (muscle-display (map #(% @muscle-exertion) muscles)) 2.228 - 2.229 - ;;(println-repl (vision-data)) 2.230 - (.setLocalTranslation me (.getLocation (.getCamera world))) 2.231 - (fix-display world) 2.232 - 2.233 - )] 2.234 - ;;(let [timer (atom 0)] 2.235 - ;; (fn [_ _] 2.236 - ;; (swap! timer inc) 2.237 - ;; (if (= (rem @timer 60) 0) 2.238 - ;; (println-repl (float (/ @timer 60)))))) 2.239 - )))) 2.240 - 2.241 - 2.242 - 2.243 -;; the camera will stay in its initial position/rotation with relation 2.244 -;; to the spatial. 2.245 - 2.246 - 2.247 -;;dylan (defn follow-sense, adjoin-sense, attach-stimuli, 2.248 -;;anchor-qualia, augment-organ, with-organ 2.249 - 2.250 -(defn follow-test 2.251 - "show a camera that stays in the same relative position to a blue cube." 2.252 - [] 2.253 - (let [camera-pos (Vector3f. 0 30 0) 2.254 - rock (box 1 1 1 :color ColorRGBA/Blue 2.255 - :position (Vector3f. 0 10 0) 2.256 - :mass 30 2.257 - ) 2.258 - rot (.getWorldRotation rock) 2.259 - 2.260 - table (box 3 1 10 :color ColorRGBA/Gray :mass 0 2.261 - :position (Vector3f. 0 -3 0))] 2.262 - 2.263 - (world 2.264 - (nodify [rock table]) 2.265 - standard-debug-controls 2.266 - (fn [world] 2.267 - (let 2.268 - [cam (doto (.clone (.getCamera world)) 2.269 - (.setLocation camera-pos) 2.270 - (.lookAt Vector3f/ZERO 2.271 - Vector3f/UNIT_X))] 2.272 - (bind-sense rock cam) 2.273 - 2.274 - (.setTimer world (RatchetTimer. 60)) 2.275 - (add-camera! world cam (comp (view-image) BufferedImage!)) 2.276 - (add-camera! world (.getCamera world) no-op)) 2.277 - ) 2.278 - (fn [_ _] (println-repl rot))))) 2.279 - 2.280 - 2.281 - 2.282 -#+end_src 2.283 - 2.284 -#+results: body-1 2.285 -: #'cortex.silly/follow-test 2.286 - 2.287 - 2.288 -* COMMENT purgatory 2.289 -#+begin_src clojure 2.290 - 2.291 -(defn bullet-trans* [] 2.292 - (let [obj-a (box 1.5 0.5 0.5 :color ColorRGBA/Red 2.293 - :position (Vector3f. 5 0 0) 2.294 - :mass 90) 2.295 - obj-b (sphere 0.5 :color ColorRGBA/Blue 2.296 - :position (Vector3f. -5 0 0) 2.297 - :mass 0) 2.298 - control-a (.getControl obj-a RigidBodyControl) 2.299 - control-b (.getControl obj-b RigidBodyControl) 2.300 - move-up? (atom nil) 2.301 - move-down? (atom nil) 2.302 - move-left? (atom nil) 2.303 - move-right? (atom nil) 2.304 - roll-left? (atom nil) 2.305 - roll-right? (atom nil) 2.306 - force 100 2.307 - swivel 2.308 - (.toRotationMatrix 2.309 - (doto (Quaternion.) 2.310 - (.fromAngleAxis (/ Math/PI 2) 2.311 - Vector3f/UNIT_X))) 2.312 - x-move 2.313 - (doto (Matrix3f.) 2.314 - (.fromStartEndVectors Vector3f/UNIT_X 2.315 - (.normalize (Vector3f. 1 1 0)))) 2.316 - 2.317 - timer (atom 0)] 2.318 - (doto 2.319 - (ConeJoint. 2.320 - control-a control-b 2.321 - (Vector3f. -8 0 0) 2.322 - (Vector3f. 2 0 0) 2.323 - ;;swivel swivel 2.324 - ;;Matrix3f/IDENTITY Matrix3f/IDENTITY 2.325 - x-move Matrix3f/IDENTITY 2.326 - ) 2.327 - (.setCollisionBetweenLinkedBodys false) 2.328 - (.setLimit (* 1 (/ Math/PI 4)) ;; twist 2.329 - (* 1 (/ Math/PI 4)) ;; swing span in X-Y plane 2.330 - (* 0 (/ Math/PI 4)))) ;; swing span in Y-Z plane 2.331 - (world (nodify 2.332 - [obj-a obj-b]) 2.333 - (merge standard-debug-controls 2.334 - {"key-r" (fn [_ pressed?] (reset! move-up? pressed?)) 2.335 - "key-t" (fn [_ pressed?] (reset! move-down? pressed?)) 2.336 - "key-f" (fn [_ pressed?] (reset! move-left? pressed?)) 2.337 - "key-g" (fn [_ pressed?] (reset! move-right? pressed?)) 2.338 - "key-v" (fn [_ pressed?] (reset! roll-left? pressed?)) 2.339 - "key-b" (fn [_ pressed?] (reset! roll-right? pressed?))}) 2.340 - 2.341 - (fn [world] 2.342 - (enable-debug world) 2.343 - (set-gravity world Vector3f/ZERO) 2.344 - ) 2.345 - 2.346 - (fn [world _] 2.347 - 2.348 - (if @move-up? 2.349 - (.applyForce control-a 2.350 - (Vector3f. force 0 0) 2.351 - (Vector3f. 0 0 0))) 2.352 - (if @move-down? 2.353 - (.applyForce control-a 2.354 - (Vector3f. (- force) 0 0) 2.355 - (Vector3f. 0 0 0))) 2.356 - (if @move-left? 2.357 - (.applyForce control-a 2.358 - (Vector3f. 0 force 0) 2.359 - (Vector3f. 0 0 0))) 2.360 - (if @move-right? 2.361 - (.applyForce control-a 2.362 - (Vector3f. 0 (- force) 0) 2.363 - (Vector3f. 0 0 0))) 2.364 - 2.365 - (if @roll-left? 2.366 - (.applyForce control-a 2.367 - (Vector3f. 0 0 force) 2.368 - (Vector3f. 0 0 0))) 2.369 - (if @roll-right? 2.370 - (.applyForce control-a 2.371 - (Vector3f. 0 0 (- force)) 2.372 - (Vector3f. 0 0 0))) 2.373 - 2.374 - (if (zero? (rem (swap! timer inc) 100)) 2.375 - (.attachChild 2.376 - (.getRootNode world) 2.377 - (sphere 0.05 :color ColorRGBA/Yellow 2.378 - :physical? false :position 2.379 - (.getWorldTranslation obj-a))))) 2.380 - ) 2.381 - )) 2.382 - 2.383 -(defn test-joint [joint] 2.384 - (let [[origin top bottom floor] (world-setup joint) 2.385 - control (.getControl top RigidBodyControl) 2.386 - move-up? (atom false) 2.387 - move-down? (atom false) 2.388 - move-left? (atom false) 2.389 - move-right? (atom false) 2.390 - roll-left? (atom false) 2.391 - roll-right? (atom false) 2.392 - timer (atom 0)] 2.393 - 2.394 - (world 2.395 - (nodify [top bottom floor origin]) 2.396 - (merge standard-debug-controls 2.397 - {"key-r" (fn [_ pressed?] (reset! move-up? pressed?)) 2.398 - "key-t" (fn [_ pressed?] (reset! move-down? pressed?)) 2.399 - "key-f" (fn [_ pressed?] (reset! move-left? pressed?)) 2.400 - "key-g" (fn [_ pressed?] (reset! move-right? pressed?)) 2.401 - "key-v" (fn [_ pressed?] (reset! roll-left? pressed?)) 2.402 - "key-b" (fn [_ pressed?] (reset! roll-right? pressed?))}) 2.403 - 2.404 - (fn [world] 2.405 - (light-up-everything world) 2.406 - (enable-debug world) 2.407 - (set-gravity world (Vector3f. 0 0 0)) 2.408 - ) 2.409 - 2.410 - (fn [world _] 2.411 - (if (zero? (rem (swap! timer inc) 100)) 2.412 - (do 2.413 - ;; (println-repl @timer) 2.414 - (.attachChild (.getRootNode world) 2.415 - (sphere 0.05 :color ColorRGBA/Yellow 2.416 - :position (.getWorldTranslation top) 2.417 - :physical? false)) 2.418 - (.attachChild (.getRootNode world) 2.419 - (sphere 0.05 :color ColorRGBA/LightGray 2.420 - :position (.getWorldTranslation bottom) 2.421 - :physical? false)))) 2.422 - 2.423 - (if @move-up? 2.424 - (.applyTorque control 2.425 - (.mult (.getPhysicsRotation control) 2.426 - (Vector3f. 0 0 10)))) 2.427 - (if @move-down? 2.428 - (.applyTorque control 2.429 - (.mult (.getPhysicsRotation control) 2.430 - (Vector3f. 0 0 -10)))) 2.431 - (if @move-left? 2.432 - (.applyTorque control 2.433 - (.mult (.getPhysicsRotation control) 2.434 - (Vector3f. 0 10 0)))) 2.435 - (if @move-right? 2.436 - (.applyTorque control 2.437 - (.mult (.getPhysicsRotation control) 2.438 - (Vector3f. 0 -10 0)))) 2.439 - (if @roll-left? 2.440 - (.applyTorque control 2.441 - (.mult (.getPhysicsRotation control) 2.442 - (Vector3f. -1 0 0)))) 2.443 - (if @roll-right? 2.444 - (.applyTorque control 2.445 - (.mult (.getPhysicsRotation control) 2.446 - (Vector3f. 1 0 0)))))))) 2.447 -#+end_src 2.448 - 2.449 - 2.450 -* COMMENT generate source 2.451 -#+begin_src clojure :tangle ../src/cortex/silly.clj 2.452 -<<body-1>> 2.453 -#+end_src 2.454 - 2.455 - 2.456 - 2.457 -
3.1 --- a/org/util.org Sat Feb 04 11:02:19 2012 -0700 3.2 +++ b/org/util.org Sat Feb 04 11:29:45 2012 -0700 3.3 @@ -102,7 +102,7 @@ 3.4 (:import javax.swing.JPanel) 3.5 (:import javax.swing.JFrame) 3.6 (:import javax.swing.SwingUtilities) 3.7 - 3.8 + (:import com.jme3.scene.plugins.blender.BlenderModelLoader) 3.9 (:import (java.util.logging Level Logger))) 3.10 3.11 (defvar println-repl 3.12 @@ -318,15 +318,15 @@ 3.13 :shape (Sphere. 32 32 (float r)))))) 3.14 ([] (sphere 0.5))) 3.15 3.16 -(defn green-x-ray 3.17 - "A usefull material for debuging -- it can be seen no matter what 3.18 - object occuldes it." 3.19 - [] 3.20 - (doto (Material. (asset-manager) 3.21 - "Common/MatDefs/Misc/Unshaded.j3md") 3.22 - (.setColor "Color" ColorRGBA/Green) 3.23 - (-> (.getAdditionalRenderState) 3.24 - (.setDepthTest false)))) 3.25 +(defn x-ray 3.26 + "A usefull material for debuging -- it can be seen no matter what 3.27 + object occuldes it." 3.28 + [#^ColorRGBA color] 3.29 + (doto (Material. (asset-manager) 3.30 + "Common/MatDefs/Misc/Unshaded.j3md") 3.31 + (.setColor "Color" color) 3.32 + (-> (.getAdditionalRenderState) 3.33 + (.setDepthTest false)))) 3.34 3.35 (defn node-seq 3.36 "Take a node and return a seq of all its children 3.37 @@ -344,6 +344,14 @@ 3.38 node)) 3.39 ([children] (nodify "" children))) 3.40 3.41 +(defn load-blender-model 3.42 + "Load a .blend file using an asset folder relative path." 3.43 + [^String model] 3.44 + (.loadModel 3.45 + (doto (asset-manager) 3.46 + (.registerLoader BlenderModelLoader 3.47 + (into-array String ["blend"]))) model)) 3.48 + 3.49 3.50 #+end_src 3.51