資源簡介
使用MFC繪制的反走樣直線源程序,直接運行即可看到效果。這是vs2010版程序。參考教材是孔令德編寫的《計算機圖形學實踐教程(Visual C++版)第2版》。

代碼片段和文件信息
//?ALine.cpp:?implementation?of?the?CALine?class.
//
//////////////////////////////////////////////////////////////////////
#include?“stdafx.h“
#include?“Test.h“
#include?“ALine.h“
#include?“math.h“
#define?Round(d)?int(floor(d+0.5))//四舍五入宏定義
#ifdef?_DEBUG
#undef?THIS_FILE
static?char?THIS_FILE[]=__FILE__;
#define?new?DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
//?Construction/Destruction
//////////////////////////////////////////////////////////////////////
CALine::CALine()
{?
}
CALine::~CALine()
{
}
void?CALine::MoveTo(CDC?*pDCCP2?p0)
{
P0=p0;
}
void?CALine::MoveTo(CDC?*pDCdouble?xdouble?y)//重載函數
{
MoveTo(pDCCP2(xyCRGB(0.00.00.0)));
}
void?CALine::MoveTo(CDC?*pDCdouble?xdouble?yCRGB?c)?
{
MoveTo(pDCCP2(xyc));
}
void?CALine::LineTo(CDC?*pDCCP2?p1)
{
P1=p1;
CP2?pt;
CRGB?c0c1;
if(fabs(P0.x-P1.x)==0)??????//繪制垂線
{
if(P0.y>P1.y)???????????//交換頂點使得起始點低于終點頂點
{
t=P0;P0=P1;P1=t;
}
for(p=P0;p.y {
pDC->SetPixelV(Round(p.x)Round(p.y)RGB(p.c.red*255p.c.green*255p.c.blue*255));
}
}
else
{
double?ke=0;
k=(P1.y-P0.y)/(P1.x-P0.x);
if(k>1.0)????????????//繪制k>1
{
if(P0.y>P1.y)
{
t=P0;P0=P1;P1=t;
} ??
for(p=P0;p.y {
c0=CRGB(eee);
c1=CRGB(1.0-e1.0-e1.0-e);
pDC->SetPixelV(Round(p.x)Round(p.y)RGB(c0.red*255c0.green*255c0.blue*255));
pDC->SetPixelV(Round(p.x+1)Round(p.y)RGB(c1.red*255c1.green*255c1.blue*255));
e=e+1/k;
???????????????????if(e>=1.0)
{
p.x++;
e--;
}
}
}
if(0.0<=k?&&?k<=1.0)?????//繪制0≤k≤1
{
if(P0.x>P1.x)
{
t=P0;P0=P1;P1=t;
} ??
for(p=P0;p.x {
c0=CRGB(eee);
c1=CRGB(1.0-e1.0-e1.0-e);
pDC->SetPixelV(Round(p.x)Round(p.y)RGB(c0.red*255c0.green*255c0.blue*255));
pDC->SetPixelV(Round(p.x)Round(p.y+1)RGB(c1.red*255c1.green*255c1.blue*255));
e=e+k;
??????????????????if(e>=1.0)
{
p.y++;
e--;
}
}
}
if(k>=-1.0?&&?k<0.0)?????//繪制-1≤k<0
{
if(P0.x>P1.x)
{
t=P0;P0=P1;P1=t;
} ?
for(p=P0;p.x {
c0=CRGB(eee);
c1=CRGB(1.0-e1.0-e1.0-e);
pDC->SetPixelV(Round(p.x)Round(p.y)RGB(c0.red*255c0.green*255c0.blue*255));
pDC->SetPixelV(Round(p.x)Round(p.y-1)RGB(c1.red*255c1.green*255c1.blue*255));
e=e-k;
???????????????????if(e>=1.0)
{
p.y--;
e--;
}
}
}
if(k<-1.0)???????????//繪制k<-1?
{
if(P0.y {
t=P0;P0=P1;P1=t;
}?
for(p=P0;p.y>P1.y;p.y--)
{
c0=CRGB(eee);
c1=CRGB(1.0-e1.0-e1.0-e);
pDC->SetPixelV(Round(p.x)Round(p.y)RGB(c0.red*255c0.green*255c0.blue*255));
pDC->SetPixelV(Round(p.x+1)Round(p.y)RGB(c1.red*255c1.green*255c1.blue*255));
e=e-1/k;
????????????????if(e>=1.0)
{
p.x++;
e--;
}
}
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????3288??2014-11-15?11:28??案例5-直線反走樣Wu算法\Test\ALine.cpp
?????文件????????781??2014-11-19?08:13??案例5-直線反走樣Wu算法\Test\ALine.h
?????文件???????1769??2014-11-22?13:38??案例5-直線反走樣Wu算法\Test\MainFrm.cpp
?????文件????????669??2014-11-22?13:38??案例5-直線反走樣Wu算法\Test\MainFrm.h
?????文件????????669??2010-12-06?10:07??案例5-直線反走樣Wu算法\Test\P2.cpp
?????文件????????571??2010-02-11?21:05??案例5-直線反走樣Wu算法\Test\P2.h
?????文件???????3605??2014-11-22?13:38??案例5-直線反走樣Wu算法\Test\ReadMe.txt
?????文件??????68576??2014-11-22?13:46??案例5-直線反走樣Wu算法\Test\res\about.bmp
?????文件??????10134??2006-11-22?11:29??案例5-直線反走樣Wu算法\Test\res\app.ico
?????文件????????766??2014-11-22?13:46??案例5-直線反走樣Wu算法\Test\res\draw.ico
?????文件???????4710??2014-11-22?13:46??案例5-直線反走樣Wu算法\Test\res\exit.ico
?????文件???????3638??2014-11-22?13:46??案例5-直線反走樣Wu算法\Test\res\Help.ico
?????文件???????1078??2006-11-22?11:32??案例5-直線反走樣Wu算法\Test\res\Test.ico
?????文件????????664??2014-11-22?13:38??案例5-直線反走樣Wu算法\Test\res\Test.rc2
?????文件???????4710??2009-08-31?02:31??案例5-直線反走樣Wu算法\Test\res\TestDoc.ico
?????文件???????1654??2014-11-22?13:46??案例5-直線反走樣Wu算法\Test\res\Toolbar.bmp
?????文件???????2270??2014-11-22?13:47??案例5-直線反走樣Wu算法\Test\resource.h
?????文件???????2412??2011-09-23?23:55??案例5-直線反走樣Wu算法\Test\RGB.cpp
?????文件???????1098??2004-02-20?21:51??案例5-直線反走樣Wu算法\Test\RGB.h
?????文件????????137??2014-11-22?13:38??案例5-直線反走樣Wu算法\Test\stdafx.cpp
?????文件???????1632??2014-11-22?13:38??案例5-直線反走樣Wu算法\Test\stdafx.h
?????文件????????234??2014-11-22?13:38??案例5-直線反走樣Wu算法\Test\targetver.h
?????文件?????113248??2014-11-22?13:57??案例5-直線反走樣Wu算法\Test\Test.aps
?????文件???????4299??2014-11-22?14:10??案例5-直線反走樣Wu算法\Test\Test.cpp
?????文件????????486??2014-11-22?13:38??案例5-直線反走樣Wu算法\Test\Test.h
?????文件??????20364??2014-11-22?13:52??案例5-直線反走樣Wu算法\Test\Test.rc
?????文件???????6501??2014-11-22?14:11??案例5-直線反走樣Wu算法\Test\Test.vcxproj
?????文件???????3364??2014-11-22?14:11??案例5-直線反走樣Wu算法\Test\Test.vcxproj.filters
?????文件????????143??2014-11-22?13:38??案例5-直線反走樣Wu算法\Test\Test.vcxproj.user
?????文件???????2464??2014-11-22?13:38??案例5-直線反走樣Wu算法\Test\TestDoc.cpp
............此處省略11個文件信息
- 上一篇:變壓器故障診斷 國標改良三比值法
- 下一篇:行李寄存管理軟件綠色版.
評論
共有 條評論