Perspective view in Qt.
-
wrote on 19 Mar 2014, 18:23 last edited by
Hi Guys,
It has been roughly a month I have started working with Qt. Right now I am trying to vie an image in perspective view. Lets say I want to rotate the image in along the Y axis, I am using the Qtransform function to rotate.. here is the code snippet.
int angle=20;
QTransform transform;
transform.rotate(angle, Qt::YAxis);
image = QImage(”:/images/livingroom.jpg”);
image = image.scaledToWidth(this->width());
image = image.transformed(transform);But this is not producing the desired results. The result image is not a perspective view. Can anybody please help me in achieving this?
-
wrote on 19 Mar 2014, 20:21 last edited by
I believe you are looking for
QTransform::quadToQuad(const QPolygonF & one, const QPolygonF & two, QTransform & trans)
or,
QTransform::squareToQuad(const QPolygonF & quad, QTransform & trans)
depending on the original image.
-
wrote on 19 Mar 2014, 20:27 last edited by
Hi,
Pardon my ignorance, but do i need to find out the second polygon,( the one for the perspective view) manually? After that I have to map the image to the new polygon? Please correct me if I am wrong..
-
wrote on 19 Mar 2014, 21:26 last edited by
Nope, that sounds about right. I don't suspect it should be too dificult.
ie. To make the image "fade" to the right.
Copy the original polygon,
in the new copy divide imageheight by 2, adjust the upper right y value to imageheight/4 and lower right y value = imageheight *3/4. -
wrote on 19 Mar 2014, 21:33 last edited by
I found this example using matrix. This is another way to go.
"https://blog.qt.digia.com/blog/2006/09/21/perspective-transformations/":https://blog.qt.digia.com/blog/2006/09/21/perspective-transformations/
-
wrote on 19 Mar 2014, 21:35 last edited by
Lets say I want to rotate it by 25 degrees along the y axis, so how do i calculate the height of the right edge of the polygon?
Because here you are saying the right edge is half of the left edge..but how do u find out this relation
-
wrote on 19 Mar 2014, 21:38 last edited by
yes Even I had stumbled across that example, but i cannot find the code to do that....I can see that the snapshots given are exactly what i want
-
wrote on 19 Mar 2014, 21:44 last edited by
I think I'm getting a bit confused about what you are trying to do here. I'm starting to suspect that you are trying to do a 3d flyby of "livingroom.jpg"?
If this is the case, assume you are at 89.5 degrees. You will be looking more or less at the edge of a pic, a vertical line. If this is the case it's time to start thinking about Qt OpenGL classes and go 3D. -
wrote on 19 Mar 2014, 21:49 last edited by
Umm,,,I would say I am trying to achieve exactly the same thing that the snapshots in the example show...
https://blog.qt.digia.com/blog/2006/09/21/perspective-transformations/ -
wrote on 19 Mar 2014, 22:26 last edited by
First I'll answer your previous question.
"Lets say I want to rotate it by 25 degrees along the y axis, so how do i calculate the height of the right edge of the polygon?"
I'm thinking you can't. Too many unknowns... Distance from the object, what object is the focus, the width or scale of the scene. Best you can do is simulate a rotation.
At this point I would suggest you add a horizontal slider to you gui. Set min at -50 and max at +50. if value is > 0, adjust the left side of the target polygon. If the value is < 0 adjust the right side of the target polygon. Adjust the edge of the polygon by some multiple of the slider's value. I would not go crazy here though, maybe no more than 50% of the height of the image.
I haven't tried this but I'm betting this is going to be a huge resource issue, I hope your pic is small.
1/10