# HG changeset patch # User Robert McIntyre # Date 1327063676 25200 # Node ID 94c005f7f9ddcfe5375e92633629e1d9ce9fd3da # Parent 947bef5d6670bdce0e1fe35e970fc5b419bee544 saving progress diff -r 947bef5d6670 -r 94c005f7f9dd assets/Models/creature1/try-again.blend Binary file assets/Models/creature1/try-again.blend has changed diff -r 947bef5d6670 -r 94c005f7f9dd org/test-creature.org --- a/org/test-creature.org Fri Jan 20 01:07:46 2012 -0700 +++ b/org/test-creature.org Fri Jan 20 05:47:56 2012 -0700 @@ -622,7 +622,9 @@ ;; http://en.wikipedia.org/wiki/Retina (defn test-eye [] - (.getChild (worm-model) "worm-11")) + (.getChild + (.getChild (worm-model) "eyes") + "eye")) (defn retina-sensor-image @@ -632,7 +634,7 @@ values found in the pixel. :red, :green, :blue, :gray are already defined as extracting the red green blue and average components respectively." - [#^Geometry eye] + [#^Spatial eye] (if-let [eye-map (meta-data eye "eye")] (map-vals #(ImageToAwt/convert @@ -641,6 +643,16 @@ (read-string eye-map)))) +(defn eye-dimensions + "returns the width and height specified in the metadata of the eye" + [#^Spatial eye] + (let [dimensions + (map #(vector (.getWidth %) (.getHeight %)) + (vals (retina-sensor-image eye)))] + [(apply max (map first dimensions)) + (apply max (map second dimensions))])) + + (defn creature-eyes "The eye nodes which are children of the \"eyes\" node in the creature." @@ -700,14 +712,45 @@ (.getGeometry target) (recur (float (* 2 radius))))))) +(defn bind-camera + "Bind the camera to the Spatial such that it will maintain its + current position relative to the Spatial no matter how the spatial + moves." + [#^Spatial obj #^Camera cam] + (let [cam-offset (.subtract (.getLocation cam) + (.getWorldTranslation obj)) + initial-cam-rotation (Quaternion. (.getRotation cam)) + base-anti-rotation (.inverse (.getWorldRotation obj))] + (.addControl + obj + (proxy [AbstractControl] [] + (controlUpdate [tpf] + (let [total-rotation + (.mult base-anti-rotation (.getWorldRotation obj))] + (.setLocation cam + (.add + (.mult total-rotation cam-offset) + (.getWorldTranslation obj))) + (.setRotation cam + (.mult total-rotation initial-cam-rotation)))) + (controlRender [_ _]))))) + + (defn attach-eyes - "For each eye in the creature, attach a CameraNode to the appropiate + "For each eye in the creature, attach a Camera to the appropiate area and return the Camera." [#^Node creature] (for [eye (creature-eyes creature)] - (let [target (eye-target creature eye)] - (CameraNode -) + (let [target (eye-target creature eye) + [cam-width cam-height] (eye-dimensions eye) + cam (Camera. cam-width cam-height)] + (.setLocation cam (.getWorldTranslation eye)) + (.setRotation cam (.getWorldRotation eye)) + + ) + + +)) (defn vision @@ -866,33 +909,10 @@ ;; the camera will stay in its initial position/rotation with relation ;; to the spatial. -(defn bind-camera [#^Spatial obj #^Camera cam] - (let [cam-offset (.subtract (.getLocation cam) - (.getWorldTranslation obj)) - initial-cam-rotation (.getRotation cam) - base-anti-rotation (.inverse (.getWorldRotation obj))] - (.addControl - obj - (proxy [AbstractControl] [] - (controlUpdate [tpf] - (let [total-rotation - (.mult base-anti-rotation (.getWorldRotation obj))] - - (.setLocation cam - (.add - (.mult total-rotation cam-offset) - (.getWorldTranslation obj))) - (.setRotation cam - initial-cam-rotation) - ;;(.mult total-rotation initial-cam-rotation) - - )) - (controlRender [_ _]))))) - - - -(defn follow-test [] +(defn follow-test + "show a camera that stays in the same relative position to a blue cube." + [] (let [camera-pos (Vector3f. 0 30 0) rock (box 1 1 1 :color ColorRGBA/Blue :position (Vector3f. 0 10 0)