History: Loading Animations without a RenderSystem
Source of version: 3 (current)
Copy to clipboard
{CODE(wrap="1", colors="c++")} #include "conio.h"
#include "stdlib.h"
#include "OgreMeshManager.h"
#include "OgreRoot.h"
#include "OgreDefaultHardwareBufferManager.h"
void main()
{
// start ogre
Ogre::Root* root = new Ogre::Root("", "", "ogre.log");
new Ogre::DefaultHardwareBufferManager();
// add resources
Ogre::ResourceGroupManager::getSingletonPtr()->addResourceLocation("./media", "FileSystem", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
// initialise resource paths
Ogre::ResourceGroupManager::getSingletonPtr()->initialiseAllResourceGroups();
// load the mesh
Ogre::MeshPtr mesh = Ogre::MeshManager::getSingleton().load("robot.mesh", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
// create & load a SkeletonInstance
Ogre::SkeletonInstance* skelInst = new Ogre::SkeletonInstance(mesh->getSkeleton());
skelInst->load();
// create & load an AnimationStateSet
Ogre::AnimationStateSet* animStateSet = new Ogre::AnimationStateSet();
mesh->_initAnimationState(animStateSet);
// enable the "Walk" AnimationState and loop it
Ogre::AnimationState* animState = animStateSet->getAnimationState("Walk");
animState->setEnabled(true);
animState->setLoop(true);
while(!kbhit())
{
// clear the screen
system("cls");
// print out bone positions, to see that it's working
Ogre::Skeleton::BoneIterator it = skelInst->getBoneIterator();
while(it.hasMoreElements())
{
std::cout << Ogre::StringConverter::toString(it.getNext()->_getDerivedPosition()) << std::endl;
}
// instead of this fixed time value, you would of course use
// the dynamic frame-time of your main application loop
animState->addTime(0.001);
// update the skeleton instance
skelInst->setAnimationState(*animStateSet);
}
// cleanup
mesh.setNull();
delete skelInst;
delete animStateSet;
delete root;
}
{CODE}