On 21/05/2009, at 4:21 PM, Thrall, Bryan wrote:

Also, if Philip wants to pause all animations in the scene (instead of
just ones from the subgraph), he could just pause the simulation time in
the frame loop like this untested code:
... SNIP ...

Bryan,

That's a good tip, and closer to my original intent of having a global pause / resume of all time-based things happening in the scene. For reference for others, here is the code I've used. Class names removed for sake of brevity.

In my application class header:

double _mySimulationTimeStart, _mySimulationTimePause, _mySimulationTime;
    bool _globallyPaused;

In my application class (_viewer is an osg::Viewer, already set up):

    _viewer.realize();
_mySimulationTimeStart = _mySimulationTimePause = _mySimulationTime = 0.0; _globallyPaused = false; // Could also be true, to start in a paused state.
    while (!_Viewer.done())
    {
_mySimulationTime = _viewer.getViewerFrameStamp()- >getReferenceTime() - _mySimulationTimeStart;
        if (_globallyPaused) _viewer.frame(_mySimulationTimePause);
        else _viewer.frame(_mySimulationTime);
    }

and the handler for pause/resume events:

void setGloballyPaused(bool pause)
{
    _globallyPaused = pause; // Set global state.
    if (_globallyPaused) _mySimulationTimePause = _mySimulationTime;
else _mySimulationTimeStart += _mySimulationTime - _mySimulationTimePause; // Add elapsed time since pause started to offset.

That's it.

Incidentally, I've also discovered a bug/feature in osg::AnimationCallback::reset(). if the animation callback is in a paused state, the reset of the actual transform node which the callback is attached to only takes effect once the animation callback is placed into the unpaused state. This has the rather annoying effect that if an animation has run its course, and has been paused, a reset won't change it's state in the scene graph. I tried to work up a work- around for this, but haven't so far.

Regards,

Phil.
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to