내 응용 프로그램의 요소에 적용 할 올바른 변환 순서를 알아내는 데 문제가 있습니다. app에는 부모/자식 관계가있는 요소가 있으며 각 요소에는 변형이 있습니다 (각 요소는 로컬 공간에 그려지고 변형됩니다).java Affine 올바른 순서 변환
내가 뭘 보관할 것은 내가 그 자식도 변형을하셔야 부모를 변환하는 경우 (당신이 부모를 회전하면 그래서, 아이가 부모 중심으로 회전한다)이다.
아래 코드는 그냥 않습니다하지만 난 부모를 회전 한 후 아이를 이동할 때 문제입니다. 잘못된 방향으로 이동합니다 (상위 변환으로 인해). 나는 변환의 순서를 변경해 보았지만 행운은 없었다. (나는 번역하고 변환해야하지만 부모가 아닌 자신의 축을 중심으로 회전시킨다.
코드 :
Element e;
AffineTransform t = new AffineTransform();
AffineTransform t3 = new AffineTransform();
for (i = 0; i < el.size(); i++)
{
e = el.get(i);
t3.setToIdentity();
t.setToIdentity();
tmp = e.getParent();
while(tmp != null)
{
t.translate(tmp.getX(), tmp.getY());
t3.rotate(Math.toRadians(tmp.getAngle()),tmp.getAnchorX(), tmp.getAnchorY());
tmp = tmp.getParent();
}
t.concatenate(t3);
t.translate(e.getX(), e.getY());
t.rotate(Math.toRadians(e.getAngle()),e.getAnchorX(), e.getAnchorY());
e.draw(g2d,t);
}
문제
: - 주어진 두 개의 요소 (다른 하나의 자식) - 부모 (40도에서) 회전이다 - 아이가 다음 10px 에 의해 이동되고 내가 어떻게 할 수있는 변환을 연결하여 아이를 움직일 때 회전 된 방향으로 움직이지 않습니까?
편집 : Torious는 (아직 작동하지 않습니다) 게시 코드 :
코드의public AffineTransform getTransformTo(Element ancestor) {
AffineTransform t = (AffineTransform)getAffineTransform().clone();
Element parent = getParent();
while (parent != null && parent != ancestor) {
t.preConcatenate(parent.getAffineTransform());
parent = parent.getParent();
}
return t;
}
public void translateInAncestorSpace(Element ancestor, Point translation) {
AffineTransform fromAncestor = getTransformTo(ancestor); // to ancestor space
try
{
fromAncestor.invert();
} catch(Exception e)
{
e.printStackTrace();
}
translation = (Point)fromAncestor.transform(translation, new Point());
Transform t1 = new Transform();
t1.translate(translation.x,translation.y);
transform(t1);
}
출력 :이 같은
Moving by [x=1,y=1] old position [x=22,y=40]
Moved by [x=-21,y=-39] new position [x=1,y=1]
Moving by [x=2,y=2] old position [x=1,y=1]
Moved by [x=1,y=1] new position [x=2,y=2]
Moving by [x=4,y=3] old position [x=2,y=2]
Moved by [x=2,y=1] new position [x=4,y=3]
더 나은 도움을 받으려면 [SSCCE] (http://sscce.org/)를 게시하십시오. BTW - 질문 있니? –