上QQ阅读APP看书,第一时间看更新
We will use a slightly different version of the scene from the previous chapter:
- Delete all code in the
createScene()
and thecreateCamera()
functions. - Delete the
createViewports()
function. - Add a new member variable to the class. This member variable is a pointer to a scene node:
private: Ogre::SceneNode* _SinbadNode;
- 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");
- 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));
- 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);
- We also want shadows in this scene; so activate them:
mSceneMgr->setShadowTechnique(SHADOWTYPE_STENCIL_ADDITIVE);
- 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);
- Compile and run the application, and you should see the following image: