資源簡介
2019年寫的代碼!很新!可用!大學計算機圖形學課程作業代碼,使用雙緩沖技術,實現平移、比例、旋轉、反射錯切變換。自用,代碼完整。打包下載,可直接運行。c/c++語言MFC實現。支持vs。
代碼片段和文件信息
#include?“stdafx.h“
#include?“Line.h“
#include?“RGB.h“
#define?ROUND(d)?int(floor(d+0.5))????//四舍五入
CLine::CLine()
{
}
CLine::~CLine()
{
}
//?移動到指定位置
void?CLine::MoveTo(CDC?*pDC?CP2?p0)
{
//?TODO:?在此處添加實現代碼.
P0?=?p0;
}
void?CLine::MoveTo(CDC?*pDC?double?x0?double?y0)???//重載函數
{
P0?=?CP2(x0?y0);
}
void?CLine::LineTo(CDC?*pDC?CP2?p1)
{
//?TODO:?在此處添加實現代碼.
P1?=?p1;
CP2?p?t;
CRGB?clr?=?CRGB(0.0?0.0?1.0);
//繪制垂線
if?(fabs(P0.x?-?P1.x)?1e-6)
{
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(clr.red?*?255?clr.green?*?255?clr.blue?*?255));
}
}
else
{
double?k?d;
k?=?(P1.y?-?P0.y)?/?(P1.x?-?P0.x);
//繪制k?>?1
if?(k?>?1.0)
{
if?(P0.y?>?P1.y)
{
t?=?P0;?P0?=?P1;?P1?=?t;
}
d?=?1?-?0.5*k;
for?(p?=?P0;?p.y? {
pDC->SetPixelV(ROUND(p.x)?ROUND(p.y)
RGB(clr.red?*?255?clr.green?*?255?clr.blue?*?255));
if?(d?>=?0)
{
p.x++;
d?+=?1?-?k;
}
else
d?+=?1;
}
}
//繪制0<=k<=1
if?(0.0?<=?k?&&?k?<=?1.0)
{
if?(P0.x?>?P1.x)
{
t?=?P0;?P0?=?P1;?P1?=?t;
}
d?=?0.5?-?k;
for?(p?=?P0;?p.x? {
pDC->SetPixelV(ROUND(p.x)?ROUND(p.y)
RGB(clr.red?*?255?clr.green?*?255?clr.blue?*?255));
if?(d?0)
{
p.y++;
d?+=?1?-?k;
}
else
d?-=?k;
}
}
//繪制-1<=k<0
if?(k?>=?-1.0?&&?k?0.0)
{
if?(P0.x?>?P1.x)
{
t?=?P0;?P0?=?P1;?P1?=?t;
}
d?=?-0.5?-?k;
for?(p?=?P0;?p.x? {
pDC->SetPixelV(ROUND(p.x)?ROUND(p.y)
RGB(clr.red?*?255?clr.green?*?255?clr.blue?*?255));
if?(d?>?0)
{
p.y--;
d?-=?1?+?k;
}
else
d?-=?k;
}
}
//繪制k<-1
if?(k?-1.0)
{
if?(P0.y? {
t?=?P0;?P0?=?P1;?P1?=?t;
}
d?=?-1?-?0.5*k;
for?(p?=?P0;?p.y?>?P1.y;?p.y--)
{
pDC->SetPixelV(ROUND(p.x)?ROUND(p.y)
RGB(clr.red?*?255?clr.green?*?255?clr.blue?*?255));
if?(d?0)
{
p.x++;
d?=?d?-?1?-?k;
}
else
d?-=?1;
}
}
}
P0?=?p1;
}
void?CLine::LineTo(CDC?*pDC?double?x1?double?y1)
{
LineTo(pDC?CP2(x1?y1));
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
????..A..H.?????38912??2019-11-08?16:40??Test4?-?副本\.vs\Test4\v15\.suo
?????文件???78364672??2019-11-08?16:40??Test4?-?副本\.vs\Test4\v15\Browse.VC.db
?????文件??121634816??2019-11-08?16:22??Test4?-?副本\.vs\Test4\v15\ipch\55490e51d6461155.ipch
?????文件??????23108??2019-11-08?15:41??Test4?-?副本\Debug\Line.obj
?????文件??????69049??2019-11-07?13:05??Test4?-?副本\Debug\MainFrm.obj
?????文件??????20439??2019-11-08?15:41??Test4?-?副本\Debug\P2.obj
?????文件??????23640??2019-10-31?11:11??Test4?-?副本\Debug\RGB.obj
?????文件????1007747??2019-10-31?11:11??Test4?-?副本\Debug\stdafx.obj
?????文件?????288256??2019-11-08?16:31??Test4?-?副本\Debug\Test4.exe
?????文件????3231328??2019-11-08?16:31??Test4?-?副本\Debug\Test4.ilk
?????文件?????????96??2019-11-08?16:31??Test4?-?副本\Debug\Test4.log
?????文件??????53870??2019-11-08?15:41??Test4?-?副本\Debug\Test4.obj
?????文件???56819712??2019-10-31?11:11??Test4?-?副本\Debug\Test4.pch
?????文件????3313664??2019-11-08?16:31??Test4?-?副本\Debug\Test4.pdb
?????文件??????99444??2019-11-07?13:12??Test4?-?副本\Debug\Test4.res
?????文件??????13026??2019-11-08?16:31??Test4?-?副本\Debug\Test4.tlog\CL.command.1.tlog
?????文件?????200320??2019-11-08?16:31??Test4?-?副本\Debug\Test4.tlog\CL.read.1.tlog
?????文件??????12662??2019-11-08?16:31??Test4?-?副本\Debug\Test4.tlog\CL.write.1.tlog
?????文件???????4072??2019-11-08?16:31??Test4?-?副本\Debug\Test4.tlog\li
?????文件??????12874??2019-11-08?16:31??Test4?-?副本\Debug\Test4.tlog\li
?????文件???????1968??2019-11-08?16:31??Test4?-?副本\Debug\Test4.tlog\li
?????文件????????638??2019-11-07?13:12??Test4?-?副本\Debug\Test4.tlog\rc.command.1.tlog
?????文件???????8988??2019-11-07?13:12??Test4?-?副本\Debug\Test4.tlog\rc.read.1.tlog
?????文件????????286??2019-11-07?13:12??Test4?-?副本\Debug\Test4.tlog\rc.write.1.tlog
?????文件????????215??2019-11-08?16:31??Test4?-?副本\Debug\Test4.tlog\Test4.lastbuildstate
?????文件??????94211??2019-11-07?13:05??Test4?-?副本\Debug\Test4Doc.obj
?????文件??????72932??2019-11-08?16:31??Test4?-?副本\Debug\Test4View.obj
?????文件??????25523??2019-11-08?15:41??Test4?-?副本\Debug\Transform.obj
?????文件??????26143??2019-10-30?17:36??Test4?-?副本\Debug\transform.obj.enc
?????文件????1444864??2019-11-08?16:31??Test4?-?副本\Debug\vc141.idb
............此處省略57個文件信息
評論
共有 條評論