我是在 Java Swing 上旋转和翻译形状的命令模式翻译和旋转可以分开工作,但是当我做 60 度时。旋转然后平移,平移跟随新的旋转坐标。这意味着如果我拖动鼠标,形状与鼠标运动矢量之间的间隙为 60 度,有什么简单的解决方案吗?请帮忙,我在这里撞墙
我的旋转执行方法
public void execute() {
System.out.println("command: rotate " + thetaDegrees );
Iterator iter = objects.iterator();
Shape shape;
while(iter.hasNext()){
shape = (Shape)iter.next();
mt.addMememto(shape);
AffineTransform t = shape.getAffineTransform();
t.rotate(Math.toRadians(thetaDegrees), shape.getCenter().x, shape.getCenter().y);
shape.setAffineTransform(t);
}
}
我的翻译执行方法
public void execute() {
Iterator iter = objects.iterator();
Shape shape;
while(iter.hasNext()){
shape = (Shape)iter.next();
mt.addMememto(shape);
AffineTransform t = shape.getAffineTransform();
System.out.println("Translation x :"+x + ", Translation y :"+y);
t.translate(x,y);
shape.setAffineTransform(t);
}
}
任何帮助都将不胜感激