diff 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
line wrap: on
line diff
     1.1 --- a/org/eyes.org	Wed Jan 11 21:30:26 2012 -0700
     1.2 +++ b/org/eyes.org	Sat Jan 14 01:07:18 2012 -0700
     1.3 @@ -99,31 +99,32 @@
     1.4    (:import com.jme3.math.Vector3f))
     1.5  
     1.6  (defn view-image
     1.7 -  "Initailizes a JPanel on which you may draw a BufferedImage of the
     1.8 -  given width and height.  Returns a function that accepts a
     1.9 -  BufferedImage and draws it to the JPanel."
    1.10 -  [width height]
    1.11 +  "Initailizes a JPanel on which you may draw a BufferedImage.
    1.12 +   Returns a function that accepts a BufferedImage and draws it to the
    1.13 +   JPanel."
    1.14 +  []
    1.15    (let [image
    1.16          (atom
    1.17 -         (BufferedImage. width height BufferedImage/TYPE_4BYTE_ABGR))
    1.18 +         (BufferedImage. 1 1 BufferedImage/TYPE_4BYTE_ABGR))
    1.19          panel 
    1.20          (proxy [JPanel] []
    1.21            (paint
    1.22              [graphics]
    1.23              (proxy-super paintComponent graphics)
    1.24 -            (.drawImage graphics @image 0 0 nil)))]
    1.25 +            (.drawImage graphics @image 0 0 nil)))
    1.26 +        frame (JFrame. "Display Image")]
    1.27      (SwingUtilities/invokeLater
    1.28       (fn []
    1.29 -       (.setPreferredSize panel (Dimension. width height))
    1.30 -       (doto (JFrame. "Eye Camera!")
    1.31 +       (doto frame
    1.32           (-> (.getContentPane) (.add panel))
    1.33           (.pack)
    1.34           (.setLocationRelativeTo nil)
    1.35 -         (.setResizable false)
    1.36 +         (.setResizable true)
    1.37           (.setVisible true))))
    1.38      (fn [#^BufferedImage i]
    1.39        (reset! image i)
    1.40 -      (.repaint panel))))
    1.41 +      (.setSize frame (+ 8 (.getWidth i)) (+ 28 (.getHeight i)))
    1.42 +      (.repaint panel 0 0 (.getWidth i) (.getHeight i)))))
    1.43  
    1.44  (defn test-two-eyes
    1.45    "Testing vision:
    1.46 @@ -143,12 +144,12 @@
    1.47               (let [cam (.clone (.getCamera world))
    1.48                     width (.getWidth cam)
    1.49                     height (.getHeight cam)]
    1.50 -               (add-eye world cam (view-image width height))
    1.51 +               (add-eye world cam (view-image))
    1.52                 (add-eye world
    1.53                          (doto (.clone cam)
    1.54                            (.setLocation (Vector3f. -10 0 0))
    1.55                            (.lookAt Vector3f/ZERO Vector3f/UNIT_Y))
    1.56 -                        (view-image width height))
    1.57 +                        (view-image))
    1.58                  ;; This is here to restore the main view
    1.59                 ;; after the other views have completed processing
    1.60                 (add-eye world (.getCamera world) no-op)))