From the local/object space of the model we constructed to the screen space after a series of processing, there are 6 coordinate systems.
I. World coordinates)
Learning name: Right-hand Cartesian coordinate system.
In OpenGL, the world coordinate system is based on the screen center (0, 0, 0) and remains unchanged. The positive direction of the X axis is the screen from left to right, the positive direction of the Y axis is the screen from bottom up, and the positive direction of the Z axis is the screen from the inside out. The length unit is determined as follows: the window range is exactly from (-1,-1) to (), that is, the coordinates in the lower left corner of the screen are (-1,-1 ), the coordinates in the upper right corner are ).
The direction of the angle θ to be specified during the rotation operation is determined by the right-hand rule, that is, the right hand holds the fist and the thumb goes straight to the square direction of a coordinate axis, then the other four fingers point to the direction of the positive direction of the θ angle on the coordinate axis (that is, the direction of the increase of the θ angle), marked with an arc arrow.
Coordinate Transformation Matrix Stack:
Used to store a series of transformation matrices. The top of the stack is the transformation matrix of the current coordinate. Each coordinate (homogeneous coordinate) that enters the OpenGL pipeline will first Multiply this matrix, the result is the world coordinate of the corresponding point in the scenario. Coordinate Transformations in OpenGL are completed through matrix operations.
Object coordinate system (multiplied by model view matrix) ---> eye coordinate system (multiplied by projection matrix) ---> crop coordinate system (divided by W) ---> standard equipment coordinate system ---> device coordinate system
2. Object Coordinate)
This is the coordinate system for the initial position and direction of the object before any transformation is applied, that is, the current drawing coordinate system. This Coordinate System
Not fixed, And
Applicable only to this object. By default, the coordinate system overlaps with the world coordinate system. The functions used here are:
Gltranslatef (), glscalef (), glrotatef ()When these functions are used to translate, scale, and rotate the current drawing coordinate system, the world coordinate system and the current drawing coordinate system no longer overlap. After the changes, when drawing functions such as glvertex3f () are used, all the functions are drawn in the current drawing coordinate system, and all the function parameters are relative to the current drawing coordinate system. It is the relative position of the object coordinate system and the world coordinate system after the object is transformed.
3. Eye Coordinate)
Model Transformation: Object Coordinate System --> world coordinate system
View Transformation: World coordinate system --> eye Coordinate System
The gl_modelview matrix is a combination of model transformation and an attempt to transform the matrix (view * model), because there is no separate model transformation or view change, therefore, you can use the gl_modelview matrix to convert objects directly from the object coordinate system to the eye coordinate system.
Why do we need to convert it to the eye coordinate system?
Because our observation position is not fixed. If our eyes (cameras) have different positions, the angle of the object to be observed is different, and the appearance of the object is also different. We need to take this step, match the scene with our observation position.
By default, the eye coordinate system overlaps with the world coordinate system. With glulookat (), you can specify the position of the eye (CAMERA) and the direction of the eye. The function is prototype as follows:
1 void gluLookAt(GLdouble eyex, GLdouble eyey, GLdouble eyez, 2 GLdouble centerx, GLdouble centery, GLdouble centerz,3 GLdouble upx, GLdouble upy, GLdouble upz);
In the function parameter, the vertex (eyex, eyey, Eyez) represents the position of the eye;
Point (centerx, centery, centerz) represents the position of the eye;
Vector (UPX, upy, upz) indicates the line of sight in the upward direction,The line between the viewpoint and object and the line of sight must be kept in the upward direction.
Note:
Using gltranslatef (), glscalef (), glrotatef (), these functions are
Object Coordinate SystemChange; Use void glulookat ()
Eye Coordinate SystemTo achieve the same effect. The object does not move the camera, and the camera does not move the object. For example, if the scene moves one unit (the camera does not move) to the positive side of the X axis, the camera moves one unit (the object does not move) to the negative direction of the X axis, gltranslatef (1.0, 0.0, 0.0) <=> glulookat (-1.0, 0.0, 0.0 ,...,...).
4. Clip Coordinate)
Eye coordinates are projected to crop coordinates. The eye coordinate is converted to the crop coordinate by multiplying the gl_projection matrix.
Projection is divided into perspective projection and orthographic projection)
1> Perspective Projection
Similar to the scenes seen in daily life, it is far and near small. Perspective Projection functions include gluperspective () and glfrustum ()
1 void glFrustum(GLdouble left, GLdouble right,2 GLdouble bottom, GLdouble top, 3 GLdouble near, GLdouble far)
1 void gluPerspective(GLdouble fovy, GLdouble aspect,2 GLdouble near, GLdouble far)
Far and near refer to the near-cropping surface. The distance between the far-cropping surface and the viewpoint (> 0), the fovy angle, and aspect = W/H.
2> positive projection
1 void glOrtho(GLdouble left, GLdouble right,2 GLdouble bottom, GLdouble top, 3 GLdouble near, GLdouble far);
Maps an object directly to the screen without affecting its relative size. That is, the image reflects the actual size of an object.
5. Normalized device coordinate)
Divide by W in the crop coordinate system. This operation is called perspective division. The obtained coordinates are [-].
6. Screen Coordinate)
The X axis of the screen coordinates is positive to the right, the Y axis is downward, and the coordinate origin is located in the upper left corner of the window. Yesthe normalization device coordinate system obtained through the viewport Transformation (viewport)
Geometric Transformation
The geometric transformations that can be used in OpenGL include translation, rotation, and scaling.
Gltranslatef (x, y, z );
This function can implement translation transformation. x, y, and z are the number of translations on each coordinate axis.
Glrotatef (θ, x, y, z );
This function implements Rotation Transformation. θ is the rotation angle, and X, Y, and Z are the rotation axes. The orientation of rotation is determined by the right hand rule (see section 1 "coordinate system ").
Glscalef (x, y, z );
This function enables scaling. X, Y, and Z are the expansions of each axis. If it is a negative value, it is scaled along the opposite direction of the axis.
OpenGL Coordinate System