【发布时间】:2016-10-09 17:31:49
【问题描述】:
我正在尝试获取网格的等距视图。网格只是主场景的一部分,所以我创建了一个子场景,我想给它添加一个相机。我希望能够放大和缩小相机并在所有这些操作中保持视角平移。
这是我没有相机的情况:
public class MyApp extends Application {
@Override
public void start(Stage stage) throws Exception {
Button actionButton = new Button("Placeholder\t\t\t\t\t\t\t\t\t\t\t\t");
HBox hbox = new HBox(actionButton);
BorderPane mainPane = new BorderPane(new MyView(), null, null, hbox, null);
Scene scene = new Scene(mainPane);
stage.setScene(scene);
stage.show();
}
private class MyView extends Group {
MyView() {
super();
GridPane grid = new GridPane();
for (int i = 0; i < 64; i++) {
Rectangle tile = new Rectangle(30, 30, Color.GREEN);
BorderPane pane = new BorderPane(tile);
pane.setBorder(new Border(new BorderStroke(null, BorderStrokeStyle.SOLID,
null, null, null)));
grid.add(pane, i / 8, i % 8);
}
Group root = new Group();
root.getChildren().add(grid);
SubScene scene = new SubScene(root, 300, 300, true, SceneAntialiasing.BALANCED);
scene.setFill(Color.DARKCYAN); // just to see the area
getChildren().add(scene);
}
}
public static void main(String[] args) throws Exception {
launch(args);
}
}
现在我在 MyView 构造函数中添加这样的相机:
Camera camera = new PerspectiveCamera(true);
scene.setCamera(camera);
网格消失了。
我什至还没有做任何转换(我会做camera.getTransforms().addAll(new Rotate(-15, Rotate.Y_AXIS));)。我做错了什么?
另外,我如何告诉子场景占用任何可用空间?我不想指定具体的尺寸,因为程序可以在各种屏幕上运行。
【问题讨论】:
标签: java javafx javafx-8 perspectivecamera