[vtkusers] Basic Animation Code
David Gobbi
david.gobbi at gmail.com
Wed Jan 6 09:07:33 EST 2010
On Tue, Jan 5, 2010 at 9:28 PM, David Doria <daviddoria+vtk at gmail.com> wrote:
> On Wed, Dec 16, 2009 at 10:27 PM, Leon Danon <kernelblaha at gmail.com> wrote:
>> Hi All,
>>
>> I'm attempting (and failing) to run a simple animated model where the
>> position and colour of an actor (in my case a cylider) changes, while at the
>> same time being rendered.
>> I have done a bit of googling, but have come up with nothing very useful. My
>> understanding is that it should be done with threads (one for the renderer,
>> the other for the model).
>> Does anyone have a simple example in C++ of how this would be implemented.
>> It would be greatly appreciated.
>> Thanks
>> Leon
>
> Surely someone knows how to do this? Is an example of what you want
> something like a loop to move an object across the scene?
>
> pseudo code:
>
> for(xposition = 1; xposition < 10; xposition++)
> {
> actor.setposition(xposition,0,0);
> render scene
> }
>
> Can anyone translate to VTK?
>
> Thanks,
>
> David
In general, animation should be done with timer events, because timers
don't interfere with the other event handling in an application.
Using for/while loops for animation will block the application from
doing anything _but_ the animation until the loop has completed.
Threads don't add much benefit over timers and are tricky to use
because a global VTK mutex lock would be needed, and mistakes in the
use of threads can easily lead to freezing, crashing, and other
unpredictable application behavior.
The example Rendering/Testing/Cxx/TestInteractorTimers.cxx gives some
good clues about how animation can be done in VTK (there are probably
other, better examples but this one is in C++ and not Tcl or Python).
David
More information about the vtkusers
mailing list