Monday, July 5, 2010

Magic: MATLAB® Makes Movies!

The Pledge: Let me say that ‘this is not a revelation’, so that we are on the same page. The exclamation mark(!) is present for entirely different reasons. For quite some time, I had been having some troubles making movies using 'getframe' & 'addframe' functions in MATLAB®. The .avi file would have a botched up initial frame which would drag on forever, i.e. no changing frames and hence no movie! (Did you know that Pigeons would see our movies as a slideshow?)

The Turn: I realized that this has to be due to some conflict with the graphics renderer. So, I explicitly chose the 'zbuffer' renderer and the .avi file now actually contained changing frames and hence a movie. You might think it worked out but not so soon... (If it had, this would have been a pretty ‘lame’ post!) 'zbuffer' does not support transparency but I needed that as you will see below. After digging here & there for a while, I came to the conclusion that I needed to use 'OpenGL' renderer and this was also the cause of ‘improper’ movies being made till now! (OpenGL is chosen as the default renderer if available.)

The Prestige: Digging some more in MATLAB's Help (THE BEST HELP EVER WRITTEN, just wanted to get that off my chest Smile), I found the magic line: feature('UseGenericOpenGL',1); The problem was that OpenGL supports Hardware Acceleration and it is used by default when available but somehow MATLAB couldn't keep up(?)! So the above line forces OpenGL to use software acceleration instead, which as MATLAB's Help points out rarely causes problems. (If the problem still persists, just restart MATLAB®!)

That did it for me and here are the proofs:

Umbilic Torus
Werner Boy’s Surface
Here are some more well-made animations in MATLAB®:

No comments:

Post a Comment