2

看起来Transform类中JavaFX包含 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);

    }


}
4

1 回答 1

3

JavaFX 2 一开始就考虑到了 3D,因此很多 API 都提到了 z 坐标。但实际上有用的 3D 仅在 JavaFX8 中添加(将于明年发布)。

您可以在此处查看文档:http: //docs.oracle.com/javafx/8/3d_graphics/jfxpub-3d_graphics.htm并尝试开发人员预览:https ://jdk8.java.net/download.html

于 2013-11-08T18:44:38.910 回答