Time for action — loading a model

Loading a model is easy. We just need to add two lines of code.

  1. Add the following two lines into the empty createScene() method:
    Ogre::Entity* ent =
    mSceneMgr->createEntity("MyEntity","Sinbad.mesh");
    mSceneMgr->getRootSceneNode()->attachObject(ent);
    
  2. Compile your application again.
  3. Start your application. You will see a small green figure after starting the application.
  4. Navigate the camera with the mouse and WASD until you see the green figure better.
  5. Close the application.
    Time for action — loading a model

What just happened?

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.

Pop quiz — ExampleApplication and how to display a model

Describe in your own words how to load a model and how to make it visible.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.128.168