Let us start with the code:
svn checkout svn://labs.trolltech.com/svn/graphics/dojo/genie cd genie && qmake && make && ./genie
For the impatient, a screencast is worth a thousand screenshots. For your pleasure, here is the 20-second screencast. Or view it on blip.tv, YouTube, or grab the Ogg Theora file (1.4 MB).
Usually you would not want to do the genie effect (made famous in Mac OS X) like in this implementation, as you can get mesh deformation easily using GLSL. Here I just want to show code as another example of one of the messages from my graphics talk in Qt Developer Days, namely "cheat whenever you can". If you inspect the inner loop, you can see that it is fairly simple. The idea is to store the outline of the genie shape in a table (I use logistic function, as "S" shape looks really good). During the animation, the left start-point and right end-point of each row is used to scale a horizontal slice of the original pixmap. One dimensional scaling like this is fairly cheap, as in ray casting trick. Furthermore, the only division in the loop can be optimized (at the cost of visual quality) to be carried out every N rows (the alternative is a look-up table). Since we are animating anyway, decide yourself if you can get away with the sacrificed quality.
I have no doubt that the experienced readers can further squeeze the scaling code, I left it just like it is because it starts to be less readable. Of course, feel free to have more fun there!
Final word: special thanks to Enrico Ros for the discussion, initial code, and the feedback.
Possibly related posts:
6 comments
“Usually you would not want to do the genie effect (made famous in Mac OS X) like in this implementation, as you can get mesh deformation easily using GLSL.”
May I ask what the reason was not using GLSL, then? To have it available for people who lack hardware acceleration? I mean, why would one cheat when not having to (unfortunately I could not see your talk, are there videos of it?)
The answer is the sentence after that: as another example of “cheat while you can”.
And because you are not in control of your user’s hardware. Sometimes they will be using different video cards/drivers than what you expect. Even on new hardware, it could be a laptop and “mobility” version of a chip that is not suitable for every video task you through at til.
p.s. Not that GLSL is necessarily and advanced feature, but I’ve run across more than a few OpenGL based apps that work fine on my old desktop with “obsolete” hardware, but look lousy or just won’t work on my relatively new laptop.
Hey ! You deleted Benedikte !!
Well for myself … i have no clue how to do that in GLSL … is there any resource to show ?
(so i like to do it this way)
Comments on this entry are closed.