
Loading a model is easy. We just need to add two lines of code.
- Add the following two lines into the empty
createScene()
method:Ogre::Entity* ent = mSceneMgr->createEntity("MyEntity","Sinbad.mesh"); mSceneMgr->getRootSceneNode()->attachObject(ent);
- Compile your application again.
- Start your application. You will see a small green figure after starting the application.
- Navigate the camera with the mouse and WASD until you see the green figure better.
- Close the application.
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.