我正在使用 JAVA swing 进行我的个人项目。
该项目是关于在窗口上绘制地图。
该地图可使用仿射变换进行缩放。我在这里遇到的问题是,每当我放大或缩小地图时,地图也会移动,而不是放大/缩小屏幕中心的地图点
private void updateAT()
{
Dimension d = panel.getSize();
int panelW = d.width;
int panelH = d.height;
Rectangle2D r = regionList[0].get("Victoria").getShape().getBounds2D();
scaleX = (panelW/r.getWidth()) * zoom;
scaleY = (panelH/r.getHeight()) * zoom;
AffineTransform goToOrigin = AffineTransform.getTranslateInstance(-r.getMinX(), -r.getMinY());
AffineTransform pan = AffineTransform.getTranslateInstance(panX, panY);
AffineTransform scaleAndFlip = AffineTransform.getScaleInstance(scaleX, -scaleY);
//AffineTransform mirror_y = new AffineTransform(1, 0, 0, -1, 0, panelH);
AffineTransform centre = AffineTransform.getTranslateInstance(panelW/2, panelH/2);
centre.translate(-((r.getWidth()*scaleX)/2), ((r.getHeight()*scaleY)/2));
world2pixel.setToIdentity();
//world2pixel.concatenate(mirror_y);
world2pixel.concatenate(pan);
world2pixel.concatenate(centre);
world2pixel.concatenate(scaleAndFlip);
world2pixel.concatenate(goToOrigin);
}