MFC下图形任意角度旋转. |
您所在的位置:网站首页 › xform组合排名 › MFC下图形任意角度旋转. |
图形的旋转公式: x1 = (x - xcenter) * cosθ - (y - ycenter) * sinθ + xcenter; y1 = (x - xcenter) * sinθ + (y- ycenter) * cosθ + ycenter;
x, y:为原先点的坐标位置。 x1, y1旋转后点的坐标位置。 Xcenter, ycenter:为所绕的中心点的坐标
通过这个公式,可以利用SetWorldTransform()旋转图形
只有在图形模式被设置为GM_ADVANCED模式下该函数才能生效 int nGraphicsMode = SetGraphicsMode(hDc, GM_ADVANCED); 设置图形模式 XFORM xform; // 保存旋转数据的结构体
函数按照下面的公式进行计算的:(MSDN中提供的) x' = x * eM11 + y * eM21 + eDx, y' = x * eM12 + y * eM22 + eDy,
因此结合一下旋转公式可以得出下面的赋值:
double fangle = (double)m_iAngle / 180. * 3.1415926; // 计算弧度 xform.eM11 = (float)cos(fangle); xform.eM12 = (float)sin(fangle); xform.eM21 = (float)-sin(fangle); xform.eM22 = (float)cos(fangle); xform.eDx = (float)(centerPt.x - cos(fangle)*centerPt.x + sin(fangle)*centerPt.y); xform.eDy = (float)(centerPt.y - cos(fangle)*centerPt.y - sin(fangle)*centerPt.x); SetWorldTransform(hDc, &xform);
。。。绘图操作
// 恢复原先的模式 xform.eM11 = (float)1.0; xform.eM12 = (float)0; xform.eM21 = (float)0; xform.eM22 = (float)1.0; xform.eDx = (float)0; xform.eDy = (float)0;
SetWorldTransform(hDc, &xform); SetGraphicsMode(hDc, nGraphicsMode); // 恢复图形模式 |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |