Bresenham算法画直线个别区域不能显示问题

gaowei_IT 2012-04-27 09:56:04
计算机图形实验 Bresenham算法画直线自己编的代码运行后部分区域不能显示(第一象限0到45°,第三象限225到270°)调试好久不能解决 本人新手 求大神指导
C/C++ code

void CGaowei_drawlineView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
c1=point;
HCURSOR hCur = LoadCursor(NULL,IDC_CROSS);
::SetCursor(hCur);
flag=1;


CView::OnLButtonDown(nFlags, point);
}

void CGaowei_drawlineView::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
HCURSOR hCur = LoadCursor( NULL , IDC_ARROW) ;
::SetCursor(hCur);
flag=0;
c2=point;
// CDC *pDC=GetDC(); /* CWnd中的成员函数 */
//pDC->MoveTo(c1);
//pDC->LineTo(c2);
drawing(c1,c2);




CView::OnLButtonUp(nFlags, point);
}

void CGaowei_drawlineView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default

if(flag==1){
HCURSOR hCur = LoadCursor( NULL , IDC_CROSS ) ;
::SetCursor(hCur);

// CDC *dc=GetDC();
//dc->SetROP2(R2_NOT);
//draw_line(c1,last);
//draw_line(c1,point);
//dc->MoveTo(c1);
//dc->LineTo(last);
//dc->MoveTo(c1);
//dc->LineTo(point);
}
last=point;
CView::OnMouseMove(nFlags, point);
}


void CGaowei_drawlineView::drawing(CPoint c1, CPoint c2)
{
bool flag=1;
if(c1.x>c2.x){fanzhuan_points(c1,c2);}
if(abs(c1.y-c2.y)>abs(c1.x-c2.x)){flag=0;fanzhuan_single(c1);fanzhuan_single(c2);}
int dx=c2.x-c1.x;
int dy=c2.y-c1.y;
int dx2=abs(dx)*2;
int dy2=abs(dy)*2;
int erro=-abs(dx);
int ix=c1.x;
int iy=c1.y;
int inc=1;
CDC *pDC=GetDC();
int c=RGB(255,0,0);
if(dy>0)inc=1;
if(dy<=0)inc=-1;
for(ix=c1.x;ix<c2.x;ix++)
{
if(flag==1)pDC->SetPixel(ix,iy,c);
if(flag==0)pDC->SetPixel(iy,ix,c);
erro=erro+dy2;
if(erro>0)
{
iy+=inc;
erro=erro-dx2;
}
}


}

void CGaowei_drawlineView::fanzhuan_points(CPoint &c1, CPoint& c2)
{
CPoint temp=c1;
c1=c2;
c2=temp;
}

void CGaowei_drawlineView::fanzhuan_single(CPoint &c1)
{
int temp=c1.x;
c1.x=c1.y;
c1.y=temp;

}
...全文
81 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
向立天 2013-03-04
  • 打赏
  • 举报
回复
您好 我是本版版主 此帖已多日无人关注 请您及时结帖 如您认为问题没有解决可按无满意结帖处理 另外本版设置了疑难问题汇总帖 并已在版面置顶 相关规定其帖子中有说明 您可以根据规定提交您帖子的链接 如您目前不想结帖只需回帖说明 我们会删除此结帖通知 见此回复三日内无回应 我们将强制结帖 相关规定详见界面界面版关于版主结帖工作的具体办法
gaowei_IT 2012-04-28
  • 打赏
  • 举报
回复
怎么个单步调试
  • 打赏
  • 举报
回复
单步调试 看看所在角度区间中的数值是否正确

15,976

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧