0
我想獲得一個網格的等距視圖。網格只是主場景的一部分,所以我創建了一個子場景,並且我想爲它添加一個相機。我希望能夠在所有這些操作過程中縮放相機,並保持視角。如何在SubScene中設置和變換攝像機?
這是我有沒有攝像頭:
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));
)。我究竟做錯了什麼?
另外,我怎麼能告訴子領域採取任何可用的空間?我不想指定具體的大小,因爲程序可以在各種屏幕上運行。