I have 3D scene and I have pane inside the scene which has a rotate transform by x axis, I want to use this pane as strategic game board, but I have problem.
when I enter mouse inside a pane it gives me wrong position of cursor.
For example when I enter mouse from upper left corner(red circle) inside pane(rotated pane with black border) it should shows me (0,0) as cursor position inside the pane, But it shows something like (200 , 400).
How can I solve this problem?
OR in other words, how can I get the mouse coordinate on node relative to node and its transforms?
Here is an example:
import javafx.application.Application;
import javafx.event.EventHandler;
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.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(20, 20, Color.BLUE));
root.getChildren().add(new Circle(20, Color.RED));
//root.rotateProperty().set(30);
root.getTransforms().add(RotateBuilder.create().angle(-30).pivotX(0).pivotY(100).axis(new Point3D(1, 0, 0)).build());
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);
primaryStage.setTitle("Rotation Coordinates Example");
primaryStage.setScene(scene);
scene.setCamera(PerspectiveCameraBuilder.create().fieldOfView(10).build());
primaryStage.show();
}
public static void main(String[] args){
Application.launch(args);
}
}