osgAnimation.Target是OpenSceneGraph中osgAnimation库中的一种节点类型,用于在动画过程中指定动画对象的目标。
使用osgAnimation.Target时,需要指定目标对象和目标类型。
osg::ref_ptr<osgAnimation::Target> target = new osgAnimation::Target;
target->setName("target");
// 设置目标对象为某个节点
osg::ref_ptr<osg::Node> node = ...;
target->setTargetObject(node.get());
// 设置目标类型为平移或旋转
target->setTargetType(osgAnimation::Target::TRANSLATION);
// 将Target节点加入动画中
osg::ref_ptr<osgAnimation::Animation> animation = ...;
osg::ref_ptr<osgAnimation::AnimationManagerBase> manager = animation->getOrCreateStateManager();
manager->registerTarget(target.get());
然后,在动画帧更新时,可以根据Target节点的目标类型更新目标对象的属性值。
osg::Vec3 translation(1.0f, 0.0f, 0.0f);
osg::Quat rotation(osg::PI_2, osg::Vec3d(1.0, 0.0, 0.0));
osg::Matrix matrix = osg::Matrix::translate(translation) * osg::Matrix::rotate(rotation);
// 更新Target节点的目标对象属性
osg::ref_ptr<osgAnimation::Animation> animation = ...;
osg::ref_ptr<osgAnimation::AnimationManagerBase> manager = animation->getOrCreateStateManager();
osgAnimation::FloatKeyframeContainer keys;
keys.push_back(osgAnimation::FloatKeyframe(0.0f, 0.0f));
keys.push_back(osgAnimation::FloatKeyframe(1.0f, matrix.getTrans()));
manager->setValue(target->getName(), keys);
keys.clear();
keys.push_back(osgAnimation::FloatKeyframe(0.0f, 0.0f));
keys.push_back(osgAnimation::FloatKeyframe(1.0f, matrix.getRotate()));
manager->setValue(target->getName(), keys);
osgAnimation.Target有以下属性:
属性名 | 类型 | 描述 |
---|---|---|
name | std::string | 节点名称 |
targetObject | osg::Object | 目标对象 |
targetType | TargetType | 目标对象类型 |
osgAnimation.Target的目标类型(TargetType)有以下枚举值:
枚举值 | 描述 |
---|---|
TRANSLATION | 平移 |
ROTATION | 旋转 |
SCALE | 缩放 |