Plotting three-dimensional graphics in two-dimensional axes
Code section
CRect rect;
GetClientRect (rect);
Pdc->setmapmode (Mm_anisotropic);
Pdc->setwindowext (rect. Width (), Rect. Height ());
Pdc->setviewportext (rect. Width (),-rect. Height ());
Pdc->setviewportorg (rect. Width ()/2, Rect. Height ()/2);
CRect rect1 (CPoint (0, 0), CPoint (100, 100)); CPoint P[4];
P[0] = CPoint (60, 80);
P[1] = CPoint (60, 180);
P[2] = CPoint (160, 180);
P[3] = CPoint (160, 80);
CBrush Newbrush, *poldbrush;
Poldbrush = (CBrush *) Pdc->selectstockobject (Null_brush);
pdc->rectangle (&RECT1);
pdc->moveto (0, 100);
pdc->lineto (p[1]);
pdc->moveto (100, 100);
pdc->lineto (p[2]);
pdc->moveto (100, 0);
pdc->lineto (p[3]);
pdc->moveto (p[1]);
pdc->lineto (p[2]);
pdc->lineto (p[3]);
cpen Newpen, *poldpen;
newpen.createpen (Ps_dash, 1, RGB (0, 0, 0));
poldpen = Pdc->selectobject (&newpen);
pdc->moveto (0, 0);
pdc->lineto (p[0]);
pdc->lineto (p[1]);
pdc->lineto (p[0]);
pdc->lineto (p[3]);
pdc->selectobject (Poldpen);
// pdc->selectobject (Poldbrush);
// crect rect1 (CPoint (0, 0), CPoint (200, 200));
// pdc->rectangle (&RECT1);
// pdc->roundrect (Rect1, CPoint (200, 200));
//todo:add Draw code for native the data here
// crect rect1 (CPoint ( -25, -25), CPoint (+));
//&n Bsp CPoint P[4];
// p[0] = (75, 5); p[1] = (at (); p[2] = ((); p[3] = (5);
// pdc->rectangle (rect1);
There are some explanations in the code
1.//CBrush Newbrush, *poldbrush;
Poldbrush = (CBrush *) Pdc->selectstockobject (Null_brush);
This part can be, not (in this code), because the square is the first to draw, then it is at the bottom, even if it is not transparent, the back of the drawing line is above it, is visible
And then there's this piece of code
CPoint P[4];
P[0] = (15, 5); P[1] = (15, 55); P[2] = (75, 55); P[3] = (75, 5);
This either compiles, or links are not wrong, but it is wrong, into the debug mode can see some cases, these points of y = 0, and the x value is the coordinate point we give the Y value, because forget CPoint, although I want to assign a coordinate to CPoint array element, But forget to add cpoint in front of the coordinates, so the purpose is not attainable
2. Run the code, you can get a cube-like shape, but through the code can be seen, this actually does not count as a cube, because it has only one face and 8 lines, but look like cube
The following is the key, the figure is obtained, the "two-dimensional mapping of three-dimension graphics" is feasible, but by looking at the code to find such a cumbersome, constantly "moveto", "LineTo", code, complex error prone, and very messy unclear; so this is not possible, only as a description of the feasibility
In fact, I am writing code is also thought: a cube intuitive idea should be 6 faces, just 6 lines of code can get a cube, and relative to the above incomplete cube, so that the resulting is a cube with 6 faces, but in writing to pay attention to the inside, do not see the first painting, Otherwise, you might have painted a cube but you can't see it in the window.
Added an error: compile-time no problem, link times wrong
Link:fatal Error Lnk1168:cannot open Debug/down1.exe for writing
This is because the program ran once, and its running window is not closed, so that when you compile the link again, and if it is a direct link, it will not error
Draw three-dimensional graphics in a two-dimensional axis