谁能具体解释下下面代码的具体功能哇,头疼~
两个重要函数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);
}