0

I have a few problems with this. Essentially, I want to be able to specify a point to a scale and zoom into that point. When the point is constant, it works perfectly. However, when the point changes, the first time I change the scale the camera "jumps". I also have noticed that the coordinate of the camera no longer represents the top left corner, but when I go back to the original scale it does. Is there any way to fix these two issues?

public class CameraTest extends Application {
    ParallelCamera camera = new ParallelCamera();
    Scale scale = new Scale();
    Group world = new Group();
    SubScene subScene = new SubScene(world, 480, 720);
    Group root = new Group();
    Scene scene = new Scene(root);

    double orthoScale = 1;

    @Override
    public void start(Stage stage) throws Exception {
        Rectangle floor = new Rectangle(100, 0, 200, 200);
        floor.setTranslateZ(300);
        floor.setFill(Color.ALICEBLUE);
        floor.setRotationAxis(new Point3D(1,0,0));
        floor.setRotate(90);
        world.getChildren().add(floor);

        camera.setTranslateY(100);
        camera.setRotationAxis(Rotate.X_AXIS);
        camera.setRotate(90);
        camera.getTransforms().add(scale);

        subScene.setOnScroll(event -> {
            orthoScale -= event.getDeltaY() / 70;

            scale.setPivotX(event.getX());
            scale.setPivotY(event.getY());
            scale.setX(orthoScale);
            scale.setY(orthoScale);
            scale.setZ(orthoScale);

            System.out.println(orthoScale);
        });

        subScene.setCamera(camera);
        subScene.setFill(Color.LIGHTGREY);
        root.getChildren().add(subScene);
        stage.setScene(scene);
        stage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}
  • 1
    Post a [mcve].. – user1803551 Aug 08 '18 at 23:42
  • 1
    @user1803551 I uploaded new code that I just wrote which reproduces my error – Ben Esposito Aug 09 '18 at 12:27
  • 1
    "*I also have noticed that the coordinate of the camera no longer represents the top left corner, but when I go back to the original scale it does.*" The top left corner for me is always (0,0). How did you check this? – user1803551 Aug 09 '18 at 14:20
  • 1
    As for the pivot issue, see [here](https://stackoverflow.com/questions/27356577/scale-at-pivot-point-in-an-already-scaled-node) and [here](https://stackoverflow.com/questions/29506156/javafx-8-zooming-relative-to-mouse-pointer). – user1803551 Aug 09 '18 at 14:30

0 Answers0