# HG changeset patch # User Robert McIntyre # Date 1328376371 25200 # Node ID 2902aca33c6e567d8849169620908f00f53889ef # Parent facc2ef3fe5caf4506f942a7cbaa4928978f0106 added proprioception debug view. diff -r facc2ef3fe5c -r 2902aca33c6e org/proprioception.org --- a/org/proprioception.org Sat Feb 04 10:13:15 2012 -0700 +++ b/org/proprioception.org Sat Feb 04 10:26:11 2012 -0700 @@ -16,6 +16,7 @@ (:use (cortex world util sense body)) (:use clojure.contrib.def) (:import com.jme3.scene.Node) + (:import java.awt.image.BufferedImage) (:import (com.jme3.math Vector3f Quaternion))) (defn right-handed? @@ -85,13 +86,12 @@ (map #(%) senses)))) -(import java.awt.image.BufferedImage) - (defn draw-sprite [image sprite x y color ] (dorun (for [[u v] sprite] (.setRGB image (+ u x) (+ v y) color)))) + (defn view-angle "create a debug view of an angle" [color] @@ -109,23 +109,42 @@ (reset! previous position)) image)))) -(defn proprioception-debug-window + +(defn proprioception-display-kernel + "Display proprioception angles in a BufferedImage" + [[h p r]] + (let [image (BufferedImage. 50 50 BufferedImage/TYPE_INT_RGB) + previous-heading (atom [25 25]) + previous-pitch (atom [25 25]) + previous-roll (atom [25 25]) + + heading-sprite [[0 0] [0 1] [0 -1] [-1 0] [1 0]] + pitch-sprite [[0 0] [0 1] [0 -1] [-1 0] [1 0]] + roll-sprite [[0 0] [0 1] [0 -1] [-1 0] [1 0]] + draw-angle + (fn [angle sprite previous color] + (let [angle (float angle)] + (let [position + [(+ 25 (int (* 20 (Math/cos angle)))) + (+ 25 (int (* -20 (Math/sin angle))))]] + (draw-sprite image sprite (@previous 0) (@previous 1) 0x000000) + (draw-sprite image sprite (position 0) (position 1) color) + (reset! previous position)) + image))] + (dorun (map draw-angle + [h p r] + [heading-sprite pitch-sprite roll-sprite] + [previous-heading previous-pitch previous-roll] + [0xFF0000 0x00FF00 0xFFFFFF])) + image)) + +(defn view-proprioception + "Creates a function which accepts a list of proprioceptive data and + display each element of the list to the screen as an image." [] - (let [heading (view-angle 0xFF0000) - pitch (view-angle 0x00FF00) - roll (view-angle 0xFFFFFF) - v-heading (view-image) - v-pitch (view-image) - v-roll (view-image) - ] - (fn [prop-data] - (dorun - (map - (fn [[h p r]] - (v-heading (heading h)) - (v-pitch (pitch p)) - (v-roll (roll r))) - prop-data))))) + (view-sense proprioception-display-kernel)) + + #+end_src diff -r facc2ef3fe5c -r 2902aca33c6e org/test-creature.org --- a/org/test-creature.org Sat Feb 04 10:13:15 2012 -0700 +++ b/org/test-creature.org Sat Feb 04 10:26:11 2012 -0700 @@ -145,7 +145,7 @@ hearing-display (view-hearing) prop (proprioception! creature) - prop-debug (proprioception-debug-window) + prop-display (view-proprioception) muscle-fns (movement! creature) @@ -210,7 +210,7 @@ ;;(dorun ;; (map #(%1 %2) touch-nerves (repeat (.getRootNode world)))) - (prop-debug (prop)) + (prop-display (prop)) (touch-display (map #(% (.getRootNode world)) touch))