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

MouseEvent X/Y Coordinates Don't Account for Rotation modifying Z

    XMLWordPrintable

Details

    Description

      When a rotation modifies the Z position of a node (a 3D rotation not around the Z-Axis), the reported X/Y coordinates in Mouse Events do not take into account the Z position change.

      For example, if the rotation is on the X-Axis, the X/Y coordinates when hovering on the Stage's (20,20) will always report (20,20) on the node (regardless of the amount of rotation). We would expect the Event to report the coordinates relative to the transformed node (as it does when rotating on the Z-Axis)

      import javafx.application.Application;
      import javafx.event.EventHandler;
      import javafx.geometry.Point3D;
      import javafx.scene.PerspectiveCamera;
      import javafx.scene.Scene;
      import javafx.scene.input.MouseEvent;
      import javafx.scene.layout.VBox;
      import javafx.scene.paint.Color;
      import javafx.scene.shape.Circle;
      import javafx.scene.shape.Rectangle;
      import javafx.scene.transform.Rotate;
      import javafx.scene.transform.RotateBuilder;
      import javafx.stage.Stage;


      public class JFXRotationXOrds extends Application{

      @Override
      public void start(Stage primaryStage) throws Exception {
      VBox root = new VBox();
      root.getChildren().add(new Rectangle(100, 100, Color.BLUE));
      root.getChildren().add(new Circle(20, Color.RED));
      final Rotate rotate = RotateBuilder.create().angle(80).pivotX(100).pivotY(100).pivotZ(0).axis(new Point3D(1,0,0)).build();
      root.getTransforms().add(rotate);
      root.setStyle("-fx-border-color: black; -fx-border-width:5; ");

      root.setOnMouseMoved(new EventHandler<MouseEvent>() {
      @Override
      public void handle(MouseEvent arg0) {
      if(arg0.getEventType() == MouseEvent.MOUSE_MOVED){
      System.out.println(arg0.getX() + "," + arg0.getY());
      }
      }
      });

      Scene scene = new Scene(root, 200, 500);
      PerspectiveCamera camera = new PerspectiveCamera();
      scene.setCamera(camera);
      primaryStage.setTitle("BorderPane Example");
      primaryStage.setScene(scene);
      primaryStage.show();

      }

      public static void main(String[] args){
      Application.launch(args);
      }
      }

      Attachments

        Activity

          People

            psafrata Pavel Ĺ afrata
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported: