October 18th, 2008
아쉬운 Scenegraph project


화질 봐라. 무슨 encryption도 아니고..

JavaFX의 언어적인 측면은 F3에서 왔다고 해도
선언적 graphics의 근간이 되는 프로젝트는 Scenegraph (원래 scenegraph는 일반명사지만 여기서 언급하는건 이 프로젝트를 지칭한다).

이를 이용하면 간단하고도 선언적인 방법으로 제법 쓸만한 UI(effect, animation포함)를 만들 수 있다.
그런데 지금쯤 이면 꽤나 성숙해 있어야 할텐데 좀 더딘면이 있는듯하다.

무엇보다 나를 좌절시키는 건...GPL!!
LGPL이면 더 고마울텐데.. 흑.

위의 동영상에 대한 소스는 이렇다. 대략 조잡.

JAVA:
  1. public class FlowTest {
  2.     private SGNode rootNode = null;
  3.     private SGNode coreNode = null;
  4.     private SGNode perspectiveSrc = null;
  5.     private PerspectiveTransform ptx = null;
  6.  
  7.     public FlowTest() {
  8.         // [ Reflection [ Perspective[core] ] ]
  9.         coreNode = FlowTest.createCore();
  10.         coreNode.addMouseListener(new SGMouseAdapter() {
  11.             @Override
  12.             public void mousePressed(MouseEvent e, SGNode node) {
  13.                 Clip toCenter = Clip.create(500, new TimingTarget() {
  14.                     @Override
  15.                     public void begin() {
  16.                     }
  17.  
  18.                     @Override
  19.                     public void end() {
  20.                     }
  21.  
  22.                     @Override
  23.                     public void timingEvent(float fraction, long totalElapsed) {
  24.                         setupPerspective(perspectiveSrc, true, fraction);
  25.                     }
  26.                 });
  27.                 toCenter.start();
  28.             }
  29.         });
  30.  
  31.         perspectiveSrc = FlowTest.reflect(coreNode);
  32.         SGEffect pNode = FlowTest.perspect(perspectiveSrc);
  33.         ptx = (PerspectiveTransform) pNode.getEffect();
  34.  
  35.         rootNode = pNode;
  36.         setupPerspective(perspectiveSrc, true, 0);
  37.     }
  38.  
  39.     private void setupPerspective(SGNode srcNode, boolean onLeft, float ratio) {
  40.         float left = ratio * 200;
  41.         Rectangle2D snBounds = srcNode.getBounds();
  42.         float vPadOnRight = (float) ((1 - ratio) * snBounds.getHeight() / 3);
  43.         float width = snBounds.getBounds().width * (0.5f + (0.5f * ratio));
  44.  
  45.         float ulx = left + (float)snBounds.getX();
  46.         float uly = (float) snBounds.getY();
  47.         float llx = ulx;
  48.         float lly = (float) snBounds.getHeight();
  49.         float urx = (float) (ulx + width);
  50.         float ury = uly + vPadOnRight;
  51.         float lrx = urx;
  52.         float lry = lly - vPadOnRight;
  53.         ptx.setQuadMapping(ulx, uly, urx, ury, lrx, lry, llx, lly);
  54.     }
  55.  
  56.     private static SGNode createCore() {
  57.         SGImage imageNode = new SGImage();
  58.         Image img = null;
  59.         try {
  60.             img = ImageIO.read(FlowTest.class.getResource("/ddabok.jpg"));
  61.         } catch (IOException e) {
  62.             throw new IllegalStateException(e);
  63.         }
  64.         imageNode.setImage(img);
  65.         return imageNode;
  66.     }
  67.  
  68.     private static SGEffect reflect(SGNode child) {
  69.         SGEffect resultNode = new SGEffect();
  70.         Reflection refEff = new Reflection();
  71.         resultNode.setEffect(refEff);
  72.         resultNode.setChild(child);
  73.         return resultNode;
  74.     }
  75.  
  76.     private static SGEffect perspect(SGNode child) {
  77.         SGEffect resultNode = new SGEffect();
  78.         PerspectiveTransform perspectiveTx = new PerspectiveTransform();
  79.         resultNode.setEffect(perspectiveTx);
  80.         resultNode.setChild(child);
  81.         return resultNode;
  82.     }
  83.  
  84.     public static void main(String[] args) {
  85.         JFrame frame = new JFrame("Scenegraph Test");
  86.         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  87.         JSGPanel sgPanel = new JSGPanel();
  88.         sgPanel.setBackground(Color.BLACK);
  89.         sgPanel.setPreferredSize(new Dimension(800, 400));
  90.         sgPanel.setScene(new FlowTest().rootNode);
  91.         frame.add(sgPanel);
  92.         frame.pack();
  93.         frame.setVisible(true);
  94.     }
  95. }

October 15th, 2008
JavaFX로 만든 presentation slides

javafx slide

요즘 presentation 자료를 flash로 바꿔주는 서비스들이 많이 있는데
그런 서비스는 아니고 James Weaver라는 아저씨가 발표자료를 JavaFX로 구현해 놨다.(링크)

자바 6이 있으면 아무나 실행가능토록 Web Start 버튼도 있다.
Webstartsmall2


다 좋다. 그런데 이렇게 느리면 어떻게 쓰냐. 내 컴퓨터가 아주 좋진 않아도 쓸만한 사양인데.
원본글에 성능은 아직 손봐야 한다고 써있긴 하지만..쩝