HTJY 2020-03-12 15:40 采纳率: 100%
浏览 263
已采纳

C++以鼠标为中点进行平面图形的缩放为什么缩放几次后图形变形了?

//每个点进行缩放
void CMyDraw::ZoomEx()
{
int _nTypeCount = m_vecUnit.size();
for (int _i = 0; _i < _nTypeCount; _i++)
{
int _nCount = m_vecUnit[_i].vecPoint.size();
for (int _j = 0; _j < _nCount; _j++)
{
Zoomeeexxx(m_vecUnit[_i].vecPoint[_j]);
}
}
}

//缩放
void CMyDraw::Zoomeeexxx(__ADTPt3Doub & ptDest_)
{
ptDest_.x -= m_ptPerZoomPos.x;
ptDest_.y -= m_ptPerZoomPos.y;

ptDest_.x = int(ptDest_.x*m_fScale);
ptDest_.y = int(ptDest_.y*m_fScale);

ptDest_.x += m_ptPerZoomPos.x;
ptDest_.y += m_ptPerZoomPos.y;

}

  • 写回答

1条回答 默认 最新

  • threenewbee 2020-03-12 16:05
    关注

    ptDest_.x = int(ptDest_.x*m_fScale);
    你要注意,这里转int是近似计算,比如123.4567,转换出来是123,就差一点点。
    你反复缩放,误差就会积累、放大。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?