2

I'm currently trying to rotate a Perspective Camera around a pivot point (0,0,0) however I'm getting undesirable results. The camera itself is rotating its view rather than translating the camera.

I would therefore like it to always look towards the pivot point (0,0,0) and translate itself around that point.

Currently, I'm seeing this behaviour translating in the Z axis:

Z Axis

And this in the Y Axis:

Y Axis

Code:

private Rotate rotation;
private Translate pivot;
Camera camera = new PerspectiveCamera(true);

pivot = new Translate(0,0,0);

stage.addEventHandler(KeyEvent.KEY_PRESSED, event -> {
        if(event.getCode() == KeyCode.A){
            rotation = new Rotate(-1, 0,0,0, Rotate.Z_AXIS);
        }
        if(event.getCode() == KeyCode.D){
            rotation = new Rotate(1, 0,0,0, Rotate.Z_AXIS);
        }
        if(event.getCode() == KeyCode.W){
            rotation = new Rotate(-1, pivot.getX(), pivot.getY(), pivot.getZ(), Rotate.Y_AXIS);
        }
        if(event.getCode() == KeyCode.S){
            rotation = new Rotate(1, pivot.getX(), pivot.getY(), pivot.getZ(), Rotate.Y_AXIS);
        }
        camera.getTransforms().add(rotation);
        System.out.println("Camera: x"+camera.getTranslateX()+" y:"+camera.getTranslateY()+" z:"+camera.getTranslateZ());
    });
jameslfc19
  • 1,084
  • 1
  • 10
  • 14

0 Answers0