OGRE_3D_1.7_Beginner's_Guide_第四章

  • 格式:doc
  • 大小:407.50 KB
  • 文档页数:24

[声明:本人仅仅英语四级水平,因为喜欢翻译和喜欢Ogre,翻译以下文字,如果哪里有错误或不足还望大虾们见谅,如果您发现有什么错误,请把问题发送到whistleofmysong@,我将尽快的改正。

想到可能对新手有些许帮助,所以对别人是个帮助,对自己也是个鼓励~^_^ ]4 Getting User Input and Using the Frame Listener【第四章获取用户输入和使用帧监听】Until now, we always created scenes which were static and didn't have anything moving in them. We will change this with this chapter.【迄今为止,我们总是创建静止的场景并且在场景中没有移动的物体。

在这一章,我们将会改变这种现状。

】In this chapter, we will:* Learn what a FrameListener is* Learn how to process user input* Combine both concepts to create our own camera controlSo let's get on with it...【在这章,我们将会:●认识什么是帧监听●认识如何处理用户输入●结合两种概念创建我们自己的相机控制】Preparing a scene【准备一个场景】Before adding moving things to our scene, we need a scene to add them to. So let's create a scene.【在添加移动物体之前,我们首先应创建一个可添加物体的场景。

然后让我们一起创建一个场景吧。

】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.【1. 删除createScene() 和createCamera() 函数中的所有代码:】2. Delete the createViewports() function.【2. 删除createViewports()函数。

】3. Add a new member variable to the class. This member variable is a pointer to ascene node:【3. 添加一个新的成员变量到类中。

这个成员变量是一个场景结点的指针:】private:Ogre::SceneNode* _SinbadNode;4.Create a plane and add it to the scene using the createScene() method:【4. 使用createScene() 函数创建一个平面并添加它到场景之中:】Ogre::Plane plane(Vector3::UNIT_Y, -10);Ogre::MeshManager::getSingleton().createPlane("plane",ResourceGroupManager::DEFAULT_R ESOURCE_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:【5. 然后添加一个光源到场景中:】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:【6. 我们也需要一个Sinbad的实例,创建一个结点并关联实例。

】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:【7. 我们也想在场景中增加阴影;所以添加它们:】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 thecode to the createCamera() function:【8. 创建一个摄像机并放置它在(0,100,200) 并把镜头朝向(0,0,0);记住添加代码到createCamera() 函数中。

】mCamera = mSceneMgr->createCamera("MyCamera1");mCamera->setPosition(0,100,200);mCamera->lookAt(0,0,0);mCamera->setNearClipDistance(5);pile and run the application, and you should see the following image:【编译运行,你将会看到下面图中的效果】What just happened?【刚刚发生了什么?】We used the knowledge from the previous chapters to create a scene. We should be ableto understand what happened. If not, we should go back to the previous chapters and readthem again until we understand everything.【我们使用在之前章节学到的东西创建了一个场景。

我们应可以理解发生了什么。

如果没有的话,我们就应该回过头再看看之前的章节直到我们可以理解为止。

】Adding movement to the scene【添加运动到场景之中】We have created our scene; now let's add movement to the scene.【我们已经创建了场景;现在让我们把运动添加进场景中。

】Time for action – adding movement to the scene【实践时刻——添加运动到场景中】Up until now, we only had one class, namely, ExampleApplication. This time we needanother one:【目前为止,我们只有一个类,即是,ExampleApplication。

这次我们需要另一个类:】1. Create a new class, name it Example25FrameListener, and let it inherit publiclyfrom Ogre::FrameListener:【1. 创建一个新类,命名为Example25FrameListener,并使它从Ogre::FrameListener 中公有继承。

】class Example25FrameListener : public Ogre::FrameListener{};2. Add a private member variable, which is an Ogre::SceneNode pointer, and nameit _node:【2. 添加一个私有的成员变量,一个Ogre::SceneNode的指针,并把它命名为_ node】private:Ogre::SceneNode* _node;3. Add a public constructor that takes an Ogre::SceneNode pointer as a parameterand assigns it to the member node pointer:【3. 添加接收一个Ogre::SceneNode指针为参数的公有构造函数,并把这个指针赋值操作给成员变量node 指针。