Loading a model is easy. We just need to add two lines of code.
createScene()
method:Ogre::Entity* ent = mSceneMgr->createEntity("MyEntity","Sinbad.mesh"); mSceneMgr->getRootSceneNode()->attachObject(ent);
With mSceneMgr->createEntity("MyEntity","Sinbad.mesh");,we
told Ogre that we wanted a new instance of the Sinbad.mesh
model. mSceneMgr
is a pointer to the SceneManager
of Ogre 3D, created for us by the ExampleApplication
. To create a new entity, Ogre needs to know which model file to use, and we can give a name to the new instance. It is important that the name is unique; it can't be used twice. If this happens, Ogre 3D will throw an exception. If we don't specify a name, Ogre 3D will automatically generate one for us. We will examine this behavior in more detail later.
We now have an instance of a model, and to make it visible, we need to attach it to our scene. Attaching an entity is rather easy just write the following line: mSceneMgr->getRootSceneNode()->attachObject(ent)
;
This attaches the entity to our scene so we can see it. And what we see is Sinbad, the mascot model of Ogre 3D. We will see this model a lot during the course of this book.
18.222.110.183