在尝试在 javafx 中创建第一人称相机时,我尝试使用相机的平移坐标将旋转轴设置为新的 Point3D。 这不起作用,所以我开始在 stackoverflow 上搜索,因为我最近才安装了 javafx,我对它还不太满意,因此不知道如何尝试解决问题。 不管怎样,我发现了以下关于此事的线索:
How would I make a first person camera in JavaFX 3D?
但是,如果我复制此代码并实现建议的修复,我仍然无法获得合适的第一人称相机,因此我们将不胜感激。
下面是演示该问题的简单示例代码。
package application;
import javafx.application.Application;
import javafx.scene.PerspectiveCamera;
import javafx.scene.Scene;
import javafx.scene.SubScene;
import javafx.scene.control.Slider;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.paint.PhongMaterial;
import javafx.scene.shape.Box;
import javafx.scene.transform.Rotate;
import javafx.stage.Stage;
public class Main extends Application {
BorderPane pane = new BorderPane();
Box box = new Box(150, 150, 600);
SubScene sub = new SubScene(new Pane(box), 600, 600);
PhongMaterial mat = new PhongMaterial(Color.RED);
PerspectiveCamera cam = new PerspectiveCamera();
@Override
public void start(Stage stage) throws Exception {
sub.setCamera(cam);
cam.setRotationAxis(Rotate.Y_AXIS);
box.setMaterial(mat);
box.setManaged(false);
box.setTranslateX(300);
box.setTranslateY(300);
box.setRotationAxis(Rotate.X_AXIS);
box.setTranslateZ(100);
stage.setScene(new Scene(pane));
stage.sizeToScene();
Slider slider1 = new Slider();
slider1.valueProperty().bindBidirectional(cam.rotateProperty());
pane.setCenter(sub);
pane.setBottom(slider1);
stage.centerOnScreen();
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
最佳答案
我们已经有一段时间没有更新它了,但它应该可以帮助您入门。
关于java - 在 JavaFX 中创建第一人称相机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69339243/