-1
在我的多边形(方形)问题上出现问题,它在旋转时变形,尝试使用标准函数SetWorldTransform,但感到很失望。 旋转功能正常。可能的,主要问题在于每次旋转后的错误。WinAPI多边形变形旋转
int xCenter = 105;
int yCenter = 105;
POINT pnts[5];
square()
{
pnts[0].x = 70;
pnts[0].y = 70;
pnts[1].x = 140;
pnts[1].y = 70;
pnts[2].x = 140;
pnts[2].y = 140;
pnts[3].x = 70;
pnts[3].y = 140;
pnts[4].x = 70;
pnts[4].y = 70;
}
void Drawsquare(HWND hWin)
{
HDC hdc;
HBRUSH hBrush;
HPEN hPen;
LOGBRUSH lBrush;
hdc = GetDC(hWin);
lBrush.lbStyle = BS_HOLLOW;
hBrush = CreateBrushIndirect(&lBrush);
hPen = CreatePen(PS_SOLID, 1, RGB(0, 0, 0));
SelectObject(hdc, hBrush);
SelectObject(hdc, hPen);
Polygon(hdc, pnts, 5);
ReleaseDC(hWin, hdc);
}
void Rotate(HWND hWin)
{
HDC hdc;
RECT rect;
hdc = GetDC(hWin);
double pi = acos(-1);
double ang = 45 * pi/180;
for(int i = 0; i < 5; i++)
{
pnts[i].x = (pnts[i].x - xCenter)*cos(ang) - (pnts[i].y - yCenter)*sin(ang) + xCenter;
pnts[i].y = (pnts[i].x - xCenter)*sin(ang) + (pnts[i].y - yCenter)*cos(ang) + yCenter;
}
GetClientRect(hWin, &rect);
ClearScreen(hdc, rect);
Drawsquare(hWin);
ReleaseDC(hWin, hdc);
}
你有'x-yCenter'和'y -xCenter',是否正确? –
X和Y中心是一样的,所以问题不在于这一点,谢谢你的回复。 –
您的代码不完整;特别是它似乎缺少'main()'函数和至少一个'#include'。请[编辑]你的代码,这是你的问题[mcve],然后我们可以尝试重现并解决它。你还应该阅读[问]。 –