Ogre 旋转节点后,创建该节点的节点动画,则节点旋转效果失效

如果单独设置节点的旋转,则没有问题,可正常实现,代码如下:
// 设置节点旋转(pos 为两点之间的向量,也就是方向或朝向)
Ogre::Vector3 src = m_pNode->getOrientation() * Ogre::Vector3::UNIT_X;
Ogre::Quaternion quat = src.getRotationTo(pos);
m_pNode->rotate(quat);

如果设置完毕节点旋转后,再创建节点动画,则节点旋转效果失效,代码如下:
// 设置节点旋转(pos 为两点之间的向量,也就是方向或朝向)
Ogre::Vector3 src = m_pNode->getOrientation() * Ogre::Vector3::UNIT_X;
Ogre::Quaternion quat = src.getRotationTo(pos);
m_pNode->rotate(quat);

// 创建该节点的节点动画
m_pAnimation = m_pSceneManager->createAnimation(Ogre::String("Animation"), Ogre::Real(10));
m_pAnimation->setInterpolationMode(Ogre::Animation::IM_SPLINE);

Ogre::NodeAnimationTrack* track = m_pAnimation->createNodeTrack( 0, m_pNode);

Ogre::TransformKeyFrame* key = track->createNodeKeyFrame(0);
key->setTranslate(m_acupointCenterPos);

key = track->createNodeKeyFrame(10);
key->setTranslate(m_acupointQYCenterPos);

m_pAnimationState = m_pSceneManager->createAnimationState("Animation");
m_pAnimationState->setEnabled(true);
m_pAnimationState->setLoop(true);

原因:

节点的位置、旋转等属性变换,相当于改变的是临时变量,不会更改原有的属性数据。

节点旋转后再创建动画,使用的是原有的属性数据,并不是更改后的。

所以要解决此问题,只有在每次设置TransformKeyFrame的时候,再次设置旋转数据:

// 设置节点旋转(pos 为两点之间的向量,也就是方向或朝向)
Ogre::Vector3 src = m_pNode->getOrientation() * Ogre::Vector3::UNIT_X;
Ogre::Quaternion quat = src.getRotationTo(pos);
m_pNode->rotate(quat);

// 创建该节点的节点动画
m_pAnimation = m_pSceneManager->createAnimation(Ogre::String("Animation"), Ogre::Real(10));
m_pAnimation->setInterpolationMode(Ogre::Animation::IM_SPLINE);

Ogre::NodeAnimationTrack* track = m_pAnimation->createNodeTrack( 0, m_pNode);

Ogre::TransformKeyFrame* key = track->createNodeKeyFrame(0);
key->setRotation(quat); // 再次设置旋转数据
key->setTranslate(m_acupointCenterPos);

key = track->createNodeKeyFrame(10);
key->setRotation(quat); // 再次设置旋转数据
key->setTranslate(m_acupointQYCenterPos);

m_pAnimationState = m_pSceneManager->createAnimationState("Animation");
m_pAnimationState->setEnabled(true);
m_pAnimationState->setLoop(true);
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值