Coordinate system mapping
Ron GeryMicrosoft Developer Network Technology GROUP
(Translator Note: This article is written in 92 years, it is more old, but for beginners like me, I will have inspirational significance, I am willing to share with all beginners. Given the limited level, please Haihan, don't throw a stone to me. Ah, some people have throw, & (* ^ () _) (* & ^%, I run))
Abstract This article discusses mapping mode in the Microsoft Windows graphics environment - what is it, how to work and their true meaning. Mainly used the following functions: SetMapMode, SetWindowext, SetViewPortext, SetWindoworg, SetViewportorg, Lptodp, and DPTOLP.
First, introduction
By using the Microsoft Windows Graphics Map Rules, the application can create a logical coordinate system that is not subject to real-world constraints. By default, a logical unit is equal to a pixel in the device, but a logical unit in the application can represent other scales - such as a pixel of 1 mm or 600 dpi printer. By using a logical coordinate system, the application can separate the drawing process from the actual pixel resolution of the target device.
The coordinate system mapping mechanism includes two rectangles: The window defines a rectangle of the logical coordinate space, the viewport defines a rectangle in the target device. These two rectangles have established the proportion of logical units and device units - the size of the unit in the window in the viewport, and vice versa. In the same place, the window origin is directly mapped to the origin of the visor. Figure (1) Explaining this concept:
figure 1
Define negative ranges to flip the direction of the coordinate axis. For example, the range of a negative window Y and the range of positive view ports Y is incremented up in the logical coordinate system, and the traditional Y is incremented down. This program can operate in traditional mathematical coordinate space.
The coordinate system is not subject to the defined rectangular limit, which only establishes a ratio, not the specific space size.
GDI can enable the application to create a window and viewport rectangle, or select a predefined setting. Windows defines eight mapping patterns; six have predefined settings, two can make applications some mobile. When the DC is established by the coordinate map, the next program code must be aware of it only in the logical coordinate system.
Second, how did it work?
The GDI function will transform the input logical coordinates into device units before specific calculation or passing to the device. For DCs belonging to a specific window (obtained via the getDC or CS_OWNDC style), an additional conversion in GDI occurs because the origin of these DCs is not on the top left corner of the screen. These conversions are invisible for the application. Those DCs that are not belong to the window (such as the DCS or Memory DCS of the printer), which origin is in the upper left corner of the device. Since the device driver only understands the coordinates located on the upper left corner on the surface. Conversely, the drivers and GDI convert them to logical coordinates before returning the coordinate.
The conversion formula of the equipment coordinates and logical coordinates is as follows:
DX = ((lx - wox) * VEX / WEX) VOX
Lx = ((DX - VOX) * WEX / VEX) WOX
among them
DX
X value (equipment unit)
LX
X value (logical unit)
Wox
Window origin x value
VOX
Viewport origin X value
WEX
Range of window X direction
VEX
Range of viewport X direction
Similar to the Y value.
This formula is not complicated. First, this point is shifted from the coordinate origin (the logical coordinates relative to the window origin, the device coordinates relative to the origin of the origin), the obtained value is no longer deviating from the origin, and then scaled in the target coordinate system according to the proportion Finally, the zoom value is offset by the origin of the target system, resulting in the final coordinate in the target system. Windows3.1 and Windows 3.0 processing overflow calculations are different. In Windows 3.0, when the overflow occurs (16 bits), this value is given the maximum value of the same symbol (positive: 0x7FFF, negative: 0x8000), and calculates the abort. In Windows3.1, the calculation is based on 32-bit, and the opportunity to eliminate overflow is eliminated unless the maximum is reached, the processing is the same as Windows 3.0. (I seem to have the same way to handle the process. J)
The following describes the WINDOWS mapping mode, and there are other books, and I will go.