Hi,

I have a bunch of timesteps of data that I need to animate between. I set up my 
code so that each timestep corresponds to a switch node and I attempted to 
animate between each switchnode.

Here is my switch node animation operator code:


Code:

void SwitchingCallback::operator() (osg::Node* node, osg::NodeVisitor* nv)
{
    static int tstepNum = 0;
    static int sign = -1;
    int numtimesteps = 64;

    osg::Switch* switchNode = static_cast<osg::Switch*>(node);
    if( !((++_count) % 30) && switchNode)
    {
        if(tstepNum >= numtimesteps-1)
        {
            tstepNum = numtimesteps-1;
            sign = -sign;
        }
        else if (tstepNum <= 0)
        {
            tstepNum = 0;
            sign = -sign;
        }
                
        tstepNum += sign;
        switchNode->setSingleChildOn(tstepNum);
    }
        traverse(node, nv);
}




Currently, the speed at which the switch node is animating between timesteps is 
machine dependent. In other words, the animation speed is dependent on the 
machine that could count to 30 quick enough.

I would ideally like the animation to happen at a specific time interval 
instead and hoping to avoid the


Code:

!((++_count) % 30)




and be able to specify something like

Code:

if(timeElapsed > 0.02 seconds)
    then do_something;




I looked at osganimationmakepath example and attempted to use the following:


Code:


static int tstepNum = 0;
static int sign = -1;
int numtimesteps = 64;
static int flagForFirstTime = 0;

osg::Switch* switchNode = static_cast<osg::Switch*>(node);
_currentTime = osg::Timer::instance()->tick();

if(flagForFirstTime == 0)
{
  _startTime = osg::Timer::instance()->tick();
  flagForFirstTime = 1;
}

float t = osg::Timer::instance()->delta_s(_startTime, _currentTime);

if( t > 0.02f && switchNode)
{
  blah_blah_as_above;
  tstepNum += sign;
  switchNode->setSingleChildOn(tstepNum);
  flagForFirstTime = 0;
}
traverse(node, nv);





This worked, except that the animation was inconsistent. It was slow at times 
and then it suddenly picked up speed.

I am sure I am missing something, but I do not know what. Any suggestions?

Thank you!

Cheers,
Vijay.

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=40186#40186





_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to