本文整理汇总了C++中ogre::SceneManager::createAnimation方法的典型用法代码示例。如果您正苦于以下问题:C++ SceneManager::createAnimation方法的具体用法?C++ SceneManager::createAnimation怎么用?C++ SceneManager::createAnimation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ogre::SceneManager
的用法示例。
在下文中一共展示了SceneManager::createAnimation方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ReadAnimation
void FvXMLAnimationModelSerializerImpl::ReadAnimation(
FvXMLSectionPtr spSection, Ogre::SceneNode* pkNode, FvAnimationModel* pkDest )
{
Ogre::SceneManager *pkSceneManager = Ogre::Root::getSingleton().
_getCurrentSceneManager();
FV_ASSERT(pkSceneManager);
FvString kAnimationName = spSection->ReadString("name");
bool bEnable = spSection->ReadBool("enable");
bool bLoop = spSection->ReadBool("loop");
FvString kIterpolationMode = spSection->ReadString("interpolationMode");
FvString kRotationIterpolationMode = spSection->ReadString("rotationInterpolationMode");
float fLength = spSection->ReadFloat("length");
if(!pkSceneManager->hasAnimation(pkNode->getName() + kAnimationName))
{
std::vector<FvXMLSectionPtr> kKeyFrames;
spSection->OpenSections("keyframe",kKeyFrames);
Animation *pkAnimation = pkSceneManager->createAnimation(pkNode->getName() + kAnimationName, fLength);
if(strcmp(kIterpolationMode.c_str(),"spline") == 0)
pkAnimation->setInterpolationMode(Animation::IM_SPLINE);
else
pkAnimation->setInterpolationMode(Animation::IM_LINEAR);
if(strcmp(kRotationIterpolationMode.c_str(),"spherical") == 0)
pkAnimation->setRotationInterpolationMode(Animation::RIM_SPHERICAL);
else
pkAnimation->setRotationInterpolationMode(Animation::RIM_LINEAR);
NodeAnimationTrack *pkAnimationTrack = pkAnimation->createNodeTrack(
pkAnimation->getNumNodeTracks() + 1, pkNode);
for (size_t stKeyframeIndex = 0; stKeyframeIndex < kKeyFrames.size(); stKeyframeIndex++)
{
float fTime = kKeyFrames[stKeyframeIndex]->ReadFloat("time");
FvVector3 kPosition = kKeyFrames[stKeyframeIndex]->ReadVector3("translation");
FvVector3 kScale = kKeyFrames[stKeyframeIndex]->ReadVector3("scale");
FvQuaternion kQuaternion = kKeyFrames[stKeyframeIndex]->ReadQuaternion("rotation");
TransformKeyFrame *pkKeyFrame = pkAnimationTrack->createNodeKeyFrame(fTime);
pkKeyFrame->setTranslate(Vector3(kPosition.x,kPosition.y,kPosition.z));
pkKeyFrame->setRotation(Quaternion(kQuaternion.w,kQuaternion.x,kQuaternion.y,kQuaternion.z));
pkKeyFrame->setScale(Vector3(kScale.x,kScale.y,kScale.z));
}
AnimationState *pkAnimationState = pkSceneManager->createAnimationState(pkNode->getName() + kAnimationName);
pkAnimationState->setEnabled(bEnable);
pkAnimationState->setLoop(bLoop);
pkDest->m_kModelAnimations.insert(std::make_pair(kAnimationName,pkAnimationState));
}
}
示例2: load
void WheelAnimalSceneObj::load(const std::string & filename)
{
//Ogre::ru * s = Orz::OgreGraphicsManager::getSingleton().getSceneManager()->getRootSceneNode()->createChildSceneNode(Ogre::Vector3(0, 0 ,0));
//导入场景资源
_impl = BaseSceneImpl::create(_osm, filename);
//创建总场景节点
_senceNode = Orz::OgreGraphicsManager::getSingleton().getSceneManager()->getRootSceneNode()->createChildSceneNode();
//创建场景
_osm->createScene(_senceNode);
_senceNode->setVisible(true);
//s->setVisible(false);
/*_impl->getCamera(SCENE_CAMERA)->setPosition(Ogre::Vector3(-98.851, 164.283, 237.886));
_impl->getCamera(SCENE_CAMERA)->setOrientation(Ogre::Quaternion(0.999578, -0.0192806, -0.0226839));*/
//创建摄像机的节点
_cameraSn = OgreGraphicsManager::getSingleton().getSceneManager()->getRootSceneNode()->createChildSceneNode();
//获取场景的摄像机
Ogre::Camera * camera = _impl->getCamera(SCENE_CAMERA);
//创建摄像机的节点并设置它的位置
_cameraSn = camera->getParentSceneNode()->createChildSceneNode(Ogre::Vector3(0.f, 164.283f, 237.886f));
//_cameraSn->setPosition(Ogre::Vector3(-98.851, 164.283, 237.886));
//_cameraSn->setOrientation(Ogre::Quaternion(0.999578, -0.0192806, -0.0226839));
//camera->detatchFromParent();
//脱离原有的节点
camera->detachFromParent();
//摄像机绑定在节点上
_cameraSn->attachObject(_impl->getCamera(SCENE_CAMERA));
//创建场景的中心节点
Ogre::SceneNode * sn = getBaseCenter()->createChildSceneNode(Ogre::Vector3(0, 100,0));
//setAutoTracking可以让你的摄像机总是盯着你场景中的某一个节点
//方法中第一个参数确定是否打开自动跟踪,在任何一帧渲染之前都可以重新设置它。
//二个参数是被跟踪节点得指针,除非你第一个参数是false(这时候可以用NULL),否则你必须确定调用的时候指针指向的节点必须有效
camera->setAutoTracking(true, sn);
// std::cout<<_camera->getPosition()<<"!"<<_camera->getOrientation()<<std::endl;
//获取场景管理器
Ogre::SceneManager * sm = Orz::OgreGraphicsManager::getSingleton().getSceneManager();
// set up spline animation of node
//定义动画,指定动画的名称及长度(这里为4秒)
_anim = sm->createAnimation("Cam_", 4);
//// Spline it for nice curves
// // 指定动画关键帧之间的插值方式(包括线性插值和样条插值)
_anim->setInterpolationMode(Ogre::Animation::IM_LINEAR);
//定义动画的一个动画轨迹,并指定这个轨迹是作用到_cameraSn节点上的
//// Create a track to animate the camera's node
Ogre::NodeAnimationTrack * track = _anim->createNodeTrack(0, _cameraSn);
// 定义动画轨迹包含的关键帧,下面定义了3个关键帧,加上起始帧
// 4个关健帧形成了一个曲线的动画
Ogre::TransformKeyFrame* key = track->createNodeKeyFrame(0); // startposition
key->setTranslate(Ogre::Vector3(0.f, 0.3f, 237.886f));
key = track->createNodeKeyFrame(3); // startposition
key->setTranslate(Ogre::Vector3(0.f, 0.3f, 237.886f));
key = track->createNodeKeyFrame(4);
key->setTranslate(Ogre::Vector3(0.f, -80.f, -400.f));
//////////////////////////////////
//定义动画的一个动画轨迹,并指定这个轨迹是作用到创建场景的中心节点sn上的
track = _anim->createNodeTrack(1, sn);
key = track->createNodeKeyFrame(0); // startposition
key->setTranslate(Ogre::Vector3(0, 0,0));
key = track->createNodeKeyFrame(3); // startposition
key->setTranslate(Ogre::Vector3(0, 0,0));
key = track->createNodeKeyFrame(4);
key->setTranslate(Ogre::Vector3(0, 200,0));
//// Create a new animation state to track this
//定义AnimationState类的对象,它和刚才定义的动画类相对应。设置动画的状态为启用:
_animState = sm->createAnimationState("Cam_");
_animState->setEnabled(true);// 启用该动画
_animState->setLoop(false);
//.........这里部分代码省略.........
示例3: getAnimation
/* Function used to load an AnimationState to a sceneNode.
* Params:
* @scnManager the SceneManager
* @node The SceneNode to load the AnimationStates
* @elem The TiXmlElement where is the animation
* Returns:
* anim On success
* 0 On error
*/
bool Util::getAnimation(Ogre::SceneManager *scnManager,
Ogre::SceneNode *node,
TiXmlElement *elem,
std::list<Ogre::AnimationState *> &animList)
{
ASSERT(scnManager);
ASSERT(node);
ASSERT(elem);
if(Ogre::String(elem->Value()) != "animations") {
debug("Invalid animation xml: %s \n", elem->Value());
return false;
}
animList.clear();
TiXmlElement *pElement = elem->FirstChildElement("animation");
if(!pElement){
debug("No animations found\n");
return false;
}
while(pElement){
TiXmlElement *actualElement = pElement;
Ogre::String nombreanimacion = actualElement->Attribute("name");
Ogre::String activada = actualElement->Attribute("enable");
Ogre::String loop = actualElement->Attribute("loop");
Ogre::String modointerpolacion = actualElement->Attribute("interpolationMode");
Ogre::String modointerpolacionrotacion = actualElement->Attribute("rotationInterpolationMode");
Ogre::Real longitud= Ogre::StringConverter::parseReal(actualElement->Attribute("length"));
Ogre::SceneManager *sceneMgr = scnManager;
Ogre::Animation *animrueda = sceneMgr->createAnimation(nombreanimacion,longitud);
if (modointerpolacion == "spline") {
animrueda->setInterpolationMode(Ogre::Animation::IM_SPLINE);
} else //linear
{
animrueda->setInterpolationMode(Ogre::Animation::IM_LINEAR);
}
if (modointerpolacionrotacion == "spherical") {
animrueda->setRotationInterpolationMode(Ogre::Animation::RIM_SPHERICAL);
} else //linear
{
animrueda->setRotationInterpolationMode(Ogre::Animation::RIM_LINEAR);
}
Ogre::NodeAnimationTrack *track = animrueda->createNodeTrack(
animrueda->getNumNodeTracks() + 1, node);
actualElement = actualElement->FirstChildElement();
do {
Ogre::Real tiempo = Ogre::StringConverter::parseReal(
actualElement->Attribute("time"));
Ogre::TransformKeyFrame *kf = track->createNodeKeyFrame(tiempo);
kf->setTranslate(
parseVector3(actualElement->FirstChildElement("translation")));
kf->setRotation(
parseQuaternion(
actualElement->FirstChildElement("rotation")));
kf->setScale(
parseVector3(
actualElement->FirstChildElement("scale")));
} while (actualElement = actualElement->NextSiblingElement());
// Create the animation and put it in the list
Ogre::AnimationState *as = scnManager->createAnimationState(nombreanimacion);
as->setEnabled(false);
as->setLoop(false);
ASSERT(as);
animList.push_back(as);
pElement = pElement->NextSiblingElement("animation");
}
return true;
}