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

あなたが持っている行の1つで:

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 に答える