資源簡介
實驗四 編程實現Cohen-Sutherland線段裁剪算法或者Sutherland-Hodgman多邊形裁剪算法 對各種情況進行測試,驗證算法實現的完整性
代碼片段和文件信息
#include?
#include?
#include?
#include?
using?namespace?std;
struct?Point
{
????double?xy;
????int?code;
}?firstPolygon[4]p1[8]p2[8]p3[8]p4[8]polygon[4];
int?firstnum=4p1n=0p2n=0p3n=0p4n=0;
double?xminxmaxyminymax;
//編碼
int?encode(double?xdouble?y)
{
????//??0??0??0??0
????//?上?下?右?左
????int?code=0;
????if(x ????????code+=1;
????if(x>polygon[2].x)//xmax
????????code+=2;
????if(y ????????code+=4;
????if(y>polygon[2].y)//ymax
????????code+=8;
????return?code;
}
void?init()
{
????glClearColor(0000.0);//清除當前所有顏色
????glMatrixMode(GL_PROJECTION);//投影模型
????gluOrtho2D(05000500);//二維投影,參數越大,直線越小
????polygon[0].x=200polygon[0].y=200;//裁剪窗口
????polygon[1].x=300polygon[1].y=200;
????polygon[2].x=300polygon[2].y=300;
????polygon[3].x=200polygon[3].y=300;
????xmin=polygon[0].xymin=polygon[0].y;
????xmax=polygon[2].xymax=polygon[2].y;
????firstPoly
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件?????979283??2014-12-18?16:58??Sutherland_Hodgman\bin\Debug\Sutherland_Hodgman.exe
?????文件???????6783??2014-12-18?16:58??Sutherland_Hodgman\main.cpp
?????文件??????23059??2014-12-18?16:58??Sutherland_Hodgman\obj\Debug\main.o
?????文件???????1552??2014-12-18?15:40??Sutherland_Hodgman\Sutherland_Hodgman.cbp
?????文件???????5731??2014-12-18?16:32??Sutherland_Hodgman\Sutherland_Hodgman.depend
?????文件????????667??2014-12-18?16:59??Sutherland_Hodgman\Sutherland_Hodgman.layout
?????目錄??????????0??2014-12-20?12:50??Sutherland_Hodgman\bin\Debug
?????目錄??????????0??2014-12-20?12:50??Sutherland_Hodgman\obj\Debug
?????目錄??????????0??2014-12-20?12:50??Sutherland_Hodgman\bin
?????目錄??????????0??2014-12-20?12:50??Sutherland_Hodgman\obj
?????目錄??????????0??2014-12-20?12:50??Sutherland_Hodgman
-----------?---------??----------?-----??----
??????????????1017075????????????????????11
評論
共有 條評論