[Qt-interest] QTransform SRT order (bug?)
Malyushytsky, Alex
alex at wai.com
Tue Jun 7 22:24:33 CEST 2011
I am sorry if I was not clear.
In my Qt version it does it the "correct" order - in the order operations are applied.
I was saying that you might get such impression you got cause of the coordinate system,
Which is normal for person who used to dialing with system painting,
but could be found weird for person who never dialed with it.
So I suggested you to read about coordinate system:
http://doc.qt.nokia.com/latest/coordsys.html
You can also check following link to see results of some transforms:
http://doc.qt.nokia.com/latest/qtransform.html#rendering-graphics
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: Tuesday, June 07, 2011 8:55 AM
To: qt-interest at qt.nokia.com
Subject: Re: [Qt-interest] QTransform SRT order (bug?)
I guess this is expected behavior according to a response that I received, but it should be documented that when you do the scale, translate, rotate operations, it does them in reverse order...
Josh
> I am still working with Qt 4.6.3 and result are correct there.
> Are you sure you are no confused by screen coordinate system?
>
> http://doc.qt.nokia.com/latest/coordsys.html
>
> 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: Monday, June 06, 2011 11:11 PM
> To: qt-interest at qt.nokia.com
> Subject: Re: [Qt-interest] QTransform SRT order (bug?) (fwd)
>
> 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-operati
>>>> o
>>>> ns
>>>>
>>>> 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
>>>> qt-interest-bounces+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
>>>>
>
>
> ----------------------------------------------------------------------
> ----------------------------- 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.”
> _______________________________________________
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.
More information about the Qt-interest-old
mailing list