ogre 3d 1.7 beginner’s guide 第四章 第一小节 中文翻译 准备一个场景
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 control
So 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 a
scene 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_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:
【 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 the code 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);
9. Compile 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 able
to understand what happened. If not, we should go back to the previous chapters and read
them again until we understand everything.
【 我们使用在之前章节学到的东西创建了一个场景。我们应可以理解发生了什么。如果没有的话,我们就应该回过头再看看之前的章节直到我们可以理解为止。】