As always, we are using the code from our previous excercises:
At the end of the
createScene()
function, create two instances of the sword model and name themSword1
andSword2:
Ogre::Entity* sword1 = mSceneMgr->createEntity("Sword1", "Sword.mesh"); Ogre::Entity* sword2 = mSceneMgr->createEntity("Sword2", "Sword.mesh");
Now attach the sword to the model using a bone name:
_SinbadEnt->attachObjectToBone("Handle.L", sword1); _SinbadEnt->attachObjectToBone("Handle.R", sword2);
Compile and run the application. There should be two swords in the hands of Sinbad.
We created two instances of the sword model and attached them to bones. The creation of the instances shouldn't be too difficult to understand. The difficult and interesting part is the function called attachObjectToBone()
. To understand what this function does, we need to discuss how animations are saved and played.