在透视变换后找不到与 JavaFx 形状的碰撞

Can't find collision with JavaFx shape afrer perspective transform

我有一组具有动态计算的透视变换(通过拖放应用)的矩形(或多边形)。问题是在这个变换之后矩形的坐标不是最新的,我找不到与汽车中心的碰撞。 zones

正如您在图片上看到的那样,错误的区域是绿色的,因为在拖放矩形之前位于 imageVeiw 的左上角。

这里是我试图找到碰撞的方法:

  rectGrpoup.getChildren().forEach(child -> {
        final Predicate<Car> carInZone = car -> {
            final Bounds boundsInLocal = mainController.getImageView().getBoundsInLocal();
            //different image size when detect and display
            Point fixedScalePoint = scaleService.fixScale(new Point(car.getLastCenter()), screenSize, new ScreenSize(boundsInLocal.getHeight(), boundsInLocal.getWidth()));
            //I need help in next line
            return Shape.intersect((Rectangle) child, new Rectangle(fixedScalePoint.getX(), fixedScalePoint.getY(), 10, 10)).getBoundsInLocal().getWidth() != -1;
        };

        if (cars.stream().anyMatch(carInZone)) {
          child.setFill(Color.GREEN);
          } else {
          child.setFill(Color.RED);
        }
    });

其中 child 是组中的矩形(或者我可以重构为多边形)。 Child 在转换之前有坐标,所以 predicate 不起作用。

Presentation of program work

p.s。如果有帮助,我可以提供任何代码

JavaFX 中的 PerspectiveTransform 实际上扩展了 class 效果,与实际转换(e.x。旋转)没有任何相似之处。

和class的jdoc中描述的主要区别:

Note that this effect does not adjust the coordinates of input events or any methods that measure containment on a {@code Node}. The results of mouse picking and the containment methods are undefined when a {@code Node} has a {@code PerspectiveTransform} effect in place.

这意味着可以直观地显示您的形状变化,但不会更新坐标。

其他解决方案:

  • 使用真正的 3D,e.x。 - 与 PerspectiveCamera
  • 达到相同的效果
  • 通过旋转和缩放等真实变换获得相同效果