# HG changeset patch # User Robert McIntyre # Date 1328450141 25200 # Node ID 16cbce075a0b43a18e084f88615689c3f52f3894 # Parent a165d4a86e75e29eb4064bdf9866b41695738567 reorganizing for website diff -r a165d4a86e75 -r 16cbce075a0b org/ideas.org --- a/org/ideas.org Sun Feb 05 00:21:23 2012 -0700 +++ b/org/ideas.org Sun Feb 05 06:55:41 2012 -0700 @@ -95,6 +95,7 @@ representation -- week - [ ] show sensor maps in HUD display? -- 4 days - [ ] show sensor maps in AWT display? -- 2 days + - [ ] add iteraterator constructs to Vector3f, Vector2f, etc. * refactoring objectives - [X] consistent, high-quality names diff -r a165d4a86e75 -r 16cbce075a0b org/intro.org --- a/org/intro.org Sun Feb 05 00:21:23 2012 -0700 +++ b/org/intro.org Sun Feb 05 06:55:41 2012 -0700 @@ -125,7 +125,7 @@ ago, and as a result it has been ported and modified for many different reasons. This engine was famous for its advanced use of realistic shading and had decent and fast physics -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 +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 information encoding in the hippocampal cells of rats. Those researchers created a special Quake II level that simulated a maze, and added an interface where a mouse could run around inside a ball in diff -r a165d4a86e75 -r 16cbce075a0b org/sense.org --- a/org/sense.org Sun Feb 05 00:21:23 2012 -0700 +++ b/org/sense.org Sun Feb 05 06:55:41 2012 -0700 @@ -1,4 +1,4 @@ -#+title: General sense/effector utilities +#+title: General Sense/Effector Utilities #+author: Robert McIntyre #+email: rlm@mit.edu #+description: sensory utilities @@ -6,8 +6,9 @@ #+SETUPFILE: ../../aurellem/org/setup.org #+INCLUDE: ../../aurellem/org/level-0.org -#+name: sense -#+begin_src clojure +* Namespace/Imports +#+name header +#+begin_src clojure (ns cortex.sense "Here are functions useful in the construction of two or more sensors/effectors." @@ -21,7 +22,11 @@ (:import (com.jme3.scene Node Spatial)) (:import com.jme3.scene.control.AbstractControl) (:import (com.jme3.math Quaternion Vector3f))) +#+end_src +* Blender Utilities +#+name: blender +#+begin_src clojure (defn meta-data "Get the meta-data for a node created with blender." [blender-node key] @@ -29,44 +34,30 @@ (.findValue data key) nil)) -(defn closest-node - "Return the node in creature which is closest to the given node." - [#^Node creature #^Node eye] - (loop [radius (float 0.01)] - (let [results (CollisionResults.)] - (.collideWith - creature - (BoundingBox. (.getWorldTranslation eye) - radius radius radius) - results) - (if-let [target (first results)] - (.getGeometry target) - (recur (float (* 2 radius))))))) +(defn jme-to-blender + "Convert from JME coordinates to Blender coordinates" + [#^Vector3f in] + (Vector3f. (.getX in) + (- (.getZ in)) + (.getY in))) -(defn bind-sense - "Bind the sense to the Spatial such that it will maintain its - current position relative to the Spatial no matter how the spatial - moves. 'sense can be either a Camera or Listener object." - [#^Spatial obj sense] - (let [sense-offset (.subtract (.getLocation sense) - (.getWorldTranslation obj)) - initial-sense-rotation (Quaternion. (.getRotation sense)) - base-anti-rotation (.inverse (.getWorldRotation obj))] - (.addControl - obj - (proxy [AbstractControl] [] - (controlUpdate [tpf] - (let [total-rotation - (.mult base-anti-rotation (.getWorldRotation obj))] - (.setLocation - sense - (.add - (.mult total-rotation sense-offset) - (.getWorldTranslation obj))) - (.setRotation - sense - (.mult total-rotation initial-sense-rotation)))) - (controlRender [_ _]))))) +(defn blender-to-jme + "Convert from Blender coordinates to JME coordinates" + [#^Vector3f in] + (Vector3f. (.getX in) + (.getZ in) + (- (.getY in)))) +#+end_src + +* Topology Related stuff +#+name: topology +#+begin_src clojure +(defn load-image + "Load an image as a BufferedImage using the asset-manager system." + [asset-relative-path] + (ImageToAwt/convert + (.getImage (.loadTexture (asset-manager) asset-relative-path)) + false false 0)) (def white 0xFFFFFF) @@ -171,6 +162,50 @@ squeezed))] relocated))) +#+end_src + +* Node level stuff +#+name: node +#+begin_src clojure +(defn closest-node + "Return the node in creature which is closest to the given node." + [#^Node creature #^Node eye] + (loop [radius (float 0.01)] + (let [results (CollisionResults.)] + (.collideWith + creature + (BoundingBox. (.getWorldTranslation eye) + radius radius radius) + results) + (if-let [target (first results)] + (.getGeometry target) + (recur (float (* 2 radius))))))) + +(defn bind-sense + "Bind the sense to the Spatial such that it will maintain its + current position relative to the Spatial no matter how the spatial + moves. 'sense can be either a Camera or Listener object." + [#^Spatial obj sense] + (let [sense-offset (.subtract (.getLocation sense) + (.getWorldTranslation obj)) + initial-sense-rotation (Quaternion. (.getRotation sense)) + base-anti-rotation (.inverse (.getWorldRotation obj))] + (.addControl + obj + (proxy [AbstractControl] [] + (controlUpdate [tpf] + (let [total-rotation + (.mult base-anti-rotation (.getWorldRotation obj))] + (.setLocation + sense + (.add + (.mult total-rotation sense-offset) + (.getWorldTranslation obj))) + (.setRotation + sense + (.mult total-rotation initial-sense-rotation)))) + (controlRender [_ _]))))) + (defn world-to-local "Convert the world coordinates into coordinates relative to the object (i.e. local coordinates), taking into account the rotation @@ -193,40 +228,22 @@ (if-let [sense-node (.getChild creature parent-name)] (seq (.getChildren sense-node)) (do (println-repl "could not find" parent-name "node") [])))) +#+end_src -(defn load-image - "Load an image as a BufferedImage using the asset-manager system." - [asset-relative-path] - (ImageToAwt/convert - (.getImage (.loadTexture (asset-manager) asset-relative-path)) - false false 0)) - -(defn jme-to-blender - "Convert from JME coordinates to Blender coordinates" - [#^Vector3f in] - (Vector3f. (.getX in) - (- (.getZ in)) - (.getY in))) - -(defn blender-to-jme - "Convert from Blender coordinates to JME coordinates" - [#^Vector3f in] - (Vector3f. (.getX in) - (.getZ in) - (- (.getY in)))) - - +* Viewing Senses +#+name view-senses +#+begin_src clojure (defn view-sense - "Take a function that produces a BufferedImage from some sense data - and return a function which takes a list of sense and displays - those images in multiple JFrames." + "Take a kernel that produces a BufferedImage from some sense data + and return a function which takes a list of sense data, uses the + kernem to convert to images, and displays those images, each in + its own JFrame." [sense-display-kernel] - (let - [windows (atom [])] + (let [windows (atom [])] (fn [data] (if (> (count data) (count @windows)) - (reset! windows (map (fn [_] (view-image)) - (range (count data))))) + (reset! + windows (map (fn [_] (view-image)) (range (count data))))) (dorun (map (fn [display datum] @@ -234,18 +251,19 @@ @windows data))))) (defn gray - "Create a gray RGB pixel with R, G, and B set to 'num" + "Create a gray RGB pixel with R, G, and B set to num. num must be + between 0 and 255." [num] (+ num (bit-shift-left num 8) (bit-shift-left num 16))) #+end_src -#+results: sense -: #'cortex.sense/gray - - * COMMENT generate source #+begin_src clojure :tangle ../src/cortex/sense.clj -<> +<
> +<> +<> +<> +<> #+end_src