Tutorial 7         Land Ahoi

Land Ahoi

In a previous tutorial I said that we would come back to selecting different scenemanagers, now is that time. Ogres default SceneManager is an OctreeSceneManager. This scene manager uses Octrees to help cull (Remove) SceneNodes from rendering. Ogre also has a TerrainSceneManager that is based on OctreeSceneManager. This manager has the added feature of rendering a heightmap and texture into a 3D terrain. By using the BSPSceneManager Ogre has the ability to display Quake3 BSP files. One thing to remember when using this scenemanger is that it does NOT implement all of the features in a Quake3 BSP. Another scene manager in Ogre is the NatureSceneManager. This one renders terrain using patches. Each of these SceneManagers can be retrieved from Ogre using the getSceneManager() function.

For instance:

  • To get the BSPSceneManager we would use a call like the following:
  • To get the NatureSceneManager we would use a call like:

When SceneManagers are added to Ogre, they are added via an enumerated value. There are currently 5 predefined values, each representing a SceneManager:


We are going to change the SceneManager in our TutorialApplication now. ExampleApplication has a virtual method that gets called internally that creates the default sceneManager. We will want to override that method in our TutorialApplication. Add the following to the TutorialApplication class definition.

void chooseSceneManager();

Your class should now look like the following.

class TutorialApplication : public ExampleApplication
    virtual ~TutorialApplication();
    void createScene();
    void createFrameListener();
    void chooseSceneManager();
    Entity* mShip;
    SceneNode* mShipNode;

Now add the following code to the end of the TutorialApplication.cpp file.

void TutorialApplication::chooseSceneManager(void)
    // Get the SceneManager, in this case the terrain one
    mSceneMgr = mRoot->getSceneManager( ST_EXTERIOR_CLOSE );

We are going to use the TerrainSceneManager from now on. When the TerrainSceneManager plugin was registered with Ogre, it was registered using the ST_EXTERIOR_CLOSE value. Because we want to use this manager, we have to pass ST_EXTERIOR_CLOSE to the getSceneManager.

In between setSkyDome() and createEntity() in TutorialApplication::createScene() add the following code:

// Create some terrain
mSceneMgr->setWorldGeometry( "terrain.cfg" );

This instructs our SceneManager to use terrain.cfg for creating the terrain (see the format of this file). SetWorldGeometry() is a common method for SceneManagers. Any special scene managers will override this method so that they can load static data. That is data that does not change like terrain or a BSP. Now compile and run our Tutorial.


Hang with me and you will see some real terrain in the next tutorial.