当尝试在javafx中创建第一人称相机时,我尝试使用相机的平移坐标将rotationAxis设置为新的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);
}
}发布于 2021-09-27 13:03:09
我们更新它已经有一段时间了,但它应该会让你开始使用它。
https://stackoverflow.com/questions/69339243
复制相似问题