The projection matrix and model-view matrix are set and modified with a variety of commands. The affected matrix is determined by the current matrix mode. The current matrix mode is set with

void MatrixMode ( enum mode ) ; 

which takes one of the three pre-defined constants TEXTUREMODELVIEW, or PROJECTION as the argument value. TEXTURE is described later. If the current matrix mode is MODELVIEW, then matrix operations apply to the model-view matrix; if PROJECTION, then they apply to the projection matrix.

The two basic commands for affecting the current matrix are

void LoadMatrix[fd] ( T m[16] ) ; 
void MultMatrix[fd] ( T m[16] ) ; 

LoadMatrix  takes a pointer to a OpenGL中的转换矩阵 matrix stored in column-major order as 16 consecutive floating-point values, i.e. as

OpenGL中的转换矩阵

(This differs from the standard row-major C ordering for matrix elements. If the standard ordering is used, all of the subsequent transformation equations are transposed, and the columns representing vectors become rows.)

The specified matrix replaces the current matrix with the one pointed to. MultMatrix  takes the same type argument as LoadMatrix , but multiplies the current matrix by the one pointed to and replaces the current matrix with the product. If C is the current matrix and M is the matrix pointed to byMultMatrix 's argument, then the resulting current matrix, OpenGL中的转换矩阵, is

OpenGL中的转换矩阵

 

The command

void LoadIdentity ( void ) ; 

effectively calls LoadMatrix  with the identity matrix:

OpenGL中的转换矩阵

 

There are a variety of other commands that manipulate matrices. Rotate , Translate , Scale , Frustum , and Ortho  manipulate the current matrix. Each computes a matrix and then invokes MultMatrix  with this matrix. In the case of

void Rotate[fd] ( T OpenGL中的转换矩阵T xT yT z ) ; 

OpenGL中的转换矩阵 gives an angle of rotation in degrees; the coordinates of a vector OpenGL中的转换矩阵 are given by OpenGL中的转换矩阵. The computed matrix is a counter-clockwise rotation about the line through the origin with the specified axis when that axis is pointing up (i.e. the right-hand rule determines the sense of the rotation angle). The matrix is thus

OpenGL中的转换矩阵

Let OpenGL中的转换矩阵. If

OpenGL中的转换矩阵

then

OpenGL中的转换矩阵

 

The arguments to

void Translate[fd] ( T xT yT z ) ; 

give the coordinates of a translation vector as OpenGL中的转换矩阵. The resulting matrix is a translation by the specified vector:

OpenGL中的转换矩阵

 

void Scale[fd] ( T xT yT z ) ; 

produces a general scaling along the x-, y-, and z- axes. The corresponding matrix is

OpenGL中的转换矩阵

 

For

void Frustum ( double ldouble rdouble bdouble tdouble ndouble f ) ; 

the coordinates OpenGL中的转换矩阵 and OpenGL中的转换矩阵 specify the points on the near clipping plane that are mapped to the lower-left and upper-right corners of the window, respectively (assuming that the eye is located at OpenGL中的转换矩阵). OpenGL中的转换矩阵 gives the distance from the eye to the far clipping plane. If either OpenGL中的转换矩阵 or OpenGL中的转换矩阵 is less than or equal to zero, OpenGL中的转换矩阵 is equal to OpenGL中的转换矩阵OpenGL中的转换矩阵 is equal to OpenGL中的转换矩阵, or OpenGL中的转换矩阵 is equal to OpenGL中的转换矩阵, the error INVALID_VALUE results. The corresponding matrix is

OpenGL中的转换矩阵

 

 

void Ortho ( double ldouble rdouble bdouble tdouble ndouble f ) ; 

describes a matrix that produces parallel projection. OpenGL中的转换矩阵 and OpenGL中的转换矩阵 specify the points on the near clipping plane that are mapped to the lower-left and upper-right corners of the window, respectively. f gives the distance from the eye to the far clipping plane. If OpenGL中的转换矩阵 is equal to OpenGL中的转换矩阵OpenGL中的转换矩阵 is equal to OpenGL中的转换矩阵, or OpenGL中的转换矩阵 is equal to OpenGL中的转换矩阵, the error INVALID_VALUE results. The corresponding matrix is

OpenGL中的转换矩阵

 

There is another OpenGL中的转换矩阵 matrix that is applied to texture coordinates. This matrix is applied as

OpenGL中的转换矩阵

where the left matrix is the current texture matrix. The matrix is applied to the coordinates resulting from texture coordinate generation (which may simply be the current texture coordinates), and the resulting transformed coordinates become the texture coordinates associated with a vertex. Setting the matrix mode to TEXTURE causes the already described matrix operations to apply to the texture matrix.

There is a stack of matrices for each of the matrix modes. For MODELVIEW mode, the stack depth is at least 32 (that is, there is a stack of at least 32 model-view matrices). For the other modes, the depth is at least 2. The current matrix in any mode is the matrix on the top of the stack for that mode.

void PushMatrix ( void ) ; 

pushes the stack down by one, duplicating the current matrix in both the top of the stack and the entry below it.

void PopMatrix ( void ) ; 

pops the top entry off of the stack, replacing the current matrix with the matrix that was the second entry in the stack. The pushing or popping takes place on the stack corresponding to the current matrix mode. Popping a matrix off a stack with only one entry generates the error STACK_UNDERFLOW; pushing a matrix onto a full stack generates STACK_OVERFLOW.

The state required to implement transformations consists of a three-valued integer indicating the current matrix mode, a stack of at least two OpenGL中的转换矩阵matrices for each of PROJECTION and TEXTURE with associated stack pointers, and a stack of at least 32 OpenGL中的转换矩阵 matrices with an associated stack pointer forMODELVIEW. Initially, there is only one matrix on each stack, and all matrices are set to the identity. The initial matrix mode is MODELVIEW.

相关文章:

  • 2022-01-10
  • 2022-12-23
  • 2021-08-11
  • 2022-12-23
  • 2021-06-16
  • 2022-12-23
  • 2022-12-23
  • 2021-05-25
猜你喜欢
  • 2021-11-07
  • 2021-05-13
  • 2021-06-13
  • 2022-12-23
  • 2021-10-13
相关资源
相似解决方案