| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 372 人关注过本帖
标题:谁能具体解释下下面代码的具体功能哇,头疼~
只看楼主 加入收藏
whmjisi
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2010-3-26
结帖率:100%
收藏
 问题点数:0 回复次数:0 
谁能具体解释下下面代码的具体功能哇,头疼~
两个重要函数ON_PARA_START()和ON_DRAW()的具体实现
//开始跟踪的执行过程,生成结果链表,刷新时可以不用重复跟踪计算。
void CSoundView::OnParaStart()
{
    // TODO: Add your command handler code here

//    delete old pathlist;   
    deleteoldpath(&plist);

//    lighttrace();
    int i;
    Clight *light;
    for (i=0;i<number;i++)
    {
        light=new Clight(sourcepoint,2*i*PI/number);
        while (!light->isover(depth))
        {
            struct BSPspacelist *temp=BSPlist;
            CBSPspace *nowspace;
            if (temp!=NULL)
            {
                nowspace=&temp->BSPspace;
                while (!nowspace->islightin(light) && temp!=NULL)
                {
                    temp=temp->next;
                    if (temp!=NULL) nowspace=&temp->BSPspace;
                }
                if (temp!=NULL)
                {
                    if (nowspace->ispointin(destpoint) && light->gothrough(destpoint))
                    {
                        light->ended(destpoint);
                        light->savepath(&plist);
                        break;
                    }
                    //caculate the reflect light or out light;
                    nowspace->reflect(light);
                }
                else break;
            }
        }
        delete light;
    }

    Invalidate();
}

//根据BSP链表和产生的路径链表画出空间结构和跟踪结果。
void CSoundView::OnDraw(CDC* pDC)
{
    CSoundDoc* pDoc = GetDocument();
    ASSERT_VALID(pDoc);
    // TODO: add draw code for native data here

//    drawwall();
    struct BSPspacelist *temp=BSPlist;
    while (temp!=NULL)
    {
        pDC->MoveTo(temp->BSPspace.x1,temp->BSPspace.y1);
        long i;
        for (i=0;i<=temp->BSPspace.y2-temp->BSPspace.y1;i++)
        {
            if (temp->BSPspace.wx1[i]) pDC->SetPixel(temp->BSPspace.x1,temp->BSPspace.y1+i,WALLCOLOR);
            if (temp->BSPspace.wx2[i]) pDC->SetPixel(temp->BSPspace.x2,temp->BSPspace.y1+i,WALLCOLOR);
        }
        for (i=0;i<=temp->BSPspace.x2-temp->BSPspace.x1;i++)
        {
            if (temp->BSPspace.wy1[i]) pDC->SetPixel(temp->BSPspace.x1+i,temp->BSPspace.y1,WALLCOLOR);
            if (temp->BSPspace.wy2[i]) pDC->SetPixel(temp->BSPspace.x1+i,temp->BSPspace.y2,WALLCOLOR);
        }
        temp=temp->next;
    }

//    drawlight();
    struct pathlist *pathtemp=plist;
    while (pathtemp!=NULL)
    {
        COLORREF lightcolor;
        do
        {
            lightcolor=RGB(rand()%256,rand()%256,rand()%256);
        }while (lightcolor==RGB(0,0,0) || lightcolor==RGB(255,255,255));
        CPen newpen(PS_SOLID,1,lightcolor);
        CPen *oldpen=pDC->SelectObject(&newpen);
        pDC->MoveTo(sourcepoint);
        struct pointlist *plisttemp=pathtemp->plist->next;
        while (plisttemp!=NULL)
        {
            pDC->LineTo(plisttemp->point);
            plisttemp=plisttemp->next;
        }
//        pDC->LineTo(destpoint);
        pathtemp=pathtemp->next;
        pDC->SelectObject(oldpen);
    }

//    draw sourcepoint and destpoint;
//不画成一个点是因为显示时看不清楚。最后画点是为了不被跟踪路径覆盖。
    CBrush brush1(SOURCECOLOR);
    CBrush *oldbrush1=pDC->SelectObject(&brush1);
    pDC->Ellipse(sourcepoint.x-1,sourcepoint.y-1,sourcepoint.x+1,sourcepoint.y+1);
    pDC->SelectObject(&oldbrush1);

    CBrush brush2(DESTCOLOR);
    CBrush *oldbrush2=pDC->SelectObject(&brush2);
    pDC->Ellipse(destpoint.x-1,destpoint.y-1,destpoint.x+1,destpoint.y+1);
    pDC->SelectObject(&oldbrush2);
}
搜索更多相关主题的帖子: 代码 头疼 解释 
2010-05-09 11:26
快速回复:谁能具体解释下下面代码的具体功能哇,头疼~
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016805 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved