1. 2D Cartesian coordinates
The coordinates are determined by x and y.
2. 3D Cartesian coordinate system
The coordinates are determined by x, y, and z.
3. The viewport
glViewport(GLint x,GLint y,GLsizei width,GLsizei height)
The size of the window and viewport can be the same or different, usually in proportion to the window.
4. The projection
- The starting point of the light source is called the projection center;
- The line between the projection center and each point on the object is called the projection line;
- The surface receiving the projection is called the projection surface;
- The intersection of the projection line and the projection plane of each point on the object is called the projection of these points.
- Projection is divided into central projection and parallel projection.
- A projection where all projection lines intersect at the center of the projection is called a central projection. Perspectives are drawn using this projection method.
- A projection in which all projection lines are parallel to each other is called a parallel projection. Parallel projection is divided into oblique projection and orthographic projection. When the projection line is tilted to the projection plane, it is called oblique projection; When the projection line is perpendicular to the projection plane, it is called orthographic projection.
4.1 orthogonal projection
Orthographic projection refers to the projection of parallel rays perpendicular to the projection plane.
4.2 Perspective Projection
Perspective projection is a central projection.
A perspective projection is simply called a perspective or perspective, and it is a figure obtained by projecting an object onto a single projection plane from a projection center. Perspective views are very close to the visual effects that people produce when they look at objects. Perspective to render, background, make it into a realistic renderings.
5. Coordinate system in OpenGL ES
OpenGL ES coordinate system includes window coordinates, normalized device coordinates, clipping coordinates and visual coordinates, world coordinates, object coordinates, as shown in the onion into a multi-layer system.
In world, object, camera space is the right hand coordinate system. In the normalized device coordinate system we use the left hand coordinate system.
5.1 Window Coordinate System
The window coordinate is the coordinate system corresponding to the window of our mobile phone. Starting from the upper left corner, the lower right corner corresponds to the collection of the maximum pixel value of our mobile phone. The following picture is a mobile phone with a pixel of 320*480, so the coordinate of his lower right corner is (320,480).
5.2 Standardize the equipment coordinate system
The normalized device coordinates are starting from the center of the screen, with X-axis facing right and Y-axis facing up, so the lower left coordinate is (-1, -1) and the upper right coordinate is (1,1). Of course, this is the display when the z-axis is 0. In fact, the coordinate system of our normalization equipment takes the z-axis into account, so the plane is converted to a cube. The origin coordinate is (0,0,0), which is the center of the cube, and the coordinate of the top left corner nearest to us is (1,1,1). The vertex farthest from us in the bottom right corner is negative 1, negative 1, negative 1.
5.3 Clipping Coordinate System
Clipping coordinates are the coordinates after performing the matrix transformation and perspective projection, but before performing perspective division. Coordinates outside the clipping space are discarded.
5.4 Visual Coordinate System
Vision coordinate system starting from our eyes to look our mobile devices in the past can see, there will be a recent distance and distance of the z axis, namely zNear and zFar, only between the two and also satisfy the x and Y coordinates coordinates will be displayed in the middle of the screen, the farther away the small things will be displayed, perspective effect.
5.5 World Coordinate System
A world coordinate is a fixed coordinate system constructed by the user to describe the position of various objects in this coordinate system with respect to the origin.
5.6 Object Coordinate System
Each object has its own independent coordinate system. As the object rotates and moves, the coordinate system changes accordingly.
5.7 Inertial Coordinate System
Inertial coordinate system is the intermediate product of the transformation between the world coordinate system and the object coordinate system. The origin of the inertial coordinate system coincides with the origin of the body coordinate system, but the axis of the inertial coordinate system is parallel to the axis of the world coordinate system.
** Why introduce inertial coordinate system? ** Because moving from the object coordinate system to the inertial coordinate system requires only rotation, and moving from the inertial coordinate system to the world coordinate system requires only translation.
6. Coordinate transformation in OpenGL
OpenGL renders to the screen in 2D, so we need to perform a series of transformations from 3D coordinates to 2D coordinates, as shown below.
Only clipping coordinate system, normalized device coordinate system and screen coordinate system are defined in OpenGL. Local coordinate system (model coordinate system), world coordinate system and camera coordinate system are all customized coordinate systems designed for the convenience of users, and their relationship is shown in the figure below.
- Model transformation, visual transformation and projection transformation are performed by the user in the vertex shader.
- Perspective division, viewport transformationby
OpenGL
This is done after vertex shader processing.
In development, the transition from local coordinate system (model coordinate system) to cropped coordinate system is obtained by matrix operation. The three matrices are the MVP matrix: the model matrix (M), the observation matrix (V) and the projection matrix (P).
V_clip = M_pro * M_view * M_model * V_local
Copy the code
After the calculation is done in the vertex shader, the result is handed to gl_Position, and OpenGL automatically calculates perspective division and clipping.
6.1 Model Transformation
The purpose of model transformation is to enable the model constructed by vertex definition or 3D model software to be placed to the appropriate position in the scene by shrinking, translating, rotating and other operations as required.
After model transformation, the position of the object is in the global world coordinate system, which is a common coordinate system for all objects to interact.
6.2 depending on the transformation
Visual transformation is a coordinate system set up to facilitate observation of objects in the scene and calculation. The coordinates in the camera coordinate system explain the position in the world coordinate system from the camera’s point of view.