Mercurial > cortex
changeset 117:94c005f7f9dd
saving progress
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Fri, 20 Jan 2012 05:47:56 -0700 |
parents | 947bef5d6670 |
children | 1261444da2c7 |
files | assets/Models/creature1/try-again.blend org/test-creature.org |
diffstat | 2 files changed, 52 insertions(+), 32 deletions(-) [+] |
line wrap: on
line diff
1.1 Binary file assets/Models/creature1/try-again.blend has changed
2.1 --- a/org/test-creature.org Fri Jan 20 01:07:46 2012 -0700 2.2 +++ b/org/test-creature.org Fri Jan 20 05:47:56 2012 -0700 2.3 @@ -622,7 +622,9 @@ 2.4 ;; http://en.wikipedia.org/wiki/Retina 2.5 2.6 (defn test-eye [] 2.7 - (.getChild (worm-model) "worm-11")) 2.8 + (.getChild 2.9 + (.getChild (worm-model) "eyes") 2.10 + "eye")) 2.11 2.12 2.13 (defn retina-sensor-image 2.14 @@ -632,7 +634,7 @@ 2.15 values found in the pixel. :red, :green, :blue, :gray are already 2.16 defined as extracting the red green blue and average components 2.17 respectively." 2.18 - [#^Geometry eye] 2.19 + [#^Spatial eye] 2.20 (if-let [eye-map (meta-data eye "eye")] 2.21 (map-vals 2.22 #(ImageToAwt/convert 2.23 @@ -641,6 +643,16 @@ 2.24 (read-string 2.25 eye-map)))) 2.26 2.27 +(defn eye-dimensions 2.28 + "returns the width and height specified in the metadata of the eye" 2.29 + [#^Spatial eye] 2.30 + (let [dimensions 2.31 + (map #(vector (.getWidth %) (.getHeight %)) 2.32 + (vals (retina-sensor-image eye)))] 2.33 + [(apply max (map first dimensions)) 2.34 + (apply max (map second dimensions))])) 2.35 + 2.36 + 2.37 (defn creature-eyes 2.38 "The eye nodes which are children of the \"eyes\" node in the 2.39 creature." 2.40 @@ -700,14 +712,45 @@ 2.41 (.getGeometry target) 2.42 (recur (float (* 2 radius))))))) 2.43 2.44 +(defn bind-camera 2.45 + "Bind the camera to the Spatial such that it will maintain its 2.46 + current position relative to the Spatial no matter how the spatial 2.47 + moves." 2.48 + [#^Spatial obj #^Camera cam] 2.49 + (let [cam-offset (.subtract (.getLocation cam) 2.50 + (.getWorldTranslation obj)) 2.51 + initial-cam-rotation (Quaternion. (.getRotation cam)) 2.52 + base-anti-rotation (.inverse (.getWorldRotation obj))] 2.53 + (.addControl 2.54 + obj 2.55 + (proxy [AbstractControl] [] 2.56 + (controlUpdate [tpf] 2.57 + (let [total-rotation 2.58 + (.mult base-anti-rotation (.getWorldRotation obj))] 2.59 + (.setLocation cam 2.60 + (.add 2.61 + (.mult total-rotation cam-offset) 2.62 + (.getWorldTranslation obj))) 2.63 + (.setRotation cam 2.64 + (.mult total-rotation initial-cam-rotation)))) 2.65 + (controlRender [_ _]))))) 2.66 + 2.67 + 2.68 (defn attach-eyes 2.69 - "For each eye in the creature, attach a CameraNode to the appropiate 2.70 + "For each eye in the creature, attach a Camera to the appropiate 2.71 area and return the Camera." 2.72 [#^Node creature] 2.73 (for [eye (creature-eyes creature)] 2.74 - (let [target (eye-target creature eye)] 2.75 - (CameraNode 2.76 -) 2.77 + (let [target (eye-target creature eye) 2.78 + [cam-width cam-height] (eye-dimensions eye) 2.79 + cam (Camera. cam-width cam-height)] 2.80 + (.setLocation cam (.getWorldTranslation eye)) 2.81 + (.setRotation cam (.getWorldRotation eye)) 2.82 + 2.83 + ) 2.84 + 2.85 + 2.86 +)) 2.87 2.88 (defn vision 2.89 2.90 @@ -866,33 +909,10 @@ 2.91 ;; the camera will stay in its initial position/rotation with relation 2.92 ;; to the spatial. 2.93 2.94 -(defn bind-camera [#^Spatial obj #^Camera cam] 2.95 - (let [cam-offset (.subtract (.getLocation cam) 2.96 - (.getWorldTranslation obj)) 2.97 - initial-cam-rotation (.getRotation cam) 2.98 - base-anti-rotation (.inverse (.getWorldRotation obj))] 2.99 - (.addControl 2.100 - obj 2.101 - (proxy [AbstractControl] [] 2.102 - (controlUpdate [tpf] 2.103 - (let [total-rotation 2.104 - (.mult base-anti-rotation (.getWorldRotation obj))] 2.105 - 2.106 - (.setLocation cam 2.107 - (.add 2.108 - (.mult total-rotation cam-offset) 2.109 - (.getWorldTranslation obj))) 2.110 - (.setRotation cam 2.111 - initial-cam-rotation) 2.112 - ;;(.mult total-rotation initial-cam-rotation) 2.113 - 2.114 - )) 2.115 2.116 - (controlRender [_ _]))))) 2.117 - 2.118 - 2.119 - 2.120 -(defn follow-test [] 2.121 +(defn follow-test 2.122 + "show a camera that stays in the same relative position to a blue cube." 2.123 + [] 2.124 (let [camera-pos (Vector3f. 0 30 0) 2.125 rock (box 1 1 1 :color ColorRGBA/Blue 2.126 :position (Vector3f. 0 10 0)