So I've been trying to use the yaw and pitch concept, and I've tried adjusting the angle by the change in x and y. Unfortunately, the angle of the camera sometimes goes out of bounds, and I've bothered to add in controls for the angle measurements. What am I doing wrong?
public class Main extends Application {
private Group group;
private Scene scene;
private double oldX;
private double oldY;
private double newX;
private double newY;
private double dx;
private double dy;
private Rotate yaw;
private Rotate pitch;
private double xSen = 800;
private double ySen = 600;
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
group = new Group();
scene = new Scene(group, 800, 600);
primaryStage.setScene(scene);
primaryStage.show();
yaw = new Rotate(0, Rotate.Y_AXIS);
pitch = new Rotate(0, Rotate.X_AXIS);
Box box = new Box(5, 5, 5);
box.setMaterial(new PhongMaterial(Color.BLUE));
box.setTranslateZ(40);
group.getChildren().add(box);
PerspectiveCamera camera = new PerspectiveCamera(true);
camera.getTransforms().addAll(yaw, pitch);
scene.setCamera(camera);
xSen = 1;
ySen = 1;
scene.setOnKeyPressed(event -> {
switch (event.getCode()) {
case A:
xSen -= 1;
break;
case D:
xSen += 1;
break;
default:
break;
}
System.out.println(xSen + " " + ySen);
});
scene.setOnMouseMoved(event -> {
oldX = newX;
oldY = newY;
newX = event.getX();
newY = event.getY();
dx = oldX - newX;
dy = oldY - newY;
?
});
}
}