JavaFX
中的Transform
类似乎包含3个坐标(x,y和z)。
如果我离开飞机会怎么样?它会做透视吗?
更新
实际上,如果在平面外旋转1度,物体也会消失。为什么呢?
public class TransformTry extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) {
primaryStage.setTitle("Drawing Operations Test");
Group root = new Group();
Canvas canvas = new Canvas(300, 250);
//canvas.getTransforms().add(new Rotate(1, new Point3D(0, 1, 0))); // square disappears
canvas.getTransforms().add(new Rotate(1, new Point3D(0, 0, 1))); // rotates correctly
GraphicsContext gc = canvas.getGraphicsContext2D();
gc.strokeRect(-50, -50, 100, 100);
root.getChildren().add(canvas);
primaryStage.setScene(new Scene(root));
primaryStage.show();
}
}
更新2
我找到了一种使用透视相机的方法,但它很奇怪:它看起来总是从窗口的中心上方看,所以在窗口调整大小时,平面外物体会发生变化:
public class ShapeTry01 extends Application {
@Override
public void start(Stage stage) throws Exception {
Shape shape = new Rectangle(100,100,50,50);
shape.setStroke(Color.RED);
shape.setFill(null);
Group group = new Group();
group.getChildren().add(shape);
//group.getTransforms().add(new Rotate(10, new Point3D(0, 0, 1)));
group.getTransforms().add(new Rotate(10, new Point3D(0, 1, 0)));
PerspectiveCamera camera = new PerspectiveCamera();
camera.setFieldOfView(45);
Scene scene = new Scene(group);
scene.setCamera( camera );
stage.setTitle("ShapeTry01");
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
答案 0 :(得分:3)
JavaFX 2以3D为开端,因此很多API都提到了z坐标。但实际上有用的3D仅在JavaFX8中添加(将在明年发布)。
您可以在此处查看文档:{{3}}并尝试开发人员预览:http://docs.oracle.com/javafx/8/3d_graphics/jfxpub-3d_graphics.htm