Perspective view in Qt.
-
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?
-
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. -
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/
-
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. -
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/ -
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.