English

ogre 3d 1.7 beginner’s guide 第三章 第八小节 中文翻译 创建一个视口

2011/3/2

Creating a viewport

【 创建一个视口 】

Entwined with the concept of a camera is the concept of a viewport. So we will also create

our own viewport. A viewport is a 2D surface which is used for rendering. We can think of it as the paper on which a photo is taken. The paper has a background color and if the photo doesn't cover this region, the background color will be seen.

【 我摄像机概念紧密结合的一个概念就是视口。所以我们也将会创建我们自己的视口。视口是一个被用来渲染的2D表面。我们可以把它当做呈现照片的纸。这种纸有一个底色而且如果照片没有覆盖这个区域,那么底色将被我们所看见。】

Time for action – doing something that illustrates the thing "in action"

【 实践时刻 —— 用“行动”举例说明 】

We will use the code that we used before and once again create a new empty method:

【 我们将会使用之前的代码并且在此创建一个新的方法:】

1.  Remove the setShadowTechnique() function call from the createCamera()

function. We don't want our scene in wireframe mode.

【 1. 删除在createCamera() 函数中调用的setShadowTechnique() 函数。】

    • Create an empty createViewports() method:

【 2. 创建一个空的createViewports() 方法:】

void createViewports() {

}

    • Create a viewport:

【 3. 创建一个视口:】

Ogre::Viewport* vp = mWindow->addViewport(mCamera);

4.  Set the background color and the aspect ratio:

【 4. 设置背景颜色和纵横比:】

vp->setBackgroundColour(ColourValue(0.0f,0.0f,1.0f));

mCamera->setAspectRatio(Real(vp->getActualWidth()) / Real(vp->getActualHeight()));

5.Compile and run the application.

【 编译运行程序。】

What just happened?

【 刚刚发生了什么?】

We created a viewport. To do this, we needed to pass a camera to the function. 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. The most noticeable change is that the background color

changed from black to blue. The reason should be obvious: the new viewport has the

background color blue; we set it in step 3. Also in step 3, we set the aspect ratio—the aspect ratio describes the ratio between the width and height of a rendered image; in math terms: aspect ratio = width of window divided by height of window.

【 我们创建一个视口。创建的时,我们需要传递一个摄像机作为函数的参数。每个视口只可渲染一个摄像机的视野,所以在传参时,Ogre 3D强制函数只能接受一个摄像机作为参数。当然,摄像机可适当地使用getter和setter函数以发生改变。最值得注意的改变是背景色从黑色变为蓝色。原因很明显:在第三步中,新的视口设置背景色为蓝色。同样在第三步,我们设置了纵横比——纵横比描述了当渲染图像时宽和高的比例。数学公式为:纵横比 = 窗口宽度 / 窗口高度】

Have a go hero – playing with different aspect ratio

【 让英雄动起来 —— 使用不同的纵横比 】

Try playing with different aspect ratios and see how this affects the image produced. Also

change the background color. Here is an image where the width of the aspect ratio is divided by five.

【 尝试使用不同的纵横比并查看图形产生的不同效果。同样的,改变背景色并查看效果。下面的图片是纵横比的宽度设置为1/5的效果图。】

Summary

【 概要】

In this chapter, we added lights and shadows to our scene, created a viewport, and worked with a viewfrustum.

【 在这一章,我们添加光源和阴影到我们的场景,创建了视口并且了解了无锥顶的视锥体。】

Specifically, we covered:

* What lights are and how they can modify the appearance of our scene

* Adding shadows to our scene

* Creating our own camera, frustum, and viewport

【具体来说,我们讨论:

 什么是光源和他们如何修改场景的外观。

 添加阴影到我们的场景

 创建我们自己的摄像机,无锥顶视锥体和视口

In the next chapter, we will learn how to process user input from the keyboard and mouse.

We will also learn what a FrameListener is and how to use it.

【 在下一章,我们将会学习如何处理用户的键盘和鼠标输入。我们将会学习什么是帧监听和如何使用它。】