Re: [osg-users] SwitchNode Animation with a specific time interval

2011-06-08 Thread Vijay Kalivarapu
Thanks Ulrich. I didn't know about this earlier. Looks like this is what I 
might need. I will post my findings on this soon.

... 

Thank you!

Cheers,
Vijay

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





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


Re: [osg-users] SwitchNode Animation with a specific time interval

2011-06-08 Thread Ulrich Hertlein
Hi Vijay,

On 7/06/11 23:32 , Vijay Kalivarapu wrote:
> 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.
>... 
> 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

Have you considered using osg::Sequence?  It does exactly that, switch between 
nodes based
on times.

Cheers,
/ulrich
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


[osg-users] SwitchNode Animation with a specific time interval

2011-06-07 Thread Vijay Kalivarapu
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(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(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