comparison org/eyes.org @ 99:b7a3ba5e879b

made BufferedImage visulation more general
author Robert McIntyre <rlm@mit.edu>
date Sat, 14 Jan 2012 01:07:18 -0700
parents 39e4e1542e4a
children 128fa71ee188
comparison
equal deleted inserted replaced
98:5b23961433e3 99:b7a3ba5e879b
97 (:import com.jme3.math.ColorRGBA) 97 (:import com.jme3.math.ColorRGBA)
98 (:import com.jme3.scene.Node) 98 (:import com.jme3.scene.Node)
99 (:import com.jme3.math.Vector3f)) 99 (:import com.jme3.math.Vector3f))
100 100
101 (defn view-image 101 (defn view-image
102 "Initailizes a JPanel on which you may draw a BufferedImage of the 102 "Initailizes a JPanel on which you may draw a BufferedImage.
103 given width and height. Returns a function that accepts a 103 Returns a function that accepts a BufferedImage and draws it to the
104 BufferedImage and draws it to the JPanel." 104 JPanel."
105 [width height] 105 []
106 (let [image 106 (let [image
107 (atom 107 (atom
108 (BufferedImage. width height BufferedImage/TYPE_4BYTE_ABGR)) 108 (BufferedImage. 1 1 BufferedImage/TYPE_4BYTE_ABGR))
109 panel 109 panel
110 (proxy [JPanel] [] 110 (proxy [JPanel] []
111 (paint 111 (paint
112 [graphics] 112 [graphics]
113 (proxy-super paintComponent graphics) 113 (proxy-super paintComponent graphics)
114 (.drawImage graphics @image 0 0 nil)))] 114 (.drawImage graphics @image 0 0 nil)))
115 frame (JFrame. "Display Image")]
115 (SwingUtilities/invokeLater 116 (SwingUtilities/invokeLater
116 (fn [] 117 (fn []
117 (.setPreferredSize panel (Dimension. width height)) 118 (doto frame
118 (doto (JFrame. "Eye Camera!")
119 (-> (.getContentPane) (.add panel)) 119 (-> (.getContentPane) (.add panel))
120 (.pack) 120 (.pack)
121 (.setLocationRelativeTo nil) 121 (.setLocationRelativeTo nil)
122 (.setResizable false) 122 (.setResizable true)
123 (.setVisible true)))) 123 (.setVisible true))))
124 (fn [#^BufferedImage i] 124 (fn [#^BufferedImage i]
125 (reset! image i) 125 (reset! image i)
126 (.repaint panel)))) 126 (.setSize frame (+ 8 (.getWidth i)) (+ 28 (.getHeight i)))
127 (.repaint panel 0 0 (.getWidth i) (.getHeight i)))))
127 128
128 (defn test-two-eyes 129 (defn test-two-eyes
129 "Testing vision: 130 "Testing vision:
130 Tests the vision system by creating two views of the same rotating 131 Tests the vision system by creating two views of the same rotating
131 object from different angles and displaying both of those views in 132 object from different angles and displaying both of those views in
141 {} 142 {}
142 (fn [world] 143 (fn [world]
143 (let [cam (.clone (.getCamera world)) 144 (let [cam (.clone (.getCamera world))
144 width (.getWidth cam) 145 width (.getWidth cam)
145 height (.getHeight cam)] 146 height (.getHeight cam)]
146 (add-eye world cam (view-image width height)) 147 (add-eye world cam (view-image))
147 (add-eye world 148 (add-eye world
148 (doto (.clone cam) 149 (doto (.clone cam)
149 (.setLocation (Vector3f. -10 0 0)) 150 (.setLocation (Vector3f. -10 0 0))
150 (.lookAt Vector3f/ZERO Vector3f/UNIT_Y)) 151 (.lookAt Vector3f/ZERO Vector3f/UNIT_Y))
151 (view-image width height)) 152 (view-image))
152 ;; This is here to restore the main view 153 ;; This is here to restore the main view
153 ;; after the other views have completed processing 154 ;; after the other views have completed processing
154 (add-eye world (.getCamera world) no-op))) 155 (add-eye world (.getCamera world) no-op)))
155 (fn [world tpf] 156 (fn [world tpf]
156 (.rotate candy (* tpf 0.2) 0 0))))) 157 (.rotate candy (* tpf 0.2) 0 0)))))