changeset 197:16cbce075a0b

reorganizing for website
author Robert McIntyre <rlm@mit.edu>
date Sun, 05 Feb 2012 06:55:41 -0700
parents a165d4a86e75
children fc0bf33bded2
files org/ideas.org org/intro.org org/sense.org
diffstat 3 files changed, 95 insertions(+), 76 deletions(-) [+]
line wrap: on
line diff
     1.1 --- a/org/ideas.org	Sun Feb 05 00:21:23 2012 -0700
     1.2 +++ b/org/ideas.org	Sun Feb 05 06:55:41 2012 -0700
     1.3 @@ -95,6 +95,7 @@
     1.4         representation -- week
     1.5   - [ ] show sensor maps in HUD display? -- 4 days
     1.6   - [ ] show sensor maps in AWT display? -- 2 days
     1.7 + - [ ] add iteraterator constructs to Vector3f, Vector2f, etc.
     1.8  
     1.9  * refactoring objectives
    1.10   - [X] consistent, high-quality names
     2.1 --- a/org/intro.org	Sun Feb 05 00:21:23 2012 -0700
     2.2 +++ b/org/intro.org	Sun Feb 05 06:55:41 2012 -0700
     2.3 @@ -125,7 +125,7 @@
     2.4  ago, and as a result it has been ported and modified for many
     2.5  different reasons. This engine was famous for its advanced use of
     2.6  realistic shading and had decent and fast physics
     2.7 -simulation. Researchers at Princeton [[http://papers.cnl.salk.edu/PDFs/Intracelllular%20Dynamics%20of%20Virtual%20Place%20Cells%202011-4178.pdf][used this code]] to study spatial
     2.8 +simulation. Researchers at Princeton [[http://papers.cnl.salk.edu/PDFs/Intracelllular%20Dynamics%20of%20Virtual%20Place%20Cells%202011-4178.pdf][used this code]] ([[http://brainwindows.wordpress.com/2009/10/14/playing-quake-with-a-real-mouse/][video]]) to study spatial
     2.9  information encoding in the hippocampal cells of rats. Those
    2.10  researchers created a special Quake II level that simulated a maze,
    2.11  and added an interface where a mouse could run around inside a ball in
     3.1 --- a/org/sense.org	Sun Feb 05 00:21:23 2012 -0700
     3.2 +++ b/org/sense.org	Sun Feb 05 06:55:41 2012 -0700
     3.3 @@ -1,4 +1,4 @@
     3.4 -#+title: General sense/effector utilities
     3.5 +#+title: General Sense/Effector Utilities
     3.6  #+author: Robert McIntyre
     3.7  #+email: rlm@mit.edu
     3.8  #+description: sensory utilities
     3.9 @@ -6,8 +6,9 @@
    3.10  #+SETUPFILE: ../../aurellem/org/setup.org
    3.11  #+INCLUDE: ../../aurellem/org/level-0.org
    3.12  
    3.13 -#+name: sense
    3.14 -#+begin_src clojure 
    3.15 +* Namespace/Imports
    3.16 +#+name header
    3.17 +#+begin_src clojure
    3.18  (ns cortex.sense
    3.19    "Here are functions useful in the construction of two or more
    3.20     sensors/effectors."
    3.21 @@ -21,7 +22,11 @@
    3.22    (:import (com.jme3.scene Node Spatial))
    3.23    (:import com.jme3.scene.control.AbstractControl)
    3.24    (:import (com.jme3.math Quaternion Vector3f)))
    3.25 +#+end_src
    3.26  
    3.27 +* Blender Utilities
    3.28 +#+name: blender
    3.29 +#+begin_src clojure
    3.30  (defn meta-data
    3.31    "Get the meta-data for a node created with blender."
    3.32    [blender-node key]
    3.33 @@ -29,44 +34,30 @@
    3.34      (.findValue data key)
    3.35      nil))
    3.36  
    3.37 -(defn closest-node
    3.38 -  "Return the node in creature which is closest to the given node."
    3.39 -  [#^Node creature #^Node eye]
    3.40 -  (loop [radius (float 0.01)]
    3.41 -    (let [results (CollisionResults.)]
    3.42 -      (.collideWith
    3.43 -       creature
    3.44 -       (BoundingBox. (.getWorldTranslation eye)
    3.45 -                     radius radius radius)
    3.46 -       results)
    3.47 -      (if-let [target (first results)]
    3.48 -        (.getGeometry target)
    3.49 -        (recur (float (* 2 radius)))))))
    3.50 +(defn jme-to-blender
    3.51 +  "Convert from JME coordinates to Blender coordinates"
    3.52 +  [#^Vector3f in]
    3.53 +  (Vector3f. (.getX in)
    3.54 +             (- (.getZ in))
    3.55 +             (.getY in)))
    3.56  
    3.57 -(defn bind-sense
    3.58 -  "Bind the sense to the Spatial such that it will maintain its
    3.59 -   current position relative to the Spatial no matter how the spatial
    3.60 -   moves. 'sense can be either a Camera or Listener object."
    3.61 -  [#^Spatial obj sense]
    3.62 -  (let [sense-offset (.subtract (.getLocation sense)
    3.63 -                                (.getWorldTranslation obj))
    3.64 -        initial-sense-rotation (Quaternion. (.getRotation sense))
    3.65 -        base-anti-rotation (.inverse (.getWorldRotation obj))]
    3.66 -    (.addControl
    3.67 -     obj
    3.68 -     (proxy [AbstractControl] []
    3.69 -       (controlUpdate [tpf]
    3.70 -         (let [total-rotation
    3.71 -               (.mult base-anti-rotation (.getWorldRotation obj))]
    3.72 -           (.setLocation
    3.73 -            sense
    3.74 -            (.add
    3.75 -             (.mult total-rotation sense-offset)
    3.76 -             (.getWorldTranslation obj)))
    3.77 -           (.setRotation
    3.78 -            sense
    3.79 -            (.mult total-rotation initial-sense-rotation))))
    3.80 -       (controlRender [_ _])))))
    3.81 +(defn blender-to-jme
    3.82 +  "Convert from Blender coordinates to JME coordinates"
    3.83 +  [#^Vector3f in]
    3.84 +  (Vector3f. (.getX in)
    3.85 +             (.getZ in)
    3.86 +             (- (.getY in))))
    3.87 +#+end_src
    3.88 +
    3.89 +* Topology Related stuff
    3.90 +#+name: topology
    3.91 +#+begin_src clojure
    3.92 +(defn load-image
    3.93 +  "Load an image as a BufferedImage using the asset-manager system." 
    3.94 +  [asset-relative-path]
    3.95 +  (ImageToAwt/convert
    3.96 +   (.getImage (.loadTexture (asset-manager) asset-relative-path))
    3.97 +   false false 0))
    3.98  
    3.99  (def white 0xFFFFFF)
   3.100  
   3.101 @@ -171,6 +162,50 @@
   3.102                    squeezed))]
   3.103          relocated)))
   3.104  
   3.105 +#+end_src
   3.106 +
   3.107 +* Node level stuff
   3.108 +#+name: node
   3.109 +#+begin_src clojure
   3.110 +(defn closest-node
   3.111 +  "Return the node in creature which is closest to the given node."
   3.112 +  [#^Node creature #^Node eye]
   3.113 +  (loop [radius (float 0.01)]
   3.114 +    (let [results (CollisionResults.)]
   3.115 +      (.collideWith
   3.116 +       creature
   3.117 +       (BoundingBox. (.getWorldTranslation eye)
   3.118 +                     radius radius radius)
   3.119 +       results)
   3.120 +      (if-let [target (first results)]
   3.121 +        (.getGeometry target)
   3.122 +        (recur (float (* 2 radius)))))))
   3.123 +
   3.124 +(defn bind-sense
   3.125 +  "Bind the sense to the Spatial such that it will maintain its
   3.126 +   current position relative to the Spatial no matter how the spatial
   3.127 +   moves. 'sense can be either a Camera or Listener object."
   3.128 +  [#^Spatial obj sense]
   3.129 +  (let [sense-offset (.subtract (.getLocation sense)
   3.130 +                                (.getWorldTranslation obj))
   3.131 +        initial-sense-rotation (Quaternion. (.getRotation sense))
   3.132 +        base-anti-rotation (.inverse (.getWorldRotation obj))]
   3.133 +    (.addControl
   3.134 +     obj
   3.135 +     (proxy [AbstractControl] []
   3.136 +       (controlUpdate [tpf]
   3.137 +         (let [total-rotation
   3.138 +               (.mult base-anti-rotation (.getWorldRotation obj))]
   3.139 +           (.setLocation
   3.140 +            sense
   3.141 +            (.add
   3.142 +             (.mult total-rotation sense-offset)
   3.143 +             (.getWorldTranslation obj)))
   3.144 +           (.setRotation
   3.145 +            sense
   3.146 +            (.mult total-rotation initial-sense-rotation))))
   3.147 +       (controlRender [_ _])))))
   3.148 +
   3.149  (defn world-to-local
   3.150    "Convert the world coordinates into coordinates relative to the 
   3.151     object (i.e. local coordinates), taking into account the rotation
   3.152 @@ -193,40 +228,22 @@
   3.153      (if-let [sense-node (.getChild creature parent-name)]
   3.154        (seq (.getChildren sense-node))
   3.155        (do (println-repl "could not find" parent-name "node") []))))
   3.156 +#+end_src
   3.157  
   3.158 -(defn load-image
   3.159 -  "Load an image as a BufferedImage using the asset-manager system." 
   3.160 -  [asset-relative-path]
   3.161 -  (ImageToAwt/convert
   3.162 -   (.getImage (.loadTexture (asset-manager) asset-relative-path))
   3.163 -   false false 0))
   3.164 -
   3.165 -(defn jme-to-blender
   3.166 -  "Convert from JME coordinates to Blender coordinates"
   3.167 -  [#^Vector3f in]
   3.168 -  (Vector3f. (.getX in)
   3.169 -             (- (.getZ in))
   3.170 -             (.getY in)))
   3.171 -
   3.172 -(defn blender-to-jme
   3.173 -  "Convert from Blender coordinates to JME coordinates"
   3.174 -  [#^Vector3f in]
   3.175 -  (Vector3f. (.getX in)
   3.176 -             (.getZ in)
   3.177 -             (- (.getY in))))
   3.178 -
   3.179 -
   3.180 +* Viewing Senses
   3.181 +#+name view-senses
   3.182 +#+begin_src clojure
   3.183  (defn view-sense 
   3.184 -  "Take a function that produces a BufferedImage from some sense data
   3.185 -   and return a function which takes a list of sense and displays
   3.186 -   those images in multiple JFrames."
   3.187 +  "Take a kernel that produces a BufferedImage from some sense data
   3.188 +   and return a function which takes a list of sense data, uses the
   3.189 +   kernem to convert to images, and displays those images, each in
   3.190 +   its own JFrame."
   3.191    [sense-display-kernel]
   3.192 -  (let
   3.193 -      [windows (atom [])]
   3.194 +  (let [windows (atom [])]
   3.195      (fn [data]
   3.196        (if (> (count data) (count @windows))
   3.197 -        (reset! windows (map (fn [_] (view-image))
   3.198 -                             (range (count data)))))
   3.199 +        (reset! 
   3.200 +         windows (map (fn [_] (view-image)) (range (count data)))))
   3.201        (dorun
   3.202         (map
   3.203          (fn [display datum]
   3.204 @@ -234,18 +251,19 @@
   3.205          @windows data)))))
   3.206  
   3.207  (defn gray
   3.208 -  "Create a gray RGB pixel with R, G, and B set to 'num"
   3.209 +  "Create a gray RGB pixel with R, G, and B set to num. num must be
   3.210 +   between 0 and 255."
   3.211    [num]
   3.212    (+ num
   3.213       (bit-shift-left num 8)
   3.214       (bit-shift-left num 16)))
   3.215  #+end_src
   3.216  
   3.217 -#+results: sense
   3.218 -: #'cortex.sense/gray
   3.219 -
   3.220 -
   3.221  * COMMENT generate source
   3.222  #+begin_src clojure :tangle ../src/cortex/sense.clj
   3.223 -<<sense>>
   3.224 +<<header>>
   3.225 +<<blender>>
   3.226 +<<topology>>
   3.227 +<<node>>
   3.228 +<<view-senses>>
   3.229  #+end_src