0

我正在使用折线函数在 C++ 中绘制三角形。我在将三角形存储在结构中时遇到问题(以便在窗口失效时重新绘制它们)

#define MAX_OBJECTS 10000

typedef struct
{
unsigned int topCornerX;
unsigned int topCornerY;
unsigned int RightX;
unsigned int RightY;
unsigned int LeftX;
unsigned int LeftY;

}Triangles;

int mouse_down_x = 0;
int mouse_down_y = 0;



Triangles triangleList[MAX_OBJECTS];
Triangles temp_tri;
int current_tri_count = 0;
int t = 0;

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
POINT Pt[4];
POINT pT[4];

我正在使用这个来绘制临时三角形

Pt[0].x = temp_tri.topCornerX;  Pt[0].y = temp_tri.topCornerY;
Pt[1].x = temp_tri.LeftX; Pt[1].y = temp_tri.LeftY;
Pt[2].x = temp_tri.RightX; Pt[2].y = temp_tri.RightY;
Pt[3].x = temp_tri.topCornerX; Pt[3].y = temp_tri.topCornerY;

这个是重绘所有以前的三角形,但是它不起作用

pT[0].x = triangleList[t].topCornerX;
pT[0].y = triangleList[t].topCornerX;
pT[1].x = triangleList[t].LeftX;
pT[1].y = triangleList[t].LeftY;
pT[2].x = triangleList[t].RightX;
pT[2].y = triangleList[t].RightY;
pT[3].x = triangleList[t].topCornerX;
pT[3].y = triangleList[t].topCornerY;

case WM_PAINT:
    hdc = BeginPaint(hWnd, &ps);

Polyline(hdc, Pt, 4); // using this one to draw the temp triangle as the object is drawn by user

while (t < current_tri_count) // should be redrawing the old ones
    {
        Polyline(hdc,pT,4);
        t++;


    }


case WM_LBUTTONDOWN:

mouse_down_x = LOWORD(lParam);
        mouse_down_y = HIWORD(lParam);

        temp_tri.topCornerX = mouse_down_x;
        temp_tri.topCornerY = mouse_down_y;

        mouse_down = true;

break;

case WM_MOUSEMOVE:

if(mouse_down)
        {
            temp_tri.LeftX = LOWORD(lParam);
            temp_tri.LeftY = HIWORD(lParam);
            temp_tri.RightX = LOWORD(lParam) + 90;
            temp_tri.RightY = HIWORD(lParam) + 90;
            mouse_down = true;

        }
        InvalidateRect(hWnd, NULL, true);

break;

case WM_LBUTTONUP:

                          temp_tri.LeftX = LOWORD(lParam);
        temp_tri.LeftY = HIWORD(lParam);
        temp_tri.RightX = LOWORD(lParam) + 90;
        temp_tri.RightY = HIWORD(lParam) + 90;

        triangleList[current_tri_count] = temp_tri;

        current_tri_count ++;
        mouse_down = false;

break;
4

1 回答 1

0

在其中一行中,您有:

pT[0].x = triangleList[t].topCornerX;
pT[0].y = triangleList[t].topCornerX;

我认为应该是:

pT[0].x = triangleList[t].topCornerX;
pT[0].y = triangleList[t].topCornerY; // <- Y
于 2012-10-28T03:32:38.250 回答