![[最新]掃描線算法代碼_第1頁](http://file2.renrendoc.com/fileroot_temp3/2021-3/29/88a0c6be-78af-4b21-8227-3f499faf479a/88a0c6be-78af-4b21-8227-3f499faf479a1.gif)
![[最新]掃描線算法代碼_第2頁](http://file2.renrendoc.com/fileroot_temp3/2021-3/29/88a0c6be-78af-4b21-8227-3f499faf479a/88a0c6be-78af-4b21-8227-3f499faf479a2.gif)
![[最新]掃描線算法代碼_第3頁](http://file2.renrendoc.com/fileroot_temp3/2021-3/29/88a0c6be-78af-4b21-8227-3f499faf479a/88a0c6be-78af-4b21-8227-3f499faf479a3.gif)
![[最新]掃描線算法代碼_第4頁](http://file2.renrendoc.com/fileroot_temp3/2021-3/29/88a0c6be-78af-4b21-8227-3f499faf479a/88a0c6be-78af-4b21-8227-3f499faf479a4.gif)
![[最新]掃描線算法代碼_第5頁](http://file2.renrendoc.com/fileroot_temp3/2021-3/29/88a0c6be-78af-4b21-8227-3f499faf479a/88a0c6be-78af-4b21-8227-3f499faf479a5.gif)
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、 最新 掃描線算法代碼#include#include#include stdlib.hvoid init (void)glClearColor (1.0, 1.0, 1.0, 0.0); /指定清空顏色 (背景色)為白色glMatrixMode (GL_PROJECTION); / 指定投影矩陣gluOrtho2D (0.0, 400.0, 0.0, 400.0); /指定二維坐標(biāo)系中被顯示的區(qū)域typedef struct tEdge int yUpper;float xIntersect, dxPerScan;struct tEdge * next; Edge;struct dcPt /
2、dcPt實(shí)際上是一個(gè)點(diǎn)的結(jié)構(gòu)體 int x;int y;void setPixel(GLint x, GLint y) glBegin(GL_POINTS);glVertex2i(x, y);glEnd();/* Inserts edge into list in order of increasing xIntersect field.*/ void insertEdge (Edge * list, Edge * edge) Edge * p, * q = list; p = q-next;while (p != NULL) if (edge-xIntersect xIntersect)p
3、= NULL;else q = p; p = p-next;edge-next = q-next; q-next = edge;/* For an index, return y-coordinate of next nonhorizontal line */ int yNext (int k, int cnt, dcPt * pts) int j;if (k+1) (cnt-1)j = 0;else j = k + 1;while (ptsk.y = ptsj.y)if (j+1) (cnt-1)j = 0;elsej+;return (ptsj.y);/* Store lower-y co
4、ordinate and inverse slope for each edge. Adjust and storeupper-y coordinate for edges that are the lower member of a monotically increasing ordecreasing pair of edges */void makeEdgeRec(dcPt lower, dcPt upper, int yComp, Edge * edge, Edge * edges) edge-dxPerScan =(float) (upper.x - lower.x) / (uppe
5、r.y - lower.y); edge-xIntersect = lower.x;if (upper.y yUpper = upper.y - 1;elseedge-yUpper = upper.y;insertEdge (edgeslower.y, edge); void buildEdgeList (int cnt, dcPt * pts, Edge * edges) Edge *edge;dcPt v1, v2;int i, yPrev = ptscnt - 2.y;v1.x = ptscnt-1.x; v1.y = ptscnt-1.y; for (i=0; icnt; i+) v2
6、 = ptsi;if (v1.y != v2.y) /* nonhorizontal line */ edge=(Edge *) malloc (sizeof (Edge);if (v1.y next;while (p) q = p-next; insertEdge (active, p);p = q;void fillScan (int scan, Edge * active) Edge * p1, * p2;int i;p1 = active-next;while (p1) p2 = p1-next;for (i=p1-xIntersect; ixIntersect; i+)setPixe
7、l (int) i, scan);p1 = p2-next;void deleteAfter (Edge * q) Edge * p = q-next;q-next = p-next;free (p);/* Delete completed edges. Update xIntersect field for others */ void updateActiveList (int scan, Edge * active) Edge * q = active, * p = active-next;while (p)if (scan = p-yUpper) p = p-next; deleteA
8、fter (q);else p-xIntersect = p-xIntersect + p-dxPerScan; q = p;p = p-next;void resortActiveList (Edge * active) Edge * q, * p = active-next;active-next = NULL;while (p) q = p-next;insertEdge (active, p);p = q;void scanFill (int cnt, dcPt * pts)Edge *edges400, * active;int i, scan;for (i=0; inext = N
9、ULL;buildEdgeList (cnt, pts, edges);active = (Edge *) malloc (sizeof (Edge); active-next = NULL;for (scan=0; scannext) fillScan (scan, active); updateActiveList (scan, active);resortActiveList (active);/* Free edge records that have been malloced . */ void myDisplay (void)glClear (GL_COLOR_BUFFER_BI
10、T); / 清空顯示窗口 glColor3f (1.0, 0.0, 0.0); / 指定前景色 (當(dāng)前繪制顏色 ) 為藍(lán)色dcPt pts = 250,50,550,150,550,400,250,250,100,350,100,100,120,30; glBegin(GL_LINES);glVertex2i(180,15); /Specify line-segment geometry.glVertex2i(10,145);glEnd();scanFill (7,pts);glFlush ( ); /使繪制立即反映到屏幕上 void main(int argc, char *argv) glutInit(&argc, argv); glutInitDisplayMode(GLUT_R
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 中小企業(yè)聘用人員勞動(dòng)合同書
- 購銷合同紙箱購銷合同
- 股份制企業(yè)合同樣本集
- 汽車修理廠場(chǎng)地租賃合同
- 健身器材租賃合同
- Unit 4 Sharing Using Language 教學(xué)設(shè)計(jì)-2023-2024學(xué)年高二英語人教版(2019)選擇性必修第四冊(cè)
- 河南司法警官職業(yè)學(xué)院《生活中的管理學(xué)》2023-2024學(xué)年第二學(xué)期期末試卷
- 浙江旅游職業(yè)學(xué)院《藥事管理法規(guī)》2023-2024學(xué)年第二學(xué)期期末試卷
- 湖南城市學(xué)院《作物生物信息學(xué)及應(yīng)用》2023-2024學(xué)年第二學(xué)期期末試卷
- 上海中僑職業(yè)技術(shù)大學(xué)《獸醫(yī)流行病學(xué)》2023-2024學(xué)年第二學(xué)期期末試卷
- 新蘇教版六年級(jí)下冊(cè)《科學(xué)》全一冊(cè)全部課件(共16課)
- 幼兒園食品安全教育培訓(xùn)ppt課件模板
- 《離騷》PPT課堂大賽一等獎(jiǎng)
- 潔凈廠房監(jiān)理實(shí)施細(xì)則
- 初三九年級(jí)下冊(cè)部編人教版歷史考試必背資料(2020最新版)
- 觀賞樹木的園林特性課件
- XX化工有限責(zé)任公司維保方案
- 冷作工工藝與技能訓(xùn)練(第三版)教學(xué)課件匯總整本書電子教案全套教學(xué)教程完整版電子教案(最新)
- 部編版六年級(jí)下冊(cè)語文課堂作業(yè)本答案
- 圖解2022年新制訂全面推進(jìn)“大思政課”建設(shè)的工作方案學(xué)習(xí)解讀《全面推進(jìn)“大思政課”建設(shè)的工作方案》課件
- 家譜樹形圖模板
評(píng)論
0/150
提交評(píng)論