[vtkusers] Starting an animation with a keypress, terminating with another keypress
Steve Chall
stevec at renci.org
Thu Oct 29 12:37:28 EDT 2009
Dear fellow VTK enthusiasts:
I'd like to trigger an animation from a keypress event, and then stop the
animation with the same keypress event. I've subclassed
vtkInteractorStyleTrackballCamera with an OnKeyPress() method that looks a
lot like what's included below. When the user presses a key,
myInteractorStyleTrackballCamera::OnKeyPress() is invoked, which (for the
selected key, say 'a') toggles myObject's isAnimating Boolean flag. If
after toggling the flag is true, I want to start an animation loop. If
after toggling it's false, I want to stop that same loop. But once I start
the loop I can't penetrate with another 'a' keypress (or anything else other
than a <Ctrl-C>) to change the flag back to false and thus stop the loop.
How can I interrupt the "while (isAnimating)" loop once it starts?
(I've also subclassed vtkRenderWindowInteractor because its Start() function
seems like a place for interrupts, but I don't know what to do with it.)
Thanks for any help you may be able to provide.
-Steve Chall
Senior Research Software Developer
Renaissance Computing Institute
Phone: 919-515-0051
Email: stevec at renci.org
// Pseudo C++ source code segments follow:
...
myClass::Animate()
{
while (isAnimating)
{
this->RenderNextFrame();
}
}
...
myClass *myObject = new myClass;
...
void myInteractorStyleTrackballCamera::OnKeyPress()
{
switch (this->Interactor->GetKeyCode())
{
case 'a':
case 'A':
if (myObject)
{
myObject->isAnimating = !(myObject->isAnimating);
if (myObject->isAnimating)
{
myObject->Animate();
}
/* This is sort of what I'd like to do:
else
{
myObject->StopAnimating();
}
}
*/
break;
default:
break;
}
vtkInteractorStyleTrackballCamera::OnKeyPress();
}
More information about the vtkusers
mailing list