在 JavaFX 中创建第一人称相机

Create a first person camera in JavaFX

尝试在 javafx 中创建第一人称相机时,我尝试将 rotationAxis 设置为具有相机转换坐标的新 Point3D。 那没有用,所以我开始在 Whosebug 上搜索,因为我最近才安装 javafx 我还不太适应它,因此不知道如何尝试解决这个问题。 无论如何,我发现了以下与此事有关的话题:

但是,如果我复制此代码并实施建议的修复,我仍然没有获得合适的第一人称相机,因此非常感谢任何帮助。

下面是演示问题的简单示例代码。

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);
    }
}

https://github.com/FXyz/FXyz/blob/master/FXyz-Core/src/main/java/org/fxyz3d/scene/SimpleFPSCamera.java

我们更新它已经有一段时间了,但它应该能让你入门。