ogre 3d 1.7 beginner’s guide 第四章 第六小节 中文翻译 窗口句柄
Window handle
【 窗口句柄 】
A window handle is simply a number that is used as an identifier for a certain window. This
number is created by the operating system and each window has a unique handle. The
input system needs this handle because without it, it couldn't get the input events. Ogre 3D creates a window for us. So to get the window handle, we need to ask it the following line:
【 一个窗口句柄仅仅是一个识别窗口的数值。这个数值是由操作系统创建并且每个窗口都有自己独一无二的句柄。输入系统需要这个句柄,因为没有它,输入系统就不能获取输入事件。Ogre 3D 为我们创建了一个窗口。所以为了获得窗口句柄,我们需要请求Ogre 3D执行下面一行代码:】
win->getCustomAttribute("WINDOW", &windowHnd);
There are several attributes that a render window has, so Ogre 3D implements a general
getter function. It is also needed to be platform independent; each platform has its own
variable types for window handles, so this is the only way for it to be cross platform. WINDOW is the keyword for the window handle. We need to pass to the function a pointer to storage for the handle value; into this pointer the value will be written. After we receive the handle, we convert it into a string using a stringstream because this is what OIS expects. OIS has the same problem and uses the same solution. During creation, we give OIS a list with parameter pairs consisting of an identifier string and a value string.
【 渲染的窗口有多种属性,Ogre 3D 实现了一个通用getter 函数。Ogre3D也需要平台独立,因为每个平台都有自己的窗口句柄的变量类型,所以通用的函数是跨平台的唯一方法。这段代码中,WINDOW是窗口句柄的标识符。我们需要传递传递一个指针来存贮句柄的值;在函数中这个指针将会被覆写。在我们接受句柄之后,我们使用stringstream来转换它为一个string类型,因为这是OIS所需要的。OIS有同样的问题并使用同样的解决办法。在创建时,我们给OIS一个对组的参数表,这个对组是由一个标识字符串和一个字符串的值组成。】
In step 6, we created this parameter list and added the window handle string. Step 7 used this list to create the input system. With the input system, we can create our keyboard interface in step 8. This interface will be used to query the system—which keys are pressed by the user? This is done with the code in step 9. Every time, before we render a frame, we capture the new state of the keyboard using the capture() function. If we didn't call this function, we won't get the newest state of the keyboard and therefore we won't receive any keyboard events ever. After updating the state, we query the keyboard if the escape key is pressed right now. When this is true, we know the user wants to quit the application. This means we must return false to let Ogre 3D know that we want the application to be shut down. Otherwise, if the user wants the application to keep running, we can return true to keep the application running.
【 在第六步中,我们创建了这个参数表并添加字符串类型的句柄。在第七步使用这个参数表创建了输入系统。通过运用输入系统,我们可以在第八步中创建我们键盘接口。这个接口将会用于查询系统——用户按下的是哪个键?这一步将会在第九步中完成(译者:我认为原作者应该指的是第十步)。每次在我们渲染帧之前,我们使用capture() 函数来获取键盘的新状态。如果不调用这个函数,我们将不会得到键盘的新状态,并此因我们将永远得不到键盘事件了。在更新完状态之后,我们】
Pop quiz – window questions
【 简单测试 —— 有关窗口的问题 】
What is a window handle and how is it used by our application and the operating system?
【 什么是窗口句柄还有它是如何被程序和操作系统所使用的?】