October 18th, 2008
아쉬운 Scenegraph project
화질 봐라. 무슨 encryption도 아니고..
JavaFX의 언어적인 측면은 F3에서 왔다고 해도
선언적 graphics의 근간이 되는 프로젝트는 Scenegraph (원래 scenegraph는 일반명사지만 여기서 언급하는건 이 프로젝트를 지칭한다).
이를 이용하면 간단하고도 선언적인 방법으로 제법 쓸만한 UI(effect, animation포함)를 만들 수 있다.
그런데 지금쯤 이면 꽤나 성숙해 있어야 할텐데 좀 더딘면이 있는듯하다.
무엇보다 나를 좌절시키는 건...GPL!!
LGPL이면 더 고마울텐데.. 흑.
위의 동영상에 대한 소스는 이렇다. 대략 조잡.
JAVA:
-
public class FlowTest {
-
private SGNode rootNode = null;
-
private SGNode coreNode = null;
-
private SGNode perspectiveSrc = null;
-
private PerspectiveTransform ptx = null;
-
-
public FlowTest() {
-
// [ Reflection [ Perspective[core] ] ]
-
coreNode = FlowTest.createCore();
-
coreNode.addMouseListener(new SGMouseAdapter() {
-
@Override
-
@Override
-
public void begin() {
-
}
-
-
@Override
-
public void end() {
-
}
-
-
@Override
-
public void timingEvent(float fraction, long totalElapsed) {
-
setupPerspective(perspectiveSrc, true, fraction);
-
}
-
});
-
toCenter.start();
-
}
-
});
-
-
perspectiveSrc = FlowTest.reflect(coreNode);
-
SGEffect pNode = FlowTest.perspect(perspectiveSrc);
-
ptx = (PerspectiveTransform) pNode.getEffect();
-
-
rootNode = pNode;
-
setupPerspective(perspectiveSrc, true, 0);
-
}
-
-
private void setupPerspective(SGNode srcNode, boolean onLeft, float ratio) {
-
float left = ratio * 200;
-
float vPadOnRight = (float) ((1 - ratio) * snBounds.getHeight() / 3);
-
float width = snBounds.getBounds().width * (0.5f + (0.5f * ratio));
-
-
float ulx = left + (float)snBounds.getX();
-
float uly = (float) snBounds.getY();
-
float llx = ulx;
-
float lly = (float) snBounds.getHeight();
-
float urx = (float) (ulx + width);
-
float ury = uly + vPadOnRight;
-
float lrx = urx;
-
float lry = lly - vPadOnRight;
-
ptx.setQuadMapping(ulx, uly, urx, ury, lrx, lry, llx, lly);
-
}
-
-
private static SGNode createCore() {
-
SGImage imageNode = new SGImage();
-
Image img = null;
-
try {
-
img = ImageIO.read(FlowTest.class.getResource("/ddabok.jpg"));
-
}
-
imageNode.setImage(img);
-
return imageNode;
-
}
-
-
private static SGEffect reflect(SGNode child) {
-
SGEffect resultNode = new SGEffect();
-
Reflection refEff = new Reflection();
-
resultNode.setEffect(refEff);
-
resultNode.setChild(child);
-
return resultNode;
-
}
-
-
private static SGEffect perspect(SGNode child) {
-
SGEffect resultNode = new SGEffect();
-
PerspectiveTransform perspectiveTx = new PerspectiveTransform();
-
resultNode.setEffect(perspectiveTx);
-
resultNode.setChild(child);
-
return resultNode;
-
}
-
-
JSGPanel sgPanel = new JSGPanel();
-
sgPanel.setScene(new FlowTest().rootNode);
-
frame.add(sgPanel);
-
frame.pack();
-
frame.setVisible(true);
-
}
-
}