Thursday, September 21, 2006

Perspective transformations

A really neat feature that Arthur in Qt4 was lacking was support for perspective transformations. QMatrix is an affine transformation class. Even though our docs advertise it as a 3x3 matrix it's actually 2x3. I've been wanting to do perspective transformations in Qt for a while. With Qt 4.2 frozen I had a chance to sit down and work in the main branch for the last two days. As a result I have a very basic support for perspective transformations in Qt. I added a QTransform class which is a true 3x3 matrix and gutted most of Qt where I replaced QMatrix with QTransform. Now it's possible to do projections of any kind of Qt element. That includes images like Konqy here:

but also all other Qt elements, like here a button with a label and icon:

All of which allows one to create a really nice looking 3D like looking effects in all Qt apps.


Anonymous said...

It's good to see QT4 still making advances :)

I'm no vector graphics or 3D expert, but I remember getting my first glimpse of 3D app source code/docs many years ago, and reading that they had used a 3x3 matrix, but that a 4x4 matrix would have been better. Did the 3x3 matrix produce rendering glitches on certain transforms? I forget what the difference was, or maybe it was never explained. But... this might be worth looking into.

Anonymous said...

4x4 transformation matrices include homogenous coordinates.

I'm actually a little supprised Zack didn't code up his implementation using a 4x4 matrix. While one can use 4x4 transformation matrices and perform matrix multiplication directly in OpenGL it's often easier to simply use the rotate, translate, etc functions which do the matrix multiplication behind the scenes. I'm curious if Qt4.3 will end up allowing us to apply similar persepctive transformations or rotations in 3 space without specifying the full transformation matrix.

-Will Stokes

Zack said...

You both got it wrong. Of course we use homogenous coordinates. We always have. How else would QMatrix have a translate method? :) That's not what this is about. This is about switching from affine transformation matrix to a perspective transformation matrix.
We're not planning to add 3D transformations to the widgets anytime soon for a very simple reasons: this is a 2D framework (especially given that with perspective transformations one can mimick 3D very nicely).

Luke Parry said...

You are doing nice work Zack, even though this isn't related to your work. The images in the blog don't appear. It had happened within some of the older blog entries, remembering back. Would be great to see your accomplishments.

Luke Parry

Vladislav Blanton said...

they appear fine here. I've never seen any problems with Zack's blog images.

Anonymous said...

I always have to click on an image to go to the link, then come back and they all appear.

Jason said...

So will this be in 4.2? I think we'd gobble it up if it was!!

Jim Walseth said...

I am developing a 2D perspective view (tilted plane) in Qt 4.4.2. I was pleased to encounter this blog entry and find QTransform in the Qt source code. Is perchance the demo application shown available somewhere?
I actually started down the OpenGL path and have a fair amount of structure built around that. (Did not work on our embedded platform.) I had a thought about using the opengl code (especially, rotation of model around an arbitrary axis) as a 'calculator', extracting the matrix elements and putting them into QTransform.