Time for action — preparing a scene

We will use a slightly different version of the scene from the previous chapter:

  1. Delete all code in the createScene() and the createCamera() functions.
  2. Delete the createViewports() function.
  3. Add a new member variable to the class. This member variable is a pointer to a scene node:
    private:
    Ogre::SceneNode* _SinbadNode;
    
  4. Create a plane and add it to the scene using the createScene() method:
    Ogre::Plane plane(Vector3::UNIT_Y, -10);
    Ogre::MeshManager::getSingleton().createPlane("plane",
    ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane,
    1500,1500,200,200,true,1,5,5,Vector3::UNIT_Z);
    Ogre::Entity* ent = mSceneMgr->createEntity("LightPlaneEntity", "plane");
    mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent);
    ent->setMaterialName("Examples/BeachStones");
    
  5. Then add a light to the scene:
    Ogre::Light* light = mSceneMgr->createLight("Light1");
    light->setType(Ogre::Light::LT_DIRECTIONAL);
    light->setDirection(Ogre::Vector3(1,-1,0));
    
  6. We also need an instance of Sinbad; create a node and attach the instance to it:
    Ogre::SceneNode* node = mSceneMgr->createSceneNode("Node1");
    mSceneMgr->getRootSceneNode()->addChild(node);
    Ogre::Entity* Sinbad = mSceneMgr->createEntity("Sinbad", "Sinbad.mesh");
    _SinbadNode = node->createChildSceneNode("SinbadNode");
    _SinbadNode->setScale(3.0f,3.0f,3.0f);
    _SinbadNode->setPosition(Ogre::Vector3(0.0f,4.0f,0.0f));
    _SinbadNode->attachObject(Sinbad);
    
  7. We also want shadows in this scene; so activate them:
    mSceneMgr->setShadowTechnique(SHADOWTYPE_STENCIL_ADDITIVE);
    
  8. Create a camera and position it at (0,100,200) and let it look at (0,0,0); remember to add the code to the createCamera() function:
    mCamera = mSceneMgr->createCamera("MyCamera1");
    mCamera->setPosition(0,100,200);
    mCamera->lookAt(0,0,0);
    mCamera->setNearClipDistance(5);
    
  9. Compile and run the application, and you should see the following image:
    Time for action — preparing a scene

What just happened?

We used the knowledge from the previous chapters to create a scene. We should be able to understand what happened. If not, we should go back to the previous chapters and read them again until we understand everything.

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

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