我正在开发一个程序,在该程序中我同时缩放并围绕一个锚点旋转。我是这样做的:
但是,我似乎无法将原点放回(0,0)。这是我的代码:
System.out.println(currentTransform.getTranslateX() + ", " + currentTransform.getTranslateY());
currentTransform.translate(anchorPoint.x, anchorPoint.y);
currentTransform.rotate(Math.toRadians(-deltaAngle));
currentTransform.scale(scaleFactor, scaleFactor);
System.out.println(currentTransform.getTranslateX() + ", " + currentTransform.getTranslateY());
currentTransform.translate(-anchorPoint.x, -anchorPoint.y);
System.out.println(currentTransform.getTranslateX() + ", " + currentTransform.getTranslateY());
我第一次运行此代码时,输出结果为:
0.0,0.0
109.0,85.0
0.2508035970521405,-1.415126056974529
任何后续运行都会在启动时显示相同的剩余翻译。
我需要做些什么才能将翻译恢复为0?
修改
即使我用行currentTransform.translate(-currentTransform.getTranslateX(), -currentTransform.getTranslateY());
代替currentTransform.translate(-anchorPoint.x, -anchorPoint.y);