glLookAt() 解析

gluLookAt (define a viewing transformation)   定义了视图观测转换

void gluLookAt( GLdoble eyex, GLdouble eyey, GLdouble eyez, GLdouble centerx, GLdouble centery, GLdouble centerz, GLdouble upx, GLdouble upy, GLdouble upz)

parameters

eyex, eyey, eyez                             specifies the position of the eye point   

centerx, centery, centerz             specifies the position of the reference point

upx, upy, upz                                  specifies the direction of the up vector

参数:

眼睛: 设置了眼睛的代表点所在的位置

中心:设置了参考点的坐标

向上方向: 定义了向上的向量

Description

gluLookAt creates a viewing matrix derived from an eye point, a reference point indicating the centre of the scene, and an up vector. The matrix maps the reference point to the negative z axis and the eye point to the origin, so that, when a typical projection matrix is used, the centre of the scene maps to the centre of the viewport. Similarly, the direction described by the up vector projected onto the viewing plane is mapped to the positive y axis so that it points upward in the viewport. The up vector must not be parallel to the line of sight from the eye to the reference point.

The matrix generated by gluLookAt postmultiplies the current matrix.

描述

gluLookAt创建了一个由眼坐标点、一个指示了场景中心的参考点和一个向上的向量三者组成的视图观测矩阵。这个矩阵把参考点映射到z轴的负向、眼坐标点映射到原点,因此,当使用一个典型的投影矩阵时,场景的中心被映射到视口的中心。类似的,由向上向量定义的y轴的正向,因此在视口中的指向是向上的。向上的向量不能与经过眼坐标到参考点的线平行。

由gluLookAt产生的矩阵右乘当前的矩阵。

Using the gluLookAt() Utility Routine

Often, programmers construct a scene around the origin or some other convenient location, then they want to look at it from an arbitrary point to get a good view of it. As its name suggests, the gluLookAt() utility routine is designed for just this purpose. It takes three sets of arguments, which specify the location of the viewpoint, define a reference point toward which the camera is aimed, and indicate which direction is up. Choose the viewpoint to yield the desired view of the scene. The reference point is typically somewhere in the middle of the scene. (If you’ve built your scene at the origin, the reference point is probably the origin.) It might be a little trickier to specify the correct up-vector. Again, if you’ve built some real-world scene at or around the origin and if you’ve been taking the positive y-axis to point upward, then that’s your up-vector for gluLookAt(). However, if you’re designing a flight simulator, up is the direction perpendicular to the plane’s wings, from the plane toward the sky when the plane is right-up on the ground.

gluLookAt()应用(实用)程序的运用

一般来说,程序员会在原点或者其他比较合适的位置创建场景,然后在任意的点观察场景。就像它的名字一样,gluLookAt()应用程序就是用来进行类似设置的。它需要三个设置参数,它们分别定义了试点、相机瞄准的参考点和指示向上方向的向量。通过选择视点来生成想要的场景的视图。而参考点则一般是场景的中点。(如果在原点创建场景的话,参考点则是原点。)而设置向上向量则稍微复杂一些。再次的,如果你是在原点的附近创建场景且你已经选定y轴的正向作为向上向量。然而,如果你是设计一个飞行模拟器的话,那么向上的向量是垂直于机翼,当飞机在地面的正上方时,向上向量是从机身指向天空的。

The gluLookAt() routine is particularly useful when you want to pan across a landscape, for instance. With a viewing volume that’s symmetric in both x and y, the (eyex, eyey, eyez) point specified is always in the center of the image on the screen, so you can use a series of commands to move this point slightly, thereby panning across the scene.

gluLookAt() 应用在你想要平行滑过整个地表的时候非常的有效。例如,如果视域是按照x轴与y轴对称的话,那么(eyex,eyey,eyez)点的设置则会一直处于场景图片的中点,因此你可以通过使用一系列的语句来慢慢的移动这个点,因此达到平滑过整个途径的效果。

In the default position, the camera is at the origin, is looking down the negative z-axis, and has the positive y-axis as straight up. This is the same calling

gluLookAt(0.0,0.0,0.0,    0.0,0.0,-100.0,    0.0,1.0,0.0 )

The z value of the reference point is -100.0, but could be any negative z, because the line of sight will remain the same. In this case, you don’t actually want to call gluLookAt(), because this is the default and you are already there! (The lines extending from the camera represent the viewing volume, which indicates its field of view.)

默认情况下,相机位于原点,指向z轴的负向,同时把y轴的正向作为向上向量。这就相当于调用:gluLookAt(0.0,0.0,0.0,   0.0,0.0,-100.0,    0.0,1.0,0.0 )

参考点的z方向的值是-100.0,它可以任意的z轴负向的值,因为视线仍会一样。这样的话,你不需要真正的调用gluLookAt(),因为这已经是默认的了。(而从相机延伸出来的线则指明了视域)

Note that gluLookAt() is part of the Utility Library rather than the basic OpenGL library. This isn’t because it’s not useful, but because it encapsulates several basic OpenGL commands – specifically, glTranslate*() and glRotate*(). To see this, imagine a camera located at an arbitrary viewpoint and oriented according to a line of sight, both as specified with gluLookAt() and a scene located at the origin. To “undo” what gluLookAt() does, you need to transform the camera so that it sits at the origin and point down the negative z-axis, the default position. A simple translate moves the camera to the origin. You can easily imagine a series of rotations about each of the three axes of a fixed coordinate system that would orient the camera so that it pointed toward negative z values. Since OpenGL allows rotation about an arbitrary axis, you can accomplish any desired rotation of the camera with a single glRotate*() command.

gluLookAt()是隶属于Utility Library而不是OpenGL的基础库。这并不是说它用处不大,而是因为它封装了几个OpenGL的基本语句——glTranslate*()和glRotate*()。可以这样理解,假设相机被安置在了任意的视点并且与视线同指向,这些都是通过gluLookAt()设置的,场景位于原点。如果要撤销gluLooAt()的效果的话,只需要对相机进行转换,使它位于原点切指向Z轴的负向。一个简单的平移就可以把相机移动到原点。你可以想象一系列的旋转,是固定坐标系(这样这个世界就会一直面对着相机)中绕一个轴旋转,即面向z轴的负向。因为OpenGL允许按照任意轴旋转,你可以让相机任意旋转,这只需要一个glRotate*()语句。

Note: You can have only one active viewing transformation. You cannot try to combine the effects of two viewing transformations, any more than a camera can have two tripods. If you want to change the position of the camera, make sure you call glLoadIdentity() to wipe away the effects of any current viewing transformation.

注意:你只能使用一个主要的视图观测转换。而不能试图把两个观测转换的效果结合在一起,多个相机就会有两个三脚架。如果你想要改变相机的位置,调用glLoadIdentity()函数来清除当前观测转换的影响。

Advanced

To transform any arbitrary vector so that it’s coincident with another arbitrary vector (for instance, the negative z-axis); you need to do a little mathematics. The axis about which you want to rotate is given by the cross product of the two normalized vectors. To find the angle of rotation, normalize the initial two vectors. The cosine of the desired angle between the vectors is equal to the dot product of the normalized vectors. The angle of rotation around the axis given by the cross product is always between 0 and 180 degrees.

进阶:

要对任意的向量进行转换,是它变为其他的向量,这需要一些数学计算。轴的旋转可以是由两个齐次的向量的叉乘得到的。计算出旋转的角度、把两个初始化向量进行齐次化。两个向量角度的cosine值就等于齐次化向量的点积。由叉乘得到的轴的旋转角度是介于0到180度之间的。

你可能感兴趣的:(android框架)