0

我正在考虑创建一个简单的迷宫游戏来探索 JavaFX 2(Java 7 的版本)当前的 3d 功能。

我可以定位和旋转墙壁的矩形,但我似乎无法在 Z 维度上定位。

请参阅下面的代码。绿墙在左右墙的中间 - 我如何将它移到后面?请注意,没有 z() 构建器属性。

public final class Walls extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage stage) {
        stage.setTitle("Walls in perspective");
        stage.setScene(makeScene());
        stage.show();
    }

    private Scene makeScene() {
        return SceneBuilder.create()
                .width(500)
                .height(500)
                .root(createRoot())
                .camera(PerspectiveCameraBuilder.create().build())
                .depthBuffer(true)
                .build();
    }

    private Parent createRoot() {
        // left wall
        Rectangle node1 = RectangleBuilder.create()
                .x(-200)
                .y(-150)
                .width(200)
                .height(200)
                .fill(Color.RED)
                .rotate(90)
                .rotationAxis(Rotate.Y_AXIS)
                .build();

        // back wall?
        Rectangle node2 = RectangleBuilder.create()
                .x(-100)
                .y(-150)
                .width(200)
                .height(200)
                .fill(Color.GREEN)
                .opacity(0.5)
                .build();

        // right wall
        Rectangle node3 = RectangleBuilder.create()
                .x(0)
                .y(-150)
                .width(200)
                .height(200)
                .fill(Color.BLUE)
                .rotate(90)

                .rotationAxis(Rotate.Y_AXIS)
                .build();

        return GroupBuilder.create()
                .children(node1, node2, node3)
                .translateX(250)
                .translateY(250)
                //.depthTest() ?
                .build();
    }
}
4

1 回答 1

1

我相信调用额外的

.translateZ(double x)

在您创建的 Rectangle 上将解决问题。

于 2013-01-21T14:28:10.883 回答