
Originally Posted by
wysota
Sure it does.
Thanks for the detailed answer.
I'm not getting the map() method to give me anywhere near the right values. I'm using a QTransform to translate the origin by the inverse of the rotation point, rotating, translating back, then offsetting by the aforementioned difference in the image centers. I then compare the values to the ones from the ones coming out of my existing method that I know works, and its not even in the same ballpark.
Maybe its some error in my code, but like I said, I already have a method that works, so I don't really see the point in investigating further.
{
qreal dist
= QLineF(anchor, center
).
length();
qreal a = qAtan2(anchor.y() - center.y(), anchor.x() - center.x());
QPointF rotAnchor
(qCos
(rot
+ a
) * dist, qSin
(rot
+ a
) * dist
);
rotAnchor += center;
QPixmap rotImage
= image.
transformed(QTransform
().
rotateRadians(rot
));
QPointF rotCenter
= QPointF(rotImage.
width() / 2, rotImage.
height() / 2);
QPointF offset
= rotCenter
- center;
origin = pos - (rotAnchor + offset);
return rotImage;
}
QPixmap getTransformedImage(QPixmap image, QPointF pos, QPointF anchor, qreal rot, QPointF &origin)
{
QPointF center = QPointF(image.width() / 2, image.height() / 2);
qreal dist = QLineF(anchor, center).length();
qreal a = qAtan2(anchor.y() - center.y(), anchor.x() - center.x());
QPointF rotAnchor(qCos(rot + a) * dist, qSin(rot + a) * dist);
rotAnchor += center;
QPixmap rotImage = image.transformed(QTransform().rotateRadians(rot));
QPointF rotCenter = QPointF(rotImage.width() / 2, rotImage.height() / 2);
QPointF offset = rotCenter - center;
origin = pos - (rotAnchor + offset);
return rotImage;
}
To copy to clipboard, switch view to plain text mode
Bookmarks