2013년 1월 14일 월요일

Calculating global time for animation clip.

The "Game engine architecture book" says that using global time instead of local time has several benefits. So I applied this algorithm to my current animation implementation.

Here is source code for calculating local time from global time.


float CurrentGlobalTime = GEngine->_TimeSeconds;
float NT;
if(_NumPlay == 0)
{
    NT = FLOAT_MAX;
}
else
{
    NT = _Clip->_Duration*(float)_NumPlay;
}

_LocalTime = fmod(Math::Clamp<float>((CurrentGlobalTime - _StartTime)*_TimeScale, -NT, NT), _Clip->_Duration);

if(_LocalTime < 0)
{
    _LocalTime = _Clip->_Duration + _LocalTime;
}

It works for loop and plus and minus time scale, but I think handling minus time scale is a little dirty.

looping


3x faster

repeat 3 times and stop



reverse (minus time scale)



댓글 없음:

댓글 쓰기