VC: 3D view plotting and blanking technology

zhaozj2021-02-17  43

VC: Three-dimensional view drawing and blanking technology Zhou Jianhua (11/03/1999) 1. Problem proposing in some database management systems or office automation and statistic software, generally has a function of drawing a three-dimensional view. When used, the data and viewing angle, proportional ruler such as the drawing are often required in the given form. This is only available for small batch statistics to draw statistics 3D views. In many areas such as geological, landform, meteorology, hydrology, transportation, forestry, usually have a space distribution characteristics, and this spatial distribution data is generally very large, and often meets when using the above three-dimensional view software drawing The problem that does not receive the number of dices, and it is easy to make mistakes and consume many people according to the table. The three-dimensional view of the drawing and the organization of the corresponding drawing data are not a very difficult thing, and this goal can be achieved using a small number of program code. This article will introduce a simple way to draw a three-dimensional view in a C language. The key technique of this method is that: (1) Corrupted the drawing data with the FoxPro database management system and makes it can be a C language .H file; (2) In the three-dimensional view, it is necessary to shake with the "polygon method" The blanking of the line segment. 2. Original data for drawing data from the foxpro (or foxbase) database management system. The data of a certain image can be placed in a one-dimensional array and included in one .h file. This can call these data in any location of the program as long as the three-dimensional view program is included in C . For example, there is a data string: 3, 8, 10, 11, 27, 6, ..., the placement placement is A, the data file is named DATA.H, in Data.h, the data string is stored in: A = {3, 8, 10, 11, 27, 6,::}; these data can be copied by FoxPro. Dbf file. Of course, there is a simple processing before copying. Set in the .dbf file, the field where the data is waiting to be drawn is DT1, and a field DH (comma) can be added and the content of the field is all "," and then copy it to the data.h file in the following command. Medium: Copy to Data.h Field DT1, DH Dele with Blank Subsequently opens the Data.h file, add "A = {" in the data, add "};" in the data end. 3. Painting three-dimensional view programming basic idea to paint three-dimensional view of the three-dimensional view in "blanking", which should be blocked when it is observed at three-dimensional observation. The blanking method introduced in the "computer graphics" is more "calculated", which is calculated from the current data point line to which of the drawn lines should be hidden, and these lines are cleared. The author designed a simple and nobbed method (here, it is called "polygonal method"), not only the program code is simple, and this principle of midden is also very simple. The basic idea and arithmetic steps are now introduced as follows: 3.1 First-row data Paining X direction network cable. Connect the first row of data points in the line function; 3.2 draw the Y direction network cable. The second row is connected to the data point corresponding to the first row in the Y direction; 3.3 is eliminated in "polygonal method". According to the data of the second row, a polygon is painted in the background color, which may be erased by the line shaded by the second row of data points (ie, the line should be blanked); 3.4 Row Data Painting X Directional network cable. Connect the second row of data points in the line function; 3.5 Repeat steps 3.2 ~ 3.4 until the drawings are drawn.

4. Painted three-dimensional view source program (for Windows) Draw3d.cpp #include #include "Data.h" Int Pascal Winmain (HWND, Word, Word, long); Long Far Pascal WINDOWPROC (HWND, Word, Word, long); INT MV [15625]; // mv [] For the plot data array, existing Handle Hinst; int Pascal Winmain (Handle Hinstance, Handle Hprevinstance, LPSTR LPSZCMDLINE, INT NCMDSHOW) {... // Create a window code block} long far pascal windowproc (hwnd hwnd, word message, word wparam, long lparam) {HDC HDC; PaintStruct ps; hbrush holdbrush; int i = 0, j = 0; int yy [maxpts]; / / Maxpts define Static Point PointTable [MaxPts 2] in Data.H; Switch (Message) {// Define Brush or Paint Brush Static Logpen LPBLACK = {PS_SOLID, 1, 1, RGB (0 , 0, 0)}; static logpen lpgreen = {ps_solid, 1,1, rgb (0,255,0)}; static logpen lpwhite = {PS_SOLID, 1, 1, RGB (255, 255, 255)}; hbrush hblackbrush; hbrush hbrushbrush; HPEN Hgreenpen; HDC HDC; PaintStruct PTSTR; LOADSTRING (HinST, IDS_CAPTION, SZCAPTION, 35); RETURN 0; Case WM_Paint: HDC = BeginPaint hWnd, & PtStr); SetMapMode (hDC, MM_TEXT); hBlackPen = CreatePenIndirect (& lpBlack); hGreenPen = CreatePenIndirect (& lpGreen); hWhitePen = CreatePenIndirect (& lpWhite); hBlackBrush = GetStockObject (BLACK_BRUSH); hWhiteBrush = GetStockObject (WHITE_BRUSH); hOldBrush = SelectObject (HDC, getStockObject (null_brush)); {yy [j] = move j * scale1; // Move For the drawing start point Y coordinate, define for for (i = 0; i {PointTable [i] in Data.H; X = i * scale2 j * scale4; // forming a polygon vertex array PointTable [i] .y = yy [j] - (PointTable [i] .x-pointTable [

0] .x) * Angle- (MV [J * MaxPTS I] * scale3); // Scale2 and Scale4 are the zoom factor IF (J> 0) // scale3 in the X and Y directions, respectively, for the drawing data (Z direction The zoom factor {// angle is the perspective, all defines SelectObject (HDC, HGreenpen) in Data.H; MoveTo (HDC, MX [I], My [I]); LINETO (HDC, PointTable [i] .x PointTable [i] .y; // Pain Y direction network cable}} PointTable [MaxPTS] .x = PointTable [MaxPTS-1] .x; pointtable [maxpts] .y = pointtable [maxpts-1] .y 20 PointTable [MAXPTS 1] .x = pointtable [0] .x; pointtable [maxpts 1] .y = pointtable [0] .y 20; if (j == (MaxPTS-1)) {SelectObject (HDC , hWhitePen); SelectObject (hDC, hWhiteBrush); Polygon (hDC, PointTable, MAXPTS); // blanking} else {SelectObject (hDC, hBlackPen); SelectObject (hDC, hBlackBrush); Polygon (hDC, PointTable, MAXPTS); // 消}} for (i = 0; i {mx [i] = pointtable [i] .x; // save front point data in MX [i] my [i], my [i] = pointtable [ I] .y; // Have the Y direction network cable} for (i = 0; i <(maxpts-1); i ) {Selectobject (HDC, hgreenpen); Moveto (HDC, PointTable [i] .x, pointtable [ I] .y); lineto (HDC, PointTable [i 1] .x, PointTable [i 1] .y); // Pain X-Direction Network}} SelectObject (HDC, HOL DBRUSH); EndPaint (hWnd, & PTSTR); Return 0; Case WM_DESTROY: OSTQUITMESSAGE: ostquitmessage (0); return 0; default: Break;} Return DefWindowProc (HWND, Message, WParam, LParam);} 5. Conclusion Data and Zoom, Parameters such as perspectives are stored in the data.h file, or in this file, so when the drawing parameters are changed, as long as the Data.h file is modified or re-created.

转载请注明原文地址:https://www.9cbs.com/read-30922.html

New Post(0)