[最新]掃描線算法代碼_第1頁
[最新]掃描線算法代碼_第2頁
[最新]掃描線算法代碼_第3頁
[最新]掃描線算法代碼_第4頁
[最新]掃描線算法代碼_第5頁
已閱讀5頁,還剩2頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

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ì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論