Mercurial > cortex
comparison org/proprioception.org @ 175:0b9ae09eaec3
renamed functions in body
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 04 Feb 2012 06:47:07 -0700 |
parents | 136349ac6972 |
children | 2902aca33c6e |
comparison
equal
deleted
inserted
replaced
174:136349ac6972 | 175:0b9ae09eaec3 |
---|---|
15 automatically generate proprioceptive senses." | 15 automatically generate proprioceptive senses." |
16 (:use (cortex world util sense body)) | 16 (:use (cortex world util sense body)) |
17 (:use clojure.contrib.def) | 17 (:use clojure.contrib.def) |
18 (:import com.jme3.scene.Node) | 18 (:import com.jme3.scene.Node) |
19 (:import (com.jme3.math Vector3f Quaternion))) | 19 (:import (com.jme3.math Vector3f Quaternion))) |
20 | |
21 (defvar | |
22 ^{:arglists '([creature])} | |
23 joints | |
24 (sense-nodes "joints") | |
25 "Return the children of the creature's \"joints\" node.") | |
26 | 20 |
27 (defn right-handed? | 21 (defn right-handed? |
28 "true iff the three vectors form a right handed coordinate | 22 "true iff the three vectors form a right handed coordinate |
29 system. The three vectors do not have to be normalized or | 23 system. The three vectors do not have to be normalized or |
30 orthogonal." | 24 orthogonal." |
87 ;; extract the body's joints | 81 ;; extract the body's joints |
88 (let [senses (map (partial proprioception-fn creature) | 82 (let [senses (map (partial proprioception-fn creature) |
89 (joints creature))] | 83 (joints creature))] |
90 (fn [] | 84 (fn [] |
91 (map #(%) senses)))) | 85 (map #(%) senses)))) |
86 | |
87 | |
88 (import java.awt.image.BufferedImage) | |
89 | |
90 (defn draw-sprite [image sprite x y color ] | |
91 (dorun | |
92 (for [[u v] sprite] | |
93 (.setRGB image (+ u x) (+ v y) color)))) | |
94 | |
95 (defn view-angle | |
96 "create a debug view of an angle" | |
97 [color] | |
98 (let [image (BufferedImage. 50 50 BufferedImage/TYPE_INT_RGB) | |
99 previous (atom [25 25]) | |
100 sprite [[0 0] [0 1] | |
101 [0 -1] [-1 0] [1 0]]] | |
102 (fn [angle] | |
103 (let [angle (float angle)] | |
104 (let [position | |
105 [(+ 25 (int (* 20 (Math/cos angle)))) | |
106 (+ 25 (int (* -20 (Math/sin angle))))]] | |
107 (draw-sprite image sprite (@previous 0) (@previous 1) 0x000000) | |
108 (draw-sprite image sprite (position 0) (position 1) color) | |
109 (reset! previous position)) | |
110 image)))) | |
111 | |
112 (defn proprioception-debug-window | |
113 [] | |
114 (let [heading (view-angle 0xFF0000) | |
115 pitch (view-angle 0x00FF00) | |
116 roll (view-angle 0xFFFFFF) | |
117 v-heading (view-image) | |
118 v-pitch (view-image) | |
119 v-roll (view-image) | |
120 ] | |
121 (fn [prop-data] | |
122 (dorun | |
123 (map | |
124 (fn [[h p r]] | |
125 (v-heading (heading h)) | |
126 (v-pitch (pitch p)) | |
127 (v-roll (roll r))) | |
128 prop-data))))) | |
129 | |
92 #+end_src | 130 #+end_src |
93 | 131 |
94 * COMMENT generate source | 132 * COMMENT generate source |
95 #+begin_src clojure :tangle ../src/cortex/proprioception.clj | 133 #+begin_src clojure :tangle ../src/cortex/proprioception.clj |
96 <<proprioception>> | 134 <<proprioception>> |