16,472
社区成员
发帖
与我相关
我的任务
分享
VOID Example_Rotate(HDC hdc)
{
Graphics graphics(hdc);
Pen pen(Color(255, 0, 0, 255));
Matrix matrix;
matrix.Translate(40.0f, 0.0f); // first a translation
matrix.Rotate(30.0f, MatrixOrderAppend); // then a rotation
graphics.SetTransform(&matrix);
graphics.DrawEllipse(&pen, 0, 0, 100, 50);
}
msdn example code
void RotatePoint(pointx& pt,const pointx& ptCenter,float angle,BOOL bClockDir)
{
float _x = pt.x;
float _y = pt.y;
if(!bClockDir)
angle = 360 - angle;
float sin_t = sin(angle);
float cos_t = cos(angle);
pt.x = (_x - ptCenter.x) * cos_t + (_y - ptCenter.y) * sin_t + ptCenter.x;
pt.y = (_y - ptCenter.y) * cos_t - (_x - ptCenter.x) * sin_t + ptCenter.y;
}
CRect RotateRect(CRect& rc,const pointx& ptCenter,float angle,BOOL bClockDir)
{
RotatePoint(rc.TopLeft,ptCenter,angle,bClockDir);
RotatePoint(rc.BottomRight,ptCenter,angle,bClockDir);
return rc;
}