Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8096996

Seems the MouseEvent getX() and getY() are returned incorrectly when using PerspectiveCamera(true) and dragging over objects in a scene

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P3 P3
    • 8u20
    • 8
    • javafx
    • Windows 7
      java version "1.8.0-ea"
      Java(TM) SE Runtime Environment (build 1.8.0-ea-b120)
      Java HotSpot(TM) 64-Bit Server VM (build 25.0-b62, mixed mode)
      NetBeans IDE 7.4 (Build 201310111528)

      I can't seem to find a way to get the version of 2.2.45 so I selected the highest released version, because I downloaded the latest JDK. All the methods explaining on how to get the version on forums are probably for the previous JavaFX

      I posted this on StackOverflow
      http://stackoverflow.com/questions/20918835/using-javafx-moleculesampleapp-as-a-starting-point-when-rotating-camera-left-be

      I am using the MouseDragged event handler and I get the X and Y coordinates from the event using getX() and getY()

      When I move over different objects in the scene the X and Y jump to that object's X and Y it seems. I believe it might be a bug in PerspectiveCamera when constructing it with a true. Further down I also added a small application to test this

      ###Test 1###
      This is the scene
      http://www.flickr.com/photos/92380311@N04/11792509775/

      Clicked on the main object and dragged left over to the bracelet. The numbers with stars show how the Y position just jumped. The target is still the same object that I started on

          X 35.567406068202395 Y 8.69569231620082 target Gizmo@24cce2f source javafx.scene.Scene@6a4dbcfe
          X 36.666015897358335 Y 12.518175916732801 target Gizmo@24cce2f source javafx.scene.Scene@6a4dbcfe
          **X 35.768187104194766 Y 8.806935956274785 target Gizmo@24cce2f source javafx.scene.Scene@6a4dbcfe
          **X 32.783125546287856 Y -1.6894216815835534 target Gizmo@24cce2f source javafx.scene.Scene@6a4dbcfe
          X 32.90862938248895 Y -1.9394236965586344 target Gizmo@24cce2f source javafx.scene.Scene@6a4dbcfe
          X 33.064687701440796 Y -2.087600004540633 target Gizmo@24cce2f source javafx.scene.Scene@6a4dbcfe
          X 33.2336308187289 Y -2.192578553217487 target Gizmo@24cce2f source javafx.scene.Scene@6a4dbcfe
          X 33.59877252681704 Y -2.312234988436174 target Gizmo@24cce2f source javafx.scene.Scene@6a4dbcfe

      ###Test 2###
      I started on the build area object and moved off it onto the scene background

          X 21.456177104447363 Y -117.68464016083907 target BuildArea@1d6a248a source javafx.scene.Scene@6a4dbcfe
          **X 21.441637105907176 Y -117.92347930756549 target BuildArea@1d6a248a source javafx.scene.Scene@6a4dbcfe
          **X 88.73924430219023 Y 283.32754251664767 target BuildArea@1d6a248a source javafx.scene.Scene@6a4dbcfe
          X 88.74685283528898 Y 282.60100768422694 target BuildArea@1d6a248a source javafx.scene.Scene@6a4dbcfe


      I wrote a little test app to test this.

          import javafx.application.Application;
          import javafx.event.ActionEvent;
          import javafx.event.EventHandler;
          import javafx.scene.PerspectiveCamera;
          import javafx.scene.Scene;
          import javafx.scene.control.Button;
          import javafx.scene.input.MouseEvent;
          import javafx.scene.layout.StackPane;
          import javafx.scene.shape.Box;
          import javafx.stage.Stage;
          
          public class TestObjectDrag extends Application {
          // private final PerspectiveCamera camera = new PerspectiveCamera(false);
              private final PerspectiveCamera camera = new PerspectiveCamera(true);
          // private final double cameraDistance = -55;
              private final double cameraDistance = 355;
              
              @Override
              public void start(Stage primaryStage) {
                  camera.setNearClip(0.1);
                  camera.setFarClip(10000.0);
          // camera.setTranslateX(-150);
          // camera.setTranslateY(-125);
                  camera.setTranslateZ(-cameraDistance);
                  final Box box = new Box(240.0, 10, 10);
                  Button btn = new Button("Long text");
                  StackPane root = new StackPane();
                  root.getChildren().addAll(btn, box, camera);
                  root.setOnMouseDragged(new EventHandler<MouseEvent>() {
                      @Override
                      public void handle(MouseEvent me) {
                          System.out.println("X " + me.getX() + " Y " + me.getY() + " target " + me.getTarget() + " source " + me.getSource());
                      }
                  });
                  
                  Scene scene = new Scene(root, 300, 250);
                  scene.setCamera(camera);
                  
                  primaryStage.setTitle("Hello World!");
                  primaryStage.setScene(scene);
                  primaryStage.show();
              }
          
              public static void main(String[] args) {
                  launch(args);
              }

      ###Test 3###
      First I switched off scene.setCamera(camera); and the numbers where fine when I started at the stackpane and moved over the button and the box

          X 177.0 Y 107.0 target StackPane@5045cf52[styleClass=root] source StackPane@5045cf52[styleClass=root]
          X 177.0 Y 108.0 target StackPane@5045cf52[styleClass=root] source StackPane@5045cf52[styleClass=root]
          X 177.0 Y 109.0 target StackPane@5045cf52[styleClass=root] source StackPane@5045cf52[styleClass=root]
          X 177.0 Y 110.0 target StackPane@5045cf52[styleClass=root] source StackPane@5045cf52[styleClass=root]
          X 177.0 Y 111.0 target StackPane@5045cf52[styleClass=root] source StackPane@5045cf52[styleClass=root]
          X 177.0 Y 112.0 target StackPane@5045cf52[styleClass=root] source StackPane@5045cf52[styleClass=root]
          X 177.0 Y 113.0 target StackPane@5045cf52[styleClass=root] source StackPane@5045cf52[styleClass=root]
          X 177.0 Y 114.0 target StackPane@5045cf52[styleClass=root] source StackPane@5045cf52[styleClass=root]
          X 177.0 Y 115.0 target StackPane@5045cf52[styleClass=root] source StackPane@5045cf52[styleClass=root]
          X 177.0 Y 116.0 target StackPane@5045cf52[styleClass=root] source StackPane@5045cf52[styleClass=root]
          X 177.0 Y 117.0 target StackPane@5045cf52[styleClass=root] source StackPane@5045cf52[styleClass=root]
          X 177.0 Y 118.0 target StackPane@5045cf52[styleClass=root] source StackPane@5045cf52[styleClass=root]
          X 177.0 Y 119.0 target StackPane@5045cf52[styleClass=root] source StackPane@5045cf52[styleClass=root]
          X 177.0 Y 120.0 target StackPane@5045cf52[styleClass=root] source StackPane@5045cf52[styleClass=root]
          X 177.0 Y 121.0 target StackPane@5045cf52[styleClass=root] source StackPane@5045cf52[styleClass=root]
          X 178.0 Y 121.0 target StackPane@5045cf52[styleClass=root] source StackPane@5045cf52[styleClass=root]
          X 178.0 Y 122.0 target StackPane@5045cf52[styleClass=root] source StackPane@5045cf52[styleClass=root]
          X 178.0 Y 123.0 target StackPane@5045cf52[styleClass=root] source StackPane@5045cf52[styleClass=root]
          X 178.0 Y 124.0 target StackPane@5045cf52[styleClass=root] source StackPane@5045cf52[styleClass=root]

      ###Test 4###
      I switched the scene camera on, but with false in the constructor of the camera and I changed the distance to 55 so that it is easier to work with and moved the camera -150 on X and -125 on Y. I don't get any jumping of numbers

          X 177.34517301523948 Y 139.11363768528489 target StackPane@1b7e2718[styleClass=root] source StackPane@1b7e2718[styleClass=root]
          X 177.34517301523948 Y 138.2315353299546 target StackPane@1b7e2718[styleClass=root] source StackPane@1b7e2718[styleClass=root]
          X 177.34517301523948 Y 137.34943297462428 target StackPane@1b7e2718[styleClass=root] source StackPane@1b7e2718[styleClass=root]
          X 177.34517301523948 Y 136.467330619294 target StackPane@1b7e2718[styleClass=root] source StackPane@1b7e2718[styleClass=root]
          X 178.2272753705698 Y 136.467330619294 target StackPane@1b7e2718[styleClass=root] source StackPane@1b7e2718[styleClass=root]
          X 178.22727537056977 Y 135.58522826396367 target StackPane@1b7e2718[styleClass=root] source StackPane@1b7e2718[styleClass=root]
          X 178.2272753705698 Y 134.70312590863335 target StackPane@1b7e2718[styleClass=root] source StackPane@1b7e2718[styleClass=root]
          X 178.2272753705698 Y 133.82102355330306 target StackPane@1b7e2718[styleClass=root] source StackPane@1b7e2718[styleClass=root]
          X 179.10937772590012 Y 133.82102355330306 target StackPane@1b7e2718[styleClass=root] source StackPane@1b7e2718[styleClass=root]
          X 179.1093777259001 Y 132.93892119797275 target StackPane@1b7e2718[styleClass=root] source StackPane@1b7e2718[styleClass=root]
          X 179.10937772590012 Y 132.05681884264246 target StackPane@1b7e2718[styleClass=root] source StackPane@1b7e2718[styleClass=root]
          X 179.1093777259001 Y 131.17471648731214 target StackPane@1b7e2718[styleClass=root] source StackPane@1b7e2718[styleClass=root]
          X 179.10937772590012 Y 130.29261413198185 target StackPane@1b7e2718[styleClass=root] source StackPane@1b7e2718[styleClass=root]
          X 178.755684791891 Y 129.3569219381653 target StackPane@1b7e2718[styleClass=root] source StackPane@1b7e2718[styleClass=root]
          X 178.755684791891 Y 128.48553755053226 target StackPane@1b7e2718[styleClass=root] source StackPane@1b7e2718[styleClass=root]
          X 178.755684791891 Y 127.61415316289919 target StackPane@1b7e2718[styleClass=root] source StackPane@1b7e2718[styleClass=root]
          X 178.755684791891 Y 126.74276877526613 target StackPane@1b7e2718[styleClass=root] source StackPane@1b7e2718[styleClass=root]
          X 178.755684791891 Y 125.87138438763306 target StackPane@1b7e2718[styleClass=root] source StackPane@1b7e2718[styleClass=root]
          X 178.755684791891 Y 125.0 target StackPane@1b7e2718[styleClass=root] source StackPane@1b7e2718[styleClass=root]
          X 178.755684791891 Y 124.12861561236694 target StackPane@1b7e2718[styleClass=root] source StackPane@1b7e2718[styleClass=root]
          X 178.755684791891 Y 123.25723122473387 target StackPane@1b7e2718[styleClass=root] source StackPane@1b7e2718[styleClass=root]
          X 178.755684791891 Y 122.38584683710081 target StackPane@1b7e2718[styleClass=root] source StackPane@1b7e2718[styleClass=root]
          X 178.755684791891 Y 121.51446244946776 target StackPane@1b7e2718[styleClass=root] source StackPane@1b7e2718[styleClass=root]
          X 178.755684791891 Y 120.6430780618347 target StackPane@1b7e2718[styleClass=root] source StackPane@1b7e2718[styleClass=root]
          X 179.10937772590012 Y 119.70738586801816 target StackPane@1b7e2718[styleClass=root] source StackPane@1b7e2718[styleClass=root]
          X 179.1093777259001 Y 118.82528351268786 target StackPane@1b7e2718[styleClass=root] source StackPane@1b7e2718[styleClass=root]
          X 179.10937772590012 Y 117.94318115735756 target StackPane@1b7e2718[styleClass=root] source StackPane@1b7e2718[styleClass=root]
          X 179.1093777259001 Y 117.06107880202724 target StackPane@1b7e2718[styleClass=root] source StackPane@1b7e2718[styleClass=root]
          X 179.10937772590012 Y 116.17897644669694 target StackPane@1b7e2718[styleClass=root] source StackPane@1b7e2718[styleClass=root]
          X 179.10937772590012 Y 115.29687409136663 target StackPane@1b7e2718[styleClass=root] source StackPane@1b7e2718[styleClass=root]
          X 179.10937772590012 Y 114.41477173603633 target StackPane@1b7e2718[styleClass=root] source StackPane@1b7e2718[styleClass=root]
          X 179.1093777259001 Y 113.53266938070603 target StackPane@1b7e2718[styleClass=root] source StackPane@1b7e2718[styleClass=root]
          X 179.10937772590012 Y 112.65056702537572 target StackPane@1b7e2718[styleClass=root] source StackPane@1b7e2718[styleClass=root]
          X 179.10937772590012 Y 111.7684646700454 target StackPane@1b7e2718[styleClass=root] source StackPane@1b7e2718[styleClass=root]
          X 178.755684791891 Y 111.05784979787103 target StackPane@1b7e2718[styleClass=root] source StackPane@1b7e2718[styleClass=root]
          X 178.755684791891 Y 110.18646541023796 target StackPane@1b7e2718[styleClass=root] source StackPane@1b7e2718[styleClass=root]
          X 178.755684791891 Y 109.3150810226049 target StackPane@1b7e2718[styleClass=root] source StackPane@1b7e2718[styleClass=root]
          X 178.755684791891 Y 108.44369663497184 target StackPane@1b7e2718[styleClass=root] source StackPane@1b7e2718[styleClass=root]
          X 178.755684791891 Y 107.57231224733877 target StackPane@1b7e2718[styleClass=root] source StackPane@1b7e2718[styleClass=root]
          X 178.755684791891 Y 106.70092785970571 target StackPane@1b7e2718[styleClass=root] source StackPane@1b7e2718[styleClass=root]


      ###Test 5###
      I created PerspectiveCamera with true, changed the camera distance and switched off moving of the camera. I started at the stackpane and moved over the box. The X jumped

          X 150.0 Y 125.0 target StackPane@2352cffe[styleClass=root] source StackPane@2352cffe[styleClass=root]
          X 150.0 Y 125.0 target StackPane@2352cffe[styleClass=root] source StackPane@2352cffe[styleClass=root]
          X 150.0 Y 125.0 target StackPane@2352cffe[styleClass=root] source StackPane@2352cffe[styleClass=root]
          **X 150.0 Y 125.0 target StackPane@2352cffe[styleClass=root] source StackPane@2352cffe[styleClass=root]
          **X 186.76262920155003 Y 120.49845356715714 target StackPane@2352cffe[styleClass=root] source StackPane@2352cffe[styleClass=root]
          X 187.5128869403572 Y 120.49845356715714 target StackPane@2352cffe[styleClass=root] source StackPane@2352cffe[styleClass=root]
          X 187.5128869403572 Y 121.24871130596428 target StackPane@2352cffe[styleClass=root] source StackPane@2352cffe[styleClass=root]
          X 187.51288694035716 Y 121.99896904477143 target StackPane@2352cffe[styleClass=root] source StackPane@2352cffe[styleClass=root]
          X 187.5128869403572 Y 122.74922678357856 target StackPane@2352cffe[styleClass=root] source StackPane@2352cffe[styleClass=root]
          X 187.51288694035716 Y 123.49948452238571 target StackPane@2352cffe[styleClass=root] source StackPane@2352cffe[styleClass=root]
          X 187.51288694035716 Y 124.24974226119285 target StackPane@2352cffe[styleClass=root] source StackPane@2352cffe[styleClass=root]
          X 187.5128869403572 Y 125.0 target StackPane@2352cffe[styleClass=root] source StackPane@2352cffe[styleClass=root]
          X 187.51288694035716 Y 125.75025773880715 target StackPane@2352cffe[styleClass=root] source StackPane@2352cffe[styleClass=root]
          X 187.51288694035716 Y 126.50051547761429 target StackPane@2352cffe[styleClass=root] source StackPane@2352cffe[styleClass=root]
          X 187.5128869403572 Y 127.25077321642144 target StackPane@2352cffe[styleClass=root] source StackPane@2352cffe[styleClass=root]
          X 187.51288694035716 Y 128.00103095522857 target StackPane@2352cffe[styleClass=root] source StackPane@2352cffe[styleClass=root]
          X 187.5128869403572 Y 128.7512886940357 target StackPane@2352cffe[styleClass=root] source StackPane@2352cffe[styleClass=root]
          **X 187.5128869403572 Y 129.50154643284287 target StackPane@2352cffe[styleClass=root] source StackPane@2352cffe[styleClass=root]
          **X 150.0 Y 125.0 target StackPane@2352cffe[styleClass=root] source StackPane@2352cffe[styleClass=root]
          X 150.0 Y 125.0 target StackPane@2352cffe[styleClass=root] source StackPane@2352cffe[styleClass=root]
          X 150.0 Y 125.0 target StackPane@2352cffe[styleClass=root] source StackPane@2352cffe[styleClass=root]
          X 150.0 Y 125.0 target StackPane@2352cffe[styleClass=root] source StackPane@2352cffe[styleClass=root]
          X 150.0 Y 125.0 target StackPane@2352cffe[styleClass=root] source StackPane@2352cffe[styleClass=root]
          X 150.0 Y 125.0 target StackPane@2352cffe[styleClass=root] source StackPane@2352cffe[styleClass=root]

            msladecek Martin Sládeček
            ktoitjfx Kobus du Toit (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: