[Qt-interest] QTransform SRT order (bug?) (fwd)
Joshua Grauman
jnfo-c at grauman.com
Tue Jun 7 08:11:15 CEST 2011
Just for the record, this does seem to be a clear bug. Can someone confirm? It
is doing the operations (scale and rotate in this case) in reverse order. If
you swap the order of operations, you get the expected result, and visa-verca.
I got the same (incorrect) result with both Qt 4.7.1 and the 4.8tp... Thanks.
Josh
> Maybe someone can help clarify for me, but this seems like a bug to me.
> Here's a complete Qt program. I do a scale first, and then a rotate. I start
> with a square, and then scale it to a rectangle. After I rotate it though,
> the angles are clearly not at 90 degrees. I would have assumed that I was
> just rotating my rectangle. What's going on here? Is this a bug? Thanks!
>
> Josh
>
> #include <QImage>
> #include <QPainter>
> #include <QTransform>
> #include <QRect>
>
> int main(int argc, char *argv[])
> {
> QRect org(0,0,100,100);
> org.moveCenter(QPoint(0,0));
> QTransform trans;
> trans.scale(.8,.4);
> trans.rotate(45.0);
> QPolygon gon=trans.mapToPolygon(org);
> QImage img(400,400,QImage::Format_ARGB32);
> QPainter p(&img);
> p.translate(200,200);
> p.drawPolygon(gon);
> img.save("test.png");
> }
>
>
>>> From qgraphicsitem_p.h
>>
>> QTransform computedFullTransform(QTransform *postmultiplyTransform = 0)
>> const
>>
>> {
>>
>> if (onlyTransform) {
>>
>> if (!postmultiplyTransform ||
>> postmultiplyTransform->isIdentity())
>>
>> return transform;
>>
>> if (transform.isIdentity())
>>
>> return *postmultiplyTransform;
>>
>> return transform * *postmultiplyTransform;
>>
>> }
>>
>> QTransform x(transform);
>>
>> if (!graphicsTransforms.isEmpty()) {
>>
>> QMatrix4x4 m;
>>
>> for (int i = 0; i < graphicsTransforms.size(); ++i)
>>
>> graphicsTransforms.at(i)->applyTo(&m);
>>
>> x *= m.toTransform();
>>
>> }
>>
>> x.translate(xOrigin, yOrigin);
>>
>> x.rotate(rotation);
>>
>> x.scale(scale, scale);
>>
>> x.translate(-xOrigin, -yOrigin);
>>
>> if (postmultiplyTransform)
>>
>> x *= *postmultiplyTransform;
>>
>> return x;
>>
>> }
>>
>>
>> 2011/6/3 Malyushytsky, Alex <alex at wai.com>
>>
>>>>> doesn't matter what order the
>>> QTransform::scale(), QTransform::rotate(), and QTransform::translate()
>>> functions are called in, does it?
>>>
>>> Yes it does.
>>> It uses matrix operation and stores transformation matrix.
>>> http://doc.qt.nokia.com/latest/qtransform.html#basic-matrix-operations
>>>
>>> Think it this way if you move rectangle from the center of the origin along
>>> x axis and rotate it
>>> 45 degrees around origin will not be equal to rotating it first and then
>>> moving.
>>>
>>> Alex
>>>
>>>
>>> -----Original Message-----
>>> From: qt-interest-bounces+alex=wai.com at qt.nokia.com [mailto:
>>> qt-interest-bounces+alex=wai.com at qt.nokia.com] On Behalf Of Joshua Grauman
>>> Sent: Friday, June 03, 2011 10:13 AM
>>> To: qt-interest at qt.nokia.com
>>> Subject: [Qt-interest] QTransform SRT order
>>>
>>> Hello all,
>>>
>>> I am using QTransform to Scale, Rotate, and Translate an image. I was
>>> wondering about the order of these operations. I'm assuming that
>>> QTransform operates in the order of: Scale, then Rotate, then Translate.
>>> Can anyone confirm this? It doesn't matter what order the
>>> QTransform::scale(), QTransform::rotate(), and QTransform::translate()
>>> functions are called in, does it? Thanks!
>>>
>>> Josh
>>> _______________________________________________
>>> Qt-interest mailing list
>>> Qt-interest at qt.nokia.com
>>> http://lists.qt.nokia.com/mailman/listinfo/qt-interest
>>>
>>>
>>>
>>>
>>>
>>> ---------------------------------------------------------------------------------------------------
>>> Weidlinger Associates, Inc. made the following annotations.
>>>
>>> This message and any attachments are solely for the intended recipient and
>>> may contain confidential or privileged information. If you are not the
>>> intended recipient, any disclosure, copying, use, or distribution of the
>>> information included in this message and any attachments is prohibited. If
>>> you have received this communication in error, please notify us by reply
>>> e-mail and immediately and permanently delete this message and any
>>> attachments. Thank you.
>>>
>>> Please consider our environment before printing this email.
>>> _______________________________________________
>>> Qt-interest mailing list
>>> Qt-interest at qt.nokia.com
>>> http://lists.qt.nokia.com/mailman/listinfo/qt-interest
>>>
More information about the Qt-interest-old
mailing list