# HG changeset patch # User Robert McIntyre # Date 1326612786 25200 # Node ID 40e72c6943d8e8191cdb30792e62bd601f8fe9cc # Parent 3334bf15854b9053ed2b8657028ac2cc9ad76c9b fixing out-of-bounds error diff -r 3334bf15854b -r 40e72c6943d8 assets/Models/creature1/tip.png Binary file assets/Models/creature1/tip.png has changed diff -r 3334bf15854b -r 40e72c6943d8 assets/Models/creature1/try-again.blend Binary file assets/Models/creature1/try-again.blend has changed diff -r 3334bf15854b -r 40e72c6943d8 org/test-creature.org --- a/org/test-creature.org Sat Jan 14 23:06:44 2012 -0700 +++ b/org/test-creature.org Sun Jan 15 00:33:06 2012 -0700 @@ -63,6 +63,7 @@ (import java.awt.Dimension) (import javax.swing.JFrame) (import java.awt.Dimension) +(import com.aurellem.capture.RatchetTimer) (declare joint-create) (defn view-image @@ -100,19 +101,21 @@ ;; TODO maybe parallelize this since it's easy [points] - (let [xs (vec (map first points)) - ys (vec (map second points)) - x0 (apply min xs) - y0 (apply min ys) - width (- (apply max xs) x0) - height (- (apply max ys) y0) - image (BufferedImage. (inc width) (inc height) - BufferedImage/TYPE_BYTE_BINARY)] - (dorun - (for [index (range (count points))] - (.setRGB image (- (xs index) x0) (- (ys index) y0) -1))) - - image)) + (if (empty? points) + (BufferedImage. 1 1 BufferedImage/TYPE_BYTE_BINARY) + (let [xs (vec (map first points)) + ys (vec (map second points)) + x0 (apply min xs) + y0 (apply min ys) + width (- (apply max xs) x0) + height (- (apply max ys) y0) + image (BufferedImage. (inc width) (inc height) + BufferedImage/TYPE_BYTE_BINARY)] + (dorun + (for [index (range (count points))] + (.setRGB image (- (xs index) x0) (- (ys index) y0) -1))) + + image))) (defn test-data [] @@ -405,36 +408,7 @@ (-> (.getAdditionalRenderState) (.setDepthTest false)))) -(defn test-creature [thing] - (let [x-axis - (box 1 0.01 0.01 :physical? false :color ColorRGBA/Red) - y-axis - (box 0.01 1 0.01 :physical? false :color ColorRGBA/Green) - z-axis - (box 0.01 0.01 1 :physical? false :color ColorRGBA/Blue)] - (world - (nodify [(blender-creature thing) - (box 10 2 10 :position (Vector3f. 0 -9 0) - :color ColorRGBA/Gray :mass 0) - x-axis y-axis z-axis - ]) - standard-debug-controls - (fn [world] - (light-up-everything world) - (enable-debug world) - ;;(com.aurellem.capture.Capture/captureVideo - ;; world (file-str "/home/r/proj/ai-videos/hand")) - (.setTimer world (NanoTimer.)) - (set-gravity world (Vector3f. 0 0 0)) - (speed-up world) - ) - no-op - ;;(let [timer (atom 0)] - ;; (fn [_ _] - ;; (swap! timer inc) - ;; (if (= (rem @timer 60) 0) - ;; (println-repl (float (/ @timer 60)))))) - ))) + (defn colorful [] (.getChild (worm-model) "worm-21")) @@ -652,6 +626,12 @@ ])) +(defn sensors-in-triangle + "find the locations of the sensors within a triangle" + [image tri] + ) + + (defn locate-feelers "Search the geometry's tactile UV image for touch sensors, returning their positions in geometry-relative coordinates." @@ -695,12 +675,14 @@ (use 'clojure.contrib.def) (defn-memo touch-topology [#^Gemoetry geo] - (let [feeler-coords - (map - #(vector (int (.getX %)) (int (.getY %))) - (white-coordinates - (.getProcessor (touch-receptor-image (colorful)))))] - (vec (collapse feeler-coords)))) + (if-let [image (touch-receptor-image geo)] + (let [feeler-coords + (map + #(vector (int (.getX %)) (int (.getY %))) + (white-coordinates + (.getProcessor image)))] + (vec (collapse feeler-coords))) + [])) (defn enable-touch [#^Geometry geo] (let [feeler-coords (locate-feelers geo) @@ -753,124 +735,46 @@ 1 -1} (sensor-data i))))) (vi image))))) -(defn world-setup [joint] - (let [joint-position (Vector3f. 0 0 0) - joint-rotation - (.toRotationMatrix - (.mult - (doto (Quaternion.) - (.fromAngleAxis - (* 1 (/ Math/PI 4)) - (Vector3f. -1 0 0))) - (doto (Quaternion.) - (.fromAngleAxis - (* 1 (/ Math/PI 2)) - (Vector3f. 0 0 1))))) - top-position (.mult joint-rotation (Vector3f. 8 0 0)) - - origin (doto - (sphere 0.1 :physical? false :color ColorRGBA/Cyan - :position top-position)) - top (doto - (sphere 0.1 :physical? false :color ColorRGBA/Yellow - :position top-position) - (.addControl - (RigidBodyControl. - (CapsuleCollisionShape. 0.5 1.5 1) (float 20)))) - bottom (doto - (sphere 0.1 :physical? false :color ColorRGBA/DarkGray - :position (Vector3f. 0 0 0)) - (.addControl - (RigidBodyControl. - (CapsuleCollisionShape. 0.5 1.5 1) (float 0)))) - table (box 10 2 10 :position (Vector3f. 0 -20 0) - :color ColorRGBA/Gray :mass 0) - a (.getControl top RigidBodyControl) - b (.getControl bottom RigidBodyControl)] +;;(defn test-touch [world creature] - (cond - (= joint :cone) - - (doto (ConeJoint. - a b - (world-to-local top joint-position) - (world-to-local bottom joint-position) - joint-rotation - joint-rotation - ) - - (.setLimit (* (/ 10) Math/PI) - (* (/ 4) Math/PI) - 0))) - [origin top bottom table])) - -(defn test-joint [joint] - (let [[origin top bottom floor] (world-setup joint) - control (.getControl top RigidBodyControl) - move-up? (atom false) - move-down? (atom false) - move-left? (atom false) - move-right? (atom false) - roll-left? (atom false) - roll-right? (atom false) - timer (atom 0)] - - (world - (nodify [top bottom floor origin]) - (merge standard-debug-controls - {"key-r" (fn [_ pressed?] (reset! move-up? pressed?)) - "key-t" (fn [_ pressed?] (reset! move-down? pressed?)) - "key-f" (fn [_ pressed?] (reset! move-left? pressed?)) - "key-g" (fn [_ pressed?] (reset! move-right? pressed?)) - "key-v" (fn [_ pressed?] (reset! roll-left? pressed?)) - "key-b" (fn [_ pressed?] (reset! roll-right? pressed?))}) - - (fn [world] - (light-up-everything world) - (enable-debug world) - (set-gravity world (Vector3f. 0 0 0)) - ) - - (fn [world _] - (if (zero? (rem (swap! timer inc) 100)) - (do - ;; (println-repl @timer) - (.attachChild (.getRootNode world) - (sphere 0.05 :color ColorRGBA/Yellow - :position (.getWorldTranslation top) - :physical? false)) - (.attachChild (.getRootNode world) - (sphere 0.05 :color ColorRGBA/LightGray - :position (.getWorldTranslation bottom) - :physical? false)))) - - (if @move-up? - (.applyTorque control - (.mult (.getPhysicsRotation control) - (Vector3f. 0 0 10)))) - (if @move-down? - (.applyTorque control - (.mult (.getPhysicsRotation control) - (Vector3f. 0 0 -10)))) - (if @move-left? - (.applyTorque control - (.mult (.getPhysicsRotation control) - (Vector3f. 0 10 0)))) - (if @move-right? - (.applyTorque control - (.mult (.getPhysicsRotation control) - (Vector3f. 0 -10 0)))) - (if @roll-left? - (.applyTorque control - (.mult (.getPhysicsRotation control) - (Vector3f. -1 0 0)))) - (if @roll-right? - (.applyTorque control - (.mult (.getPhysicsRotation control) - (Vector3f. 1 0 0)))))))) - +(defn test-creature [thing] + (let [x-axis + (box 1 0.01 0.01 :physical? false :color ColorRGBA/Red) + y-axis + (box 0.01 1 0.01 :physical? false :color ColorRGBA/Green) + z-axis + (box 0.01 0.01 1 :physical? false :color ColorRGBA/Blue) + creature (blender-creature thing) + touch-nerves (touch creature) + touch-debug-windows (map (fn [_] (debug-window)) touch-nerves) + ] + (world + (nodify [creature + (box 10 2 10 :position (Vector3f. 0 -9 0) + :color ColorRGBA/Gray :mass 0) + x-axis y-axis z-axis + ]) + standard-debug-controls + (fn [world] + (light-up-everything world) + (enable-debug world) + ;;(com.aurellem.capture.Capture/captureVideo + ;; world (file-str "/home/r/proj/ai-videos/hand")) + (.setTimer world (RatchetTimer. 60)) + ;;(set-gravity world (Vector3f. 0 0 0)) + ) + (fn [world tpf] + (dorun + (map #(%1 (%2 (.getRootNode world))) touch-debug-windows touch-nerves)) + ) + ;;(let [timer (atom 0)] + ;; (fn [_ _] + ;; (swap! timer inc) + ;; (if (= (rem @timer 60) 0) + ;; (println-repl (float (/ @timer 60)))))) + ))) #+end_src @@ -1066,6 +970,124 @@ )))) +(defn world-setup [joint] + (let [joint-position (Vector3f. 0 0 0) + joint-rotation + (.toRotationMatrix + (.mult + (doto (Quaternion.) + (.fromAngleAxis + (* 1 (/ Math/PI 4)) + (Vector3f. -1 0 0))) + (doto (Quaternion.) + (.fromAngleAxis + (* 1 (/ Math/PI 2)) + (Vector3f. 0 0 1))))) + top-position (.mult joint-rotation (Vector3f. 8 0 0)) + + origin (doto + (sphere 0.1 :physical? false :color ColorRGBA/Cyan + :position top-position)) + top (doto + (sphere 0.1 :physical? false :color ColorRGBA/Yellow + :position top-position) + + (.addControl + (RigidBodyControl. + (CapsuleCollisionShape. 0.5 1.5 1) (float 20)))) + bottom (doto + (sphere 0.1 :physical? false :color ColorRGBA/DarkGray + :position (Vector3f. 0 0 0)) + (.addControl + (RigidBodyControl. + (CapsuleCollisionShape. 0.5 1.5 1) (float 0)))) + table (box 10 2 10 :position (Vector3f. 0 -20 0) + :color ColorRGBA/Gray :mass 0) + a (.getControl top RigidBodyControl) + b (.getControl bottom RigidBodyControl)] + + (cond + (= joint :cone) + + (doto (ConeJoint. + a b + (world-to-local top joint-position) + (world-to-local bottom joint-position) + joint-rotation + joint-rotation + ) + + + (.setLimit (* (/ 10) Math/PI) + (* (/ 4) Math/PI) + 0))) + [origin top bottom table])) + +(defn test-joint [joint] + (let [[origin top bottom floor] (world-setup joint) + control (.getControl top RigidBodyControl) + move-up? (atom false) + move-down? (atom false) + move-left? (atom false) + move-right? (atom false) + roll-left? (atom false) + roll-right? (atom false) + timer (atom 0)] + + (world + (nodify [top bottom floor origin]) + (merge standard-debug-controls + {"key-r" (fn [_ pressed?] (reset! move-up? pressed?)) + "key-t" (fn [_ pressed?] (reset! move-down? pressed?)) + "key-f" (fn [_ pressed?] (reset! move-left? pressed?)) + "key-g" (fn [_ pressed?] (reset! move-right? pressed?)) + "key-v" (fn [_ pressed?] (reset! roll-left? pressed?)) + "key-b" (fn [_ pressed?] (reset! roll-right? pressed?))}) + + (fn [world] + (light-up-everything world) + (enable-debug world) + (set-gravity world (Vector3f. 0 0 0)) + ) + + (fn [world _] + (if (zero? (rem (swap! timer inc) 100)) + (do + ;; (println-repl @timer) + (.attachChild (.getRootNode world) + (sphere 0.05 :color ColorRGBA/Yellow + :position (.getWorldTranslation top) + :physical? false)) + (.attachChild (.getRootNode world) + (sphere 0.05 :color ColorRGBA/LightGray + :position (.getWorldTranslation bottom) + :physical? false)))) + + (if @move-up? + (.applyTorque control + (.mult (.getPhysicsRotation control) + (Vector3f. 0 0 10)))) + (if @move-down? + (.applyTorque control + (.mult (.getPhysicsRotation control) + (Vector3f. 0 0 -10)))) + (if @move-left? + (.applyTorque control + (.mult (.getPhysicsRotation control) + (Vector3f. 0 10 0)))) + (if @move-right? + (.applyTorque control + (.mult (.getPhysicsRotation control) + (Vector3f. 0 -10 0)))) + (if @roll-left? + (.applyTorque control + (.mult (.getPhysicsRotation control) + (Vector3f. -1 0 0)))) + (if @roll-right? + (.applyTorque control + (.mult (.getPhysicsRotation control) + (Vector3f. 1 0 0)))))))) + #+end_src