Glloadidentity () Move the origin of the current user coordinate system to the center of the screen: similar to a reset operation 1. X axis from left to right, Y axis from bottom to top, and Z axis from inside to outside. 2. The coordinates of the OpenGL screen center are 0.0f points on the X and Y axes. 3. The coordinate value on the left of the center is a negative value, and the right is a positive value. Moving to the top of the screen is positive, and moving to the bottom of the screen is negative. Moving to the depth of the screen is a negative value, and moving out of the screen is a positive value. Gltranslatef (x, y, z) Move along the X, Y, and Z axes. Note that in gltranslatef (x, y, z), when you move, you do not move relative to the center of the screen, but relative to the current screen position. The function is to translate the origin of the Point coordinate to A (x, y, z) vector based on the current origin. //////////////////////////////////////// //////////////////////////////////////// ///////////////////////////// Glloadidentity (); Gltranslatef (-1.5f, 0.0f,-6.0f ); Glbegin (gl_triangles ); Glvertex3f (0.0f, 0.0f, 0.0f ); Glvertex3f (1.0f, 0.0f, 0.0f ); Glvertex3f (0.0f, 1.0f, 0.0f ); Glend (); Glloadidentity (); Gltranslatef (0.0f, 0.0f,-6.0f ); Glbegin (gl_triangles ); Glvertex3f (0.0f, 0.0f, 0.0f ); Glvertex3f (1.0f, 0.0f, 0.0f ); Glvertex3f (0.0f, 1.0f, 0.0f ); Glend (); //////////////////////////////////////// //////////////////////////////////////// ///// ProgramThe running result is as follows: The triangle on the left is drawn in the first step. We can see that the coordinate system drawn by the triangle is actually based on (-1.5f, 0.0f,-6.0f. When the second triangle is drawn, the origin is located in the center of the screen Because glloadidentity () is used to re-return the origin to the center of the screen. glrotatef ( angle, x, y, z ) similar to gltranslatef (x, y, z), glrotatef (angle, x, y, z) it also operates on the coordinate system. the rotation axis goes through the origin, with the direction (x, y, z), angle, and right direction specified. ///////////////////////////////////// /// // glloadidentity (); gltranslatef (0.0f, 0.0f,-6.0f); glbegin (gl_triangles); glvertex3f (0.0f, 0.0f, 0.0f); glvertex3f (1.0f, 0.0f, 0.0f); glvertex3f (0.0f, 1.0f, 0.0f); glend (); ///////////////////////////////////// /// // if not rotated: //////////////////////////////////////// //////////////////////// Glloadidentity (); Glrotatef (45, 0.0f, 0.0f, 1.0f ); Gltranslatef (0.0f, 0.0f,-6.0f ); Glbegin (gl_triangles ); Glvertex3f (0.0f, 0.0f, 0.0f ); Glvertex3f (1.0f, 0.0f, 0.0f ); Glvertex3f (0.0f, 1.0f, 0.0f ); Glend (); //////////////////////////////////////// //////////////////////// The positive rotation around the Z axis is 45 degrees, because the positive direction of the Z axis is directed to the outside of the screen from the screen, and the Right Hand determines that the direction is clockwise. Since the right vertex is the origin point, it is rotated around the right corner counterclockwise. How does a program execute the rotation and translation functions? Translation only: //////////////////////////////////////// /// // glloadidentity (); // reset the current modelview Matrix Gltranslatef (0.0f, 0.0f,-6.0f ); Glbegin (gl_quads ); Glvertex3f (-0.01f,-0.01f, 0.0f ); Glvertex3f (0.01f,-0.01f, 0.0f ); Glvertex3f (0.01f, 0.01f, 0.0f ); Glvertex3f (-0.01f, 0.01f, 0.0f ); Glend (); Glloadidentity (); // Glrotatef (45.0f, 0.0f, 0.0f, 1.0f ); Gltranslatef (1.0f, 0.0f,-6.0f );
Glbegin (gl_triangles ); Glvertex3f (0.0f, 0.0f, 0.0f ); Glvertex3f (1.0f, 0.0f, 0.0f ); Glvertex3f (0.0f, 1.0f, 0.0f ); Glend (); //////////////////////////////////////// //// // The condition of rotation is added: /// // glloadidentity (); // reset the current modelview Matrix Gltranslatef (0.0f, 0.0f,-6.0f ); Glbegin (gl_quads ); Glvertex3f (-0.01f,-0.01f, 0.0f ); Glvertex3f (0.01f,-0.01f, 0.0f ); Glvertex3f (0.01f, 0.01f, 0.0f ); Glvertex3f (-0.01f, 0.01f, 0.0f ); Glend (); Glloadidentity (); Glrotatef (45.0f, 0.0f, 0.0f, 1.0f ); Gltranslatef (1.0f, 0.0f,-6.0f );
Glbegin (gl_triangles ); Glvertex3f (0.0f, 0.0f, 0.0f ); Glvertex3f (1.0f, 0.0f, 0.0f ); Glvertex3f (0.0f, 1.0f, 0.0f ); Glend (); //// // If the rotation and the sequence of the statements are in the same what will happen if I change the result? //// // Glloadidentity (); // reset the current modelview Matrix Gltranslatef (0.0f, 0.0f,-6.0f ); Glbegin (gl_quads ); Glvertex3f (-0.01f,-0.01f, 0.0f ); Glvertex3f (0.01f,-0.01f, 0.0f ); Glvertex3f (0.01f, 0.01f, 0.0f ); Glvertex3f (-0.01f, 0.01f, 0.0f ); Glend (); Glloadidentity (); Gltranslatef (1.0f, 0.0f,-6.0f ); Glrotatef (45.0f, 0.0f, 0.0f, 1.0f );
Glbegin (gl_triangles ); Glvertex3f (0.0f, 0.0f, 0.0f ); Glvertex3f (1.0f, 0.0f, 0.0f ); Glvertex3f (0.0f, 1.0f, 0.0f ); Glend ();////////////////////////// These three examples show that the execution sequence of all statements that perform operations such as pan rotation on the image is from bottom to top. In addition, the center of the rotation Statement (0.0f, 0.0f, 0.0f) is known. ///////////////////////////////////// /// // glloadidentity (); glrotatef (45, 0.0f, 0.0f, 1.0f); glloadidentity (); gltranslatef (0.0f, 0.0f,-6.0f); glbegin (gl_triangles); glvertex3f (0.0f, 0.0f, 0.0f ); glvertex3f (1.0f, 0.0f, 0.0f); glvertex3f (0.0f, 1.0f, 0.0f); glend (); ////////////////////////////////// //// // After rotation, a reset is added. command, the image will not be rotated. |