本文整理汇总了C++中osg::Node::getOrCreateUserDataContainer方法的典型用法代码示例。如果您正苦于以下问题:C++ Node::getOrCreateUserDataContainer方法的具体用法?C++ Node::getOrCreateUserDataContainer怎么用?C++ Node::getOrCreateUserDataContainer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类osg::Node
的用法示例。
在下文中一共展示了Node::getOrCreateUserDataContainer方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: update
void PropertyAnimation::update(osg::Node& node)
{
OSG_NOTICE<<"PropertyAnimation::update()"<<this<<std::endl;
double time = getAnimationTime();
if (_keyFrameMap.empty()) return;
KeyFrameMap::const_iterator itr = _keyFrameMap.lower_bound(time);
if (itr==_keyFrameMap.begin())
{
// need to copy first UserDataContainer
OSG_NOTICE<<"PropertyAnimation::update() : copy first UserDataContainer"<<std::endl;
assign(node.getOrCreateUserDataContainer(), itr->second.get());
}
else if (itr!=_keyFrameMap.end())
{
KeyFrameMap::const_iterator itr_1 = itr; --itr_1;
KeyFrameMap::const_iterator itr_2 = itr;
// delta_time = second.time - first.time
double delta_time = itr_2->first - itr_1->first;
double r1, r2;
if (delta_time==0.0)
{
r1 = 0.5;
r2 = 0.5;
}
else
{
r2 = (time - itr_1->first)/delta_time;
r1 = 1.0-r2;
}
osg::UserDataContainer* p1 = itr_1->second.get();
osg::UserDataContainer* p2 = itr_2->second.get();
// clone all the properties from p1;
osg::ref_ptr<osg::UserDataContainer> destination = node.getOrCreateUserDataContainer();
assign(destination.get(), p1);
for(unsigned int i2=0; i2<p2->getNumUserObjects(); ++i2)
{
osg::Object* obj_2 = p2->getUserObject(i2);
unsigned int i1 = p1->getUserObjectIndex(obj_2->getName());
if (i1<p1->getNumUserObjects())
{
osg::Object* obj_1 = p1->getUserObject(i1);
osg::ValueObject* valueobject_1 = dynamic_cast<osg::ValueObject*>(obj_1);
osg::ValueObject* valueobject_2 = dynamic_cast<osg::ValueObject*>(obj_2);
if (valueobject_1 && valueobject_2)
{
osg::ref_ptr<osg::ValueObject> vo = osg::clone(valueobject_1);
MySetValueVisitor mySetValue(r1, r2, valueobject_2);
vo->set(mySetValue);
assign(destination.get(), vo.get());
}
else if (obj_1)
{
assign(destination.get(), obj_1);
}
else if (obj_2)
{
assign(destination.get(), obj_2);
}
}
else
{
// need to insert property;
assign(destination.get(), obj_2);
}
}
}
else // (itr==_keyFrameMap.end())
{
OSG_NOTICE<<"PropertyAnimation::update() : copy last UserDataContainer"<<std::endl;
assign(node.getOrCreateUserDataContainer(), _keyFrameMap.rbegin()->second.get());
}
}