comparison org/util.org @ 114:9d0fe7f54e14

merged image viewing code to cortex.util
author Robert McIntyre <rlm@mit.edu>
date Thu, 19 Jan 2012 22:19:24 -0700
parents 92b857b6145d
children b591da250afc
comparison
equal deleted inserted replaced
113:a980462ebe76 114:9d0fe7f54e14
92 (:import com.jme3.scene.shape.Box) 92 (:import com.jme3.scene.shape.Box)
93 (:import com.jme3.scene.Node) 93 (:import com.jme3.scene.Node)
94 (:import com.jme3.scene.shape.Sphere) 94 (:import com.jme3.scene.shape.Sphere)
95 (:import com.jme3.light.AmbientLight) 95 (:import com.jme3.light.AmbientLight)
96 (:import com.jme3.light.DirectionalLight) 96 (:import com.jme3.light.DirectionalLight)
97 (:import com.jme3.math.ColorRGBA) 97 (:import (com.jme3.math Triangle ColorRGBA))
98 (:import com.jme3.bullet.BulletAppState) 98 (:import com.jme3.bullet.BulletAppState)
99 (:import com.jme3.material.Material) 99 (:import com.jme3.material.Material)
100 (:import com.jme3.scene.Geometry) 100 (:import com.jme3.scene.Geometry)
101 (:import java.awt.image.BufferedImage)
102 (:import javax.swing.JPanel)
103 (:import javax.swing.JFrame)
104 (:import javax.swing.SwingUtilities)
105
101 (:import (java.util.logging Level Logger))) 106 (:import (java.util.logging Level Logger)))
102
103
104 107
105 (defvar println-repl 108 (defvar println-repl
106 (bound-fn [& args] (apply println args)) 109 (bound-fn [& args] (apply println args))
107 "println called from the LWJGL thread will not go to the REPL, but 110 "println called from the LWJGL thread will not go to the REPL, but
108 instead to whatever terminal started the JVM process. This function 111 instead to whatever terminal started the JVM process. This function
109 will always output to the REPL") 112 will always output to the REPL")
110 113
111 (defn position-camera 114 (defn position-camera
112 "Change the position of the in-world camera." 115 "Change the position of the in-world camera."
113 ([world position direction up] 116 ([world position direction up]
114 (doto (.getCamera world) 117 (doto (.getCamera world)
386 389
387 #+name: world-view 390 #+name: world-view
388 #+begin_src clojure :results silent 391 #+begin_src clojure :results silent
389 (in-ns 'cortex.util) 392 (in-ns 'cortex.util)
390 393
394 (defn view-image
395 "Initailizes a JPanel on which you may draw a BufferedImage.
396 Returns a function that accepts a BufferedImage and draws it to the
397 JPanel."
398 []
399 (let [image
400 (atom
401 (BufferedImage. 1 1 BufferedImage/TYPE_4BYTE_ABGR))
402 panel
403 (proxy [JPanel] []
404 (paint
405 [graphics]
406 (proxy-super paintComponent graphics)
407 (.drawImage graphics @image 0 0 nil)))
408 frame (JFrame. "Display Image")]
409 (SwingUtilities/invokeLater
410 (fn []
411 (doto frame
412 (-> (.getContentPane) (.add panel))
413 (.pack)
414 (.setLocationRelativeTo nil)
415 (.setResizable true)
416 (.setVisible true))))
417 (fn [#^BufferedImage i]
418 (reset! image i)
419 (.setSize frame (+ 8 (.getWidth i)) (+ 28 (.getHeight i)))
420 (.repaint panel 0 0 (.getWidth i) (.getHeight i)))))
421
391 (defprotocol Viewable 422 (defprotocol Viewable
392 (view [something])) 423 (view [something]))
393 424
394 (extend-type com.jme3.scene.Geometry 425 (extend-type com.jme3.scene.Geometry
395 Viewable 426 Viewable