3D observation and coordinate transformation
The computer generating process of the three-dimensional landscape view is similar to the camera process of the object with the camera. We need to position the camera and determine the direction of the lens. When pressing the shutter, it is equivalent to cropping the scene with the lens as the window.
In computer graphics, we can achieve observation of three-dimensional objects by establishing observation coordinate systems in the world coordinate system. (See Figure 1 below)
First, establish observation coordinate system, transform the coordinates of the three-dimensional object in the world coordinate system into observation coordinates.
Second, the observation plane is established in the observation coordinate system, and the coordinates are observed to observe the observation plane.
Yw
XW
ZW
Xv
ZV
YV
Figure 1 World coordinate system and observation coordinate system
CY
X
Y
. Point
CX
Figure 2 Sitting under Window GDI
(0, 0)
(1,0)
(0, 1)
(-1,0)
(0, -1)
Figure 3 System coordinate system under OpenGL
Rear section
Front cross section
Observation window
.
point
hide
Figure 4 Configuration Space of Perspective Projection
Suppose we want to implement the left mouse button to click on the point:
Press the left mouse button in the window, issue the WM_LBUTTONDOWN message, the Void ONLBUTTONDOWN (CPOINT) function processes the message, where Point is relative to the coordinate system in Figure 2, to want to display correctly in the screen, must be The point coordinate value is converted to the standard device coordinate under OpenGL.
The first step is to convert the coordinate of the GDI to the observation coordinate coordinate value. Suppose is the establishment of perspective projection observation coordinate system
:: Gluperspective (90.0F, aspect_ratio, .01f, 100.0f);
X_ratio = Point.x / CX;
Y_ratio = Point.y / cy;
h represents the size of the Z-axis in the observation coordinate system, that is, depth information.
The length and width of the cross section of this point can be obtained by h and angles.
The coordinate value of this point in the cross section is obtained according to X_RATIO and Y_RATIO.
In the second step, it is projected from the coordinates in the cross section to the standard equipment coordinates.