我有一个3D场景,场景内有一个带有沿x轴旋转变换的面板,我想将此面板用作策略游戏棋盘,但遇到了问题。
当我将鼠标移动到面板内时,它会给出错误的光标位置。
例如,当我从面板的左上角(红色圆圈)进入面板(带有黑色边框的旋转面板)时,应在面板内显示(0,0)的光标位置,但实际上它显示的是类似于(200,400)的数字。
如何解决这个问题?
或者说,如何相对于节点和其转换得到节点上的鼠标坐标?
以下是一个示例:
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);
}
}