2002-02-27 08:58:54 +08:00
|
|
|
#include <osg/AnimationPath>
|
2002-04-22 06:05:26 +08:00
|
|
|
#include <osg/NodeVisitor>
|
2002-02-27 08:58:54 +08:00
|
|
|
|
|
|
|
using namespace osg;
|
|
|
|
|
|
|
|
void AnimationPath::insert(double time,const Key& key)
|
|
|
|
{
|
|
|
|
_timeKeyMap[time] = key;
|
|
|
|
}
|
|
|
|
|
2002-04-22 06:05:26 +08:00
|
|
|
bool AnimationPath::getMatrix(double time,Matrix& matrix) const
|
2002-02-27 08:58:54 +08:00
|
|
|
{
|
|
|
|
if (_timeKeyMap.empty()) return false;
|
|
|
|
|
2002-04-22 06:05:26 +08:00
|
|
|
TimeKeyMap::const_iterator second = _timeKeyMap.lower_bound(time);
|
2002-02-27 08:58:54 +08:00
|
|
|
if (second==_timeKeyMap.begin())
|
|
|
|
{
|
|
|
|
second->second.getMatrix(matrix);
|
|
|
|
}
|
|
|
|
else if (second!=_timeKeyMap.end())
|
|
|
|
{
|
2002-04-22 06:05:26 +08:00
|
|
|
TimeKeyMap::const_iterator first = second;
|
2002-02-27 08:58:54 +08:00
|
|
|
--first;
|
|
|
|
|
|
|
|
// we have both a lower bound and the next item.
|
|
|
|
|
|
|
|
// deta_time = second.time - first.time
|
|
|
|
double delta_time = second->first - first->first;
|
|
|
|
|
|
|
|
if (delta_time==0.0)
|
|
|
|
first->second.getMatrix(matrix);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Key key;
|
|
|
|
key.interpolate((time - first->first)/delta_time,
|
|
|
|
first->second,
|
|
|
|
second->second);
|
|
|
|
key.getMatrix(matrix);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else // (second==_timeKeyMap.end())
|
|
|
|
{
|
|
|
|
_timeKeyMap.rbegin().base()->second.getMatrix(matrix);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2002-04-22 06:05:26 +08:00
|
|
|
bool AnimationPath::getInverse(double time,Matrix& matrix) const
|
2002-02-27 08:58:54 +08:00
|
|
|
{
|
2002-03-01 17:29:56 +08:00
|
|
|
if (_timeKeyMap.empty()) return false;
|
|
|
|
|
2002-04-22 06:05:26 +08:00
|
|
|
TimeKeyMap::const_iterator second = _timeKeyMap.lower_bound(time);
|
2002-03-01 17:29:56 +08:00
|
|
|
if (second==_timeKeyMap.begin())
|
|
|
|
{
|
|
|
|
second->second.getInverse(matrix);
|
|
|
|
}
|
|
|
|
else if (second!=_timeKeyMap.end())
|
|
|
|
{
|
2002-04-22 06:05:26 +08:00
|
|
|
TimeKeyMap::const_iterator first = second;
|
2002-03-01 17:29:56 +08:00
|
|
|
--first;
|
|
|
|
|
|
|
|
// we have both a lower bound and the next item.
|
|
|
|
|
|
|
|
// deta_time = second.time - first.time
|
|
|
|
double delta_time = second->first - first->first;
|
|
|
|
|
|
|
|
if (delta_time==0.0)
|
|
|
|
first->second.getInverse(matrix);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Key key;
|
|
|
|
key.interpolate((time - first->first)/delta_time,
|
|
|
|
first->second,
|
|
|
|
second->second);
|
|
|
|
key.getInverse(matrix);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else // (second==_timeKeyMap.end())
|
|
|
|
{
|
|
|
|
_timeKeyMap.rbegin().base()->second.getInverse(matrix);
|
|
|
|
}
|
|
|
|
return true;
|
2002-02-27 08:58:54 +08:00
|
|
|
}
|
2002-04-22 06:05:26 +08:00
|
|
|
|
2002-08-13 21:22:46 +08:00
|
|
|
|
|
|
|
bool AnimationPath::getKeyFrame(double time,Key& key) const
|
2002-04-22 06:05:26 +08:00
|
|
|
{
|
2002-08-13 21:22:46 +08:00
|
|
|
if (_timeKeyMap.empty()) return false;
|
|
|
|
|
|
|
|
TimeKeyMap::const_iterator second = _timeKeyMap.lower_bound(time);
|
|
|
|
if (second==_timeKeyMap.begin())
|
2002-04-22 06:05:26 +08:00
|
|
|
{
|
2002-08-13 21:22:46 +08:00
|
|
|
key = second->second;
|
2002-04-22 06:05:26 +08:00
|
|
|
}
|
2002-08-13 21:22:46 +08:00
|
|
|
else if (second!=_timeKeyMap.end())
|
2002-04-22 06:05:26 +08:00
|
|
|
{
|
2002-08-13 21:22:46 +08:00
|
|
|
TimeKeyMap::const_iterator first = second;
|
|
|
|
--first;
|
|
|
|
|
|
|
|
// we have both a lower bound and the next item.
|
|
|
|
|
|
|
|
// deta_time = second.time - first.time
|
|
|
|
double delta_time = second->first - first->first;
|
|
|
|
|
|
|
|
if (delta_time==0.0)
|
|
|
|
key = first->second;
|
|
|
|
else
|
2002-04-22 06:05:26 +08:00
|
|
|
{
|
2002-08-13 21:22:46 +08:00
|
|
|
key.interpolate((time - first->first)/delta_time,
|
|
|
|
first->second,
|
|
|
|
second->second);
|
|
|
|
}
|
2002-04-22 06:05:26 +08:00
|
|
|
}
|
2002-08-13 21:22:46 +08:00
|
|
|
else // (second==_timeKeyMap.end())
|
|
|
|
{
|
|
|
|
key = _timeKeyMap.rbegin().base()->second;
|
|
|
|
}
|
|
|
|
return true;
|
2002-04-22 06:05:26 +08:00
|
|
|
}
|