OpenGL Learning--Introduction Chapter III Four Transformations and Examples of Their Use

Four transformations

1. View transformation: view it from different locations;
Involving functions:

glMatrixMode(GL_MODELVIEW);//Set the current operation's matrix to Model View Matrix
glLoadIdentity();//Set the current matrix as a unit matrix

glTranslate* // Multiplies the current matrix with a matrix representing the moving object, and the three parameters represent the position values on three coordinates, respectively
Example:

void glTranslated(GLdouble x, GLdouble y, GLdouble z)
void glTranslatef(GLfloat x, GLfloat y, GLfloat z)

glRotate* //Multiplies the current matrix with a matrix representing a rotating object.The object will rotate counterclockwise around a line from (0,0,0) to (x,y,z), and the angle parameter represents the angle of rotation.
Example:

void glRotated(GLdouble angle, GLdouble x, GLdouble y, GLdouble z)
void glRotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z)

glScale*, multiplies the current matrix by a matrix representing the scaled object.X, y, and Z represent scaling in that direction, respectively.
Example:

void glScalef(GLfloat x,  GLfloat y, GLfloat z);
void glScalex(GLfixed x,  GLfixed y, GLfixed z);

2. Model transformation: moving and rotating objects, enlarging and reducing objects;
3. Projective transformation: Perspective effect of near-large or far-small, only see part of the object, not all (clipping);
OpenGL supports two types of projection transformations, perspective and orthographic. Projections are also implemented using matrices.If you need to manipulate the projection matrix, you need to call the glMatrixMode function with the GL_PROJECTION parameter.
glMatrixMode(GL_PROJECTION);
Typically, we need to set the current matrix as a unit matrix before making the transformation.
glLoadIdentity(); //Operation in Same View Transformation
Two ways to set the current but projected space to perspective
Method 1:
The glFrustum function sets the current visible space to perspective projection space

void glFrustum(GLdouble left, GLdouble Right, GLdouble bottom, GLdouble top, GLdouble near, GLdouble far);
//Create a perspective view.The operation is to create a perspective projection matrix and multiply it by the current matrix.The parameters of this function define only the three-dimensional spatial coordinates of the lower left corner and the upper right corner of the near clipping plane, namely (left, bottom, -near) and (right, top, -near); the last parameter, far, is the distance value of the off-view point of the far clipping plane, whose lower left corner and upper right corner spatial coordinates are automatically generated by the function according to the principle of perspective projection.Nearr and far represent the distance from the viewpoint, and they are always positive (near/far must be > 0).

Method 2:
gluPerspective function

void gluPerspective(GLdouble fovy,GLdouble aspect,GLdouble zNear, GLdouble zFar)
//Create a symmetrical perspective scene, but its parameters are defined differently from the previous one, as shown in the figure.The operation is to create a symmetric perspective projection matrix and multiply it by the current matrix.The parameter fovy defines the angle of the field of view in the Y-Z plane, with a range of [0.0, 180.0]; the parameter aspect is the ratio of the width to the height of the projected plane; and the parameters Near and Far are the distances from the near-far clipping surface to the viewpoint (along the Z negative axis), respectively, and they are always positive.

By default, both functions have the origin and the line of sight is negative along the Z-axis.

Method 3:
The orthographic projection is equivalent to the result observed from an infinite distance, and it is only an ideal state.However, for computers, using orthographic projection may lead to better performance.
The glOrtho function allows you to set the current visible space to be orthographic.

glOrtho(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near, GLdouble far) 
//Six parameters, the first two are the minimum and maximum coordinates of the x-axis, the middle two are the y-axis, and the last two are the z-axis values; it creates a parallel view (that is, a cube space area).

If the drawing space itself is two-dimensional, you can use gluOrtho2D.His use is similar to glOrgho.
Reference:
This blog is good, but it is also reproduced, said more clearly
http://blog.csdn.net/peng6662001/article/details/7082436

4. Viewport transformation: Draw the whole picture you see, not all of it;
The whole understanding is not very good. Later, as you learn more, you will write your own understanding

Continue tomorrow...

Posted by roel_v on Tue, 04 Jun 2019 10:05:29 -0700