天天看点

OpenGL ES 中 GLU 做矩阵转换的资料

OpenGL ES 中 GLU 做矩阵转换的资料

<a target="_blank" href="http://blog.csdn.net/opengl_es">转载请保留此句:太阳火神的美丽人生 -  本博客专注于 敏捷开发及移动和物联设备研究:iOS、Android、Html5、Arduino、pcDuino,否则,出自本博客的文章拒绝转载或再转载,谢谢合作。</a>

还是有空再翻译,这些只是用过的知识备忘,其实我只是明白了之后,才找到了这些资料,没弄明白的时侯,并不知道这些资料这么有用。

也许用不了多久,记忆就会消退,当再次需要的时侯,耤由这些点滴的资料,便可唤起曾经的回忆,苦难总是在过去之后,便成为最美好的记忆。

第 4 章 矩阵转换

Chapter 4 Matrix Manipulation

        GLU 库包含对矩阵创建和坐标投影(转换)的支持。矩阵函数创建矩阵并给当前的 OpenGL 矩阵乘以这个结果。他们用于设置投影和视图参数。

坐标投影函数用于将对象空间坐标转换到屏幕坐标或者反之亦然。这使得确定一个对象在窗口的哪里进行绘制成为可能。

The GLU library includes support for matrix creation and coordinate pro-jection (transformation). The matrix routines create matrices and multiply

the current OpenGL matrix by the result. They are used for setting projec-tion and viewing parameters. The coordinate projection routines are used

to transform object space coordinates into screen coordinates or vice-versa.This makes it possible to determine where in the window an object is being

drawn.

4.1 矩阵设置

4.1 Matrix Setup

以下函数创建投影和视图矩阵,并使用 glMultMatrix 把它们应用到当前的矩阵。使用这些函数,用户可以构建一个裁剪体积并设置一个视图参数秋渲染屏幕。

gluOrtho2D 和 gluPerspective 构建常规需要的投影矩阵。

void gluOrtho2D( GLdouble left, GLdouble right, GLdouble bottom, GLdouble top );

设置一个二维的正交视图区域。参数确定了可视区域的边界框。

调用 gluOrtho2D(left, right, bottom, top) 等于调用 glOrtho(left, right, bottom, top, 1, 1) 。

The following routines create projection and viewing matrices and apply

them to the current matrix using glMultMatrix. With these routines, a

user can construct a clipping volume and set viewing parameters to render

a scene.

gluOrtho2D and gluPerspective build commonly-needed projection

matrices.

sets up a two dimensional orthographic viewing region. The pa-

rameters dene the bounding box of the region to be viewed. Call-

ing gluOrtho2D(left, right, bottom, top) is equivalent to calling

glOrtho(left, right, bottom, top, 1, 1).

void gluPerspective( GLdouble fovy, GLdouble aspect, GLdouble near, GLdouble far );

sets up a perspective viewing volume. fovy denes the eld-of-view angle

(in degrees) in the y direction. aspect is the aspect ratio used to determine

the eld-of-view in the x direction. It is the ratio of x (width) to y (height).

near and far dene the near and far clipping planes (as positive distances

from the eye point).

gluLookAt creates a commonly-used viewing matrix:

void gluLookAt( GLdouble eyex, GLdouble eyey,

GLdouble eyez, GLdouble centerx, GLdouble centery,

GLdouble centerz, GLdouble upx, GLdouble upy,

GLdouble upz );

The viewing matrix created is based on an eye point (eyex,eyey,eyez),

a reference point that represents the center of the scene (cen-

terx,centery,centerz), and an up vector (upx,upy,upz). The matrix is de-

signed to map the center of the scene to the negative Z axis, so that when

a typical projection matrix is used, the center of the scene will map to the

center of the viewport. Similarly, the projection of the up vector on the

viewing plane is mapped to the positive Y axis so that it will point upward

in the viewport. The up vector must not be parallel to the line-of-sight from

the eye to the center of the scene.

gluPickMatrix is designed to simplify selection by creating a matrix

that restricts drawing to a small region of the viewport. This is typically used

to determine which objects are being drawn near the cursor. First restrict

drawing to a small region around the cursor, then rerender the scene with

selection mode turned on. All objects that were being drawn near the cursor

will be selected and stored in the selection buer.

void gluPickMatrix( GLdouble x, GLdouble y,

GLdouble deltax, GLdouble deltay,

const GLint viewport[4] );

gluPickMatrix should be called just before applying a projection ma-

trix to the stack (eectively pre-multiplying the projection matrix by the

selection matrix). x and y specify the center of the selection bounding

box in pixel coordinates; deltax and deltay specify its width and height

in pixels. viewport should specify the current viewport's x, y, width, and

height. A convenient way to obtain this information is to call glGetInte-

gerv(GL VIEWPORT, viewport).

4.2 Coordinate Projection

Two routines are provided to project coordinates back and forth from ob-

ject space to screen space. gluProject projects from object space to screen

space, and gluUnProject does the reverse. gluUnProject4 should be

used instead of gluUnProject when a nonstandard glDepthRange is in

eect, or when a clip-space w coordinate other than 1 needs to be spec-

ied, as for vertices in the OpenGL glFeedbackBuer when data type

GL 4D COLOR TEXTURE is returned.

int gluProject( GLdouble objx, GLdouble objy,

GLdouble objz, const GLdouble modelMatrix[16],

const GLdouble projMatrix[16], const GLint viewport[4],

GLdouble *winx, GLdouble *winy, GLdouble *winz );

gluProject performs the projection with the given modelMatrix, pro-

jectionMatrix, and viewport. The format of these arguments is the same as

if they were obtained from glGetDoublev and glGetIntegerv. A return

value of GL TRUE indicates success, and GL FALSE indicates failure.

int gluUnProject( GLdouble winx, GLdouble winy,

GLdouble winz, const GLdouble modelMatrix[16],

GLdouble *objx, GLdouble *objy, GLdouble *objz );

gluUnProject uses the given modelMatrix, projectionMatrix, and view-

port to perform the projection. A return value of GL TRUE indicates success,

and GL FALSE indicates failure.

int gluUnProject4( GLdouble winx, GLdouble winy,

GLdouble winz, GLdouble clipw,

const GLdouble modelMatrix[16],

GLclampd near, GLclampd far, GLdouble *objx,

GLdouble *objy, GLdouble *objz, GLdouble *objw );

gluUnProject4 takes three additional parameters and returns one ad-

ditional parameter clipw is the clip-space w coordinate of the screen-space

vertex (e.g. the wc value computed by OpenGL); normally, clipw = 1. near

and far correspond to the current glDepthRange; normally, near = 0 and

far = 1. The object-space w value of the unprojected vertex is returned in

objw. Other parameters are the same as for gluUnProject.

继续阅读