Question

I'm looking at creating a simple maze game to explore the current 3d capabilities of JavaFX 2 (the version with Java 7).

I can position and rotate rectangles for walls but I can't seem to position on the Z dimension.

See code below. The green wall is in the middle of the left and right walls - how do I move it the the back? Note there is no z() builder property.

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();
    }
}
Was it helpful?

Solution

I believe that calling additional

.translateZ(double x)

on your created Rectangle will fix the problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top