#include "ExampleApplication.h" class Example3:public ExampleApplication { public: void createScene() { /* //1 begin Ogre::Plane plane(Vector3::UNIT_Y,-10); Ogre::MeshManager::getSingleton().createPlane("plane",ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,plane,1500,1500,20,20,true,1,5,5,Vector3::UNIT_Z); Ogre::Entity* ent=mSceneMgr->createEntity("LightPlaneEntity","plane"); mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent); ent->setMaterialName("Examples/BeachStones"); //1 end //2_1 begin Ogre::SceneNode* node1=mSceneMgr->createSceneNode("Node1"); mSceneMgr->getRootSceneNode()->addChild(node1); Ogre::Light* light1=mSceneMgr->createLight("MyLight1"); light1->setType(Ogre::Light::LT_POINT); light1->setPosition(0,20,0); light1->setDiffuseColour(1.0f,1.0f,1.0f); Ogre::Entity* LightEnt1=mSceneMgr->createEntity("MyEntity1","sphere.mesh"); Ogre::SceneNode* node2=node1->createChildSceneNode("Node2"); node2->setPosition(0,20,0); node2->setScale(0.1f,0.1f,0.1f); node2->attachObject(LightEnt1); //2_1 end //3_2 begin Ogre::Light *light2=mSceneMgr->createLight("MyLight2"); light2->setType(Ogre::Light::LT_POINT); light2->setPosition(20,20,20); light2->setDiffuseColour(1.0f,1.0f,1.0f); Ogre::Entity* LightEnt2=mSceneMgr->createEntity("MyEntity2","sphere.mesh"); Ogre::SceneNode* node3=node1->createChildSceneNode("Node3"); node3->setPosition(20,20,20); node3->setScale(0.1f,0.1f,0.1f); node3->attachObject(LightEnt2); //3_2 end*/ //4|all begin 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"); Ogre::SceneNode* node1=mSceneMgr->createSceneNode("Node1"); mSceneMgr->getRootSceneNode()->addChild(node1); Ogre::SceneNode* node4=node1->createChildSceneNode("Node4"); node4->setPosition(0,100,0); Ogre::Light* pSpotLight1=mSceneMgr->createLight("MySpotLight1"); pSpotLight1->setType(Ogre::Light::LT_SPOTLIGHT); pSpotLight1->setDirection(Ogre::Vector3(1,-1,0)); pSpotLight1->setSpotlightInnerAngle(Ogre::Degree(5.0f)); pSpotLight1->setSpotlightOuterAngle(Ogre::Degree(45.0f)); pSpotLight1->setSpotlightFalloff(0.0f); pSpotLight1->setDiffuseColour(Ogre::ColourValue(0.0f,1.0f,0.0f)); node4->attachObject(pSpotLight1);//如果不显示附着,则是在RootSceneNode()上附着 Ogre::Entity* GreenSpotLightSphere=mSceneMgr->createEntity("GreenSpotLightSphere","sphere.mesh"); node4->setScale(0.1f,0.1f,0.1f); node4->attachObject(GreenSpotLightSphere); Ogre::SceneNode* redspotlightnode=node1->createChildSceneNode("RedSpotLightNode"); Ogre::Light* redspotlight=mSceneMgr->createLight("RedSpotLight"); redspotlight->setType(Ogre::Light::LT_SPOTLIGHT); redspotlight->setDiffuseColour(Ogre::ColourValue(1.0f,0.0f,0.0f)); redspotlight->setDirection(-1,-1,0); redspotlight->setSpotlightInnerAngle(Ogre::Degree(5.0f)); redspotlight->setSpotlightOuterAngle(Ogre::Degree(45.0f)); redspotlight->setSpotlightFalloff(0.0f); redspotlightnode->attachObject(redspotlight); Ogre::Entity* redspotlightsphere=mSceneMgr->createEntity("RedSpotLightSphere","sphere.mesh"); redspotlightnode->setScale(0.1f,0.1f,0.1f); redspotlightnode->setPosition(200,100,0);//注意是结点位移,不是灯光位移,否则球体不位移 redspotlightnode->attachObject(redspotlightsphere); //4|all end //5_4 begin Ogre::Light* directionallight=mSceneMgr->createLight("DirectionLight"); directionallight->setType(Ogre::Light::LT_DIRECTIONAL); directionallight->setDirection(1,-1,0);//方向光源无需attach directionallight->setDiffuseColour(Ogre::ColourValue(1.0f,1.0f,1.0f)); //5_4 end //6_5 begin Ogre::Entity* Sinbad=mSceneMgr->createEntity("Sinbad","Sinbad.mesh"); Ogre::SceneNode* SinbadNode=mSceneMgr->getRootSceneNode()->createChildSceneNode("SinbadNode"); SinbadNode->setPosition(Ogre::Vector3(0.0f,4.0f,0.0f));//平面在-10,-10+14(Sinbad放大3倍后下半身长度为14)=4 SinbadNode->setScale(3.0f,3.0f,3.0f); SinbadNode->attachObject(Sinbad); //6_5 end //7_6 begin mSceneMgr->setShadowTechnique(Ogre::SHADOWTYPE_STENCIL_ADDITIVE); //7_6 end } //8_7 begin void createCamera() { mCamera=mSceneMgr->createCamera("MyCamera1"); mCamera->setPosition(0,100,200); mCamera->lookAt(0,0,0); mCamera->setNearClipDistance(5); //8.1 begin //mCamera->setPolygonMode(Ogre::PM_WIREFRAME); //8.1 end } //8_7 end //9_8|8.1 begin void createViewports() { Ogre::Viewport* vp=mWindow->addViewport(mCamera); vp->setBackgroundColour(Ogre::ColourValue(0.0f,0.0f,1.0f)); //9.1 begin //mCamera->setAspectRatio(Real(vp->getActualWidth())/Real(vp->getActualHeight())); //9.1 end //10_9|9.1 begin mCamera->setAspectRatio(0.2); //10_9|9.1 end } //9_8|8.1 end }; int main() { Example3 app; app.go(); return 0; }
--->mSceneMgr -----> mCamera
mRoot
--->mWindow ----------> addViewport(mCamera)
There can only be one camera active at a particular time
Each viewport can only render the view of one camera,so Ogre 3D enforces that one camera is given during creation.Of course,the camera can be changed later using the appropriate getter and setter functions.