ogre 3d 1.7 beginner’s guide 第三章 第七小节 中文翻译 创建一个摄像机
Creating a camera
【 创建一个摄像机 】
So far, we have always used a camera that was created for use by the
ExampleApplication. Now let's create one for ourselves. A camera, as the name suggests,
captures a part of our scene from a certain position. There can only be one camera active
at a particular time because we only have one output medium, that is, our monitor. But it is
possible to use several cameras in one scene when each one is rendered after the other.
【 目前为止,我们总是使用ExampleApplication类中创建的摄像机。现在让我们自己创建一个摄像机。摄像机,顾名思义,从一个确切的位置来捕捉我们的一部分场景。在某一特定时间只有一个活动的摄像机,那是因为我们仅有一个输出媒体,那就是我们的显示器。但是在场景中也有可能使用数个摄像机当每个摄像机陆续的被渲染。】
Time for action – creating a camera
【 实践时刻 —— 创建一个摄像机 】
This time we won't modify the createScene() function; so just leave it as it is with the
Sinbad instance and shadows:
【 这次我们不修改createScene() 函数;所以保留Sinbad的实例和阴影。】
- Create a new empty function named createCamera() in the ExampleApplication class:
【 在ExampleApplication中创建一个新的名为createCamera()的空函数】
void createCamera() {
}
- Create a new camera named MyCamera1 and assign it to the member mCamera:
【 2. 创建一个新的称为MyCamera1的摄像机并把它分配给数据成员mCamera:】
mCamera = mSceneMgr->createCamera("MyCamera1");
- Set the position of the camera and let it look at the null point:
【 3. 设置摄像机的位置并让其镜头朝向原点:】
mCamera->setPosition(0,100,200);
mCamera->lookAt(0,0,0);
mCamera->setNearClipDistance(5);
- Now change the render mode to wireframe modus:
【 4. 现在改变渲染模式至线框模式 】
mCamera->setPolygonMode(Ogre::PM_WIREFRAME);
- Compile and run the application.
【 5. 编译运行程序。】
What just happened?
【 刚刚发生了什么?】
We overrode the createCamera() function, which initially created a camera and set it
to a position. After creation, we set a position and used the lookat() function to set the
camera up to look at the origin. The next step we did was setting the near clipping distance.
【 我们重写了最初创建摄像机的createCamera() 函数并设置它到一个位置。在创建之后,我们设置完它的位置并且使用lookat()函数以设置摄像机的镜头对准原点。我们所做的下一步是设置剪裁的距离。】
A camera can only see parts of a 3D scene, so rendering it completely would be a waste of
precious CPU and GPU time. To prevent this, before rendering, large parts of the scene are
"cut out" from the scene by the SceneManager. Only objects visible to the camera are
rendered. This step is called culling. Only those objects that are before the near clipping
plane and behind the far clipping plane are rendered and then only when they are inside a
pyramid; this is called the view frustum of the camera. The view frustum is a pyramid with
the top cut off; only those objects that are inside the cut-off pyramid can be seen by the
camera. More information can be found at http://www.lighthouse3d.com/opengl/
viewfrustum/. We set the near clipping plane to 5. When you use a higher-value part of
the scene which is near the camera, it will be culled and not visible.
【 一个摄像机只可以看到部分的3D场景。因为完整渲染需要浪费宝贵的CPU和GPU时间。为避免这种情况,在渲染之前,场景管理器(SceneManager)将会把大部分的场景从场景中裁剪出去。只有摄像机的课件部分被渲染到。这一步叫做拣选。只有位于远近裁剪面并且在视锥体内部的物体才会被渲染。这被称为摄像机的视锥。视锥没有顶部的锥体。只有在剪裁过的锥体内部的对象才能被摄像机所看到。更多信息可在
http://www.lighthouse3d.com/opengl/viewfrustum/ 中找到 】
Then we changed the render mode to wireframe. This effect that we get when we press the R key, as suggested before, is the same as the one we got when we wanted to see the plane triangles. With R, this effect can also be undone. When the application starts, we now see a difference as compared to earlier; the camera is now above the instance of Sinbad and looks down on him.
【 然后我们改变渲染模式为线框模式。】
Before overriding the createCamera() function, the camera started hovering slightly over the plane looking at the origin. With setPosition(0,100,200),
we set the camera higher than before; the following screenshot shows the change. One interesting aspect we can observe is that even after we have created our own instance of a camera, we can still navigate the scene as before. This is possible because we used the mCamera member variable from ExampleApplication. This keeps ExampleApplication in control of our camera and thus it can be modified. One important feature of a camera is that it can also be attached to a scene node and will react the same way an entity does when attached to a scene node.
【 在重写createCamera() 函数之前,摄像机的起始位置是悬停在平面上方一点,镜头朝向原点。使用setPosition(0,100,200),设置我们的摄像机到更高的位置。下面的截图显示了改变的效果。】
Have a go hero – doing more with the thing
【 让英雄动起来 —— 做更多的事 】
Try using different positions and look at points to see how this affects the starting position of the camera. Also try increasing the near clipping distance and try out what effect this has. This should produce funny images like the following, where we can look into Sinbad's head. The near clipping distance was set to 50 to produce this image.
【 尝试设置摄像机到不同位置和使用摄像机不同镜头朝向,查看摄像机在初始位置发生的效果。 同样也尝试一下增加近距离剪裁并试验这种效果是什么。下图可能是我们看到的效果,我们可以看到Sinbad的头部的内部(译注:图中红色的Sinbad的大舌头^_^)。近距离剪裁设置到50可以产生这种效果。】