资源简介
计算机图形学的试验源代码,使用的是改进后的扫描线填充算法
代码片段和文件信息
#include “ggltools.h“
int gltRound(double x)
{
return x > 0 ? (int)(x+0.5) : (int)(x-0.5);
}
int gltTrunc(double x)
{
return (int)x;
}
void gltRasterText(double x double y const char *text void *font)
{
if(text == NULL) return ;
glRasterPos2d(x y);
for(int i=0; text[i] != ‘\0‘; i++)
{
glutBitmapCharacter(font text[i]);
}
}
void gltLine2i(int x0 int y0 int x1 int y1)
{
glBegin(GL_LINES);
glVertex2i(x0 y0);
glVertex2i(x1 y1);
glEnd();
}
void gltRect2i(int x0 int y0 int x1 int y1)
{
glBegin(GL_LINES);
glVertex2i(x0 y0);
glVertex2i(x1 y0);
glVertex2i(x1 y0);
glVertex2i(x1 y1);
glVertex2i(x1 y1);
glVertex2i(x0 y1);
glVertex2i(x0 y1);
glVertex2i(x0 y0);
glEnd();
}
void gltLine2d(double x0 double y0 double x1 double y1)
{
glBegin(GL_LINES);
glVertex2d(x0 y0);
glVertex2d(x1 y1);
glEnd();
}
void gltRect2d(double x0 double y0 double x1 double y1)
{
glBegin(GL_LINES);
glVertex2d(x0 y0);
glVertex2d(x1 y0);
glVertex2d(x1 y0);
glVertex2d(x1 y1);
glVertex2d(x1 y1);
glVertex2d(x0 y1);
glVertex2d(x0 y1);
glVertex2d(x0 y0);
glEnd();
}
bool gltPtInPolygon(int x int y const GPoint2i *points int n)
{
int crossCount;
GPoint2i pt0 pt1 pt2;
crossCount = 0;
for(int i=0; i {
pt0 = points[i];
pt1 = points[(i+1)%n];
pt2 = points[(i+2)%n];
// 跳过水平边
if(pt0.y() == pt1.y()) continue ;
// 点在边的右边不可能有交点 跳过
if(x > pt0.x() && x > pt1.x())
{
continue ;
}
if((y - pt0.y()) * (pt1.y() - y) >= 0)
{
// 计算扫描线交点xm
double xm = pt0.x()+(y-pt0.y())*(pt1.x()-pt0.x())/(pt1.y()-pt0.y());
if(xm > x)
{
if(y < pt0.y()) crossCount++;
if(y < pt1.y()) crossCount++;
}
}
}
if(crossCount % 2 == 1) return true;
else return false;
}
struct EdgeItem // 边表项
{
int yMax;
double x invk;
EdgeItem *next;
EdgeItem()
{
yMax = 0;
x = 0;
invk = 0.0;
next = 0;
}
};
template
void swap(T &aT &b)
{
T t = a;
a = b;
b = t;
}
void gltFillPolygon(const GPoint2i *points int n)
{
int iminmaxidxy;
GPoint2i pt0pt1;
EdgeItem ** EdgeBucket;
EdgeItem *p*q*pEdge*aet;
min = max = points[0].y();
for (i = 1; i < n; i ++)
{
if (min > points[i].y()) min = points[i].y();
if (max < points[i].y()) max = points[i].y();
}
//建立空桶
EdgeBucket = new EdgeItem *[max-min+1]();
for (i = 0; i < max-min+1; i ++)
{
EdgeBucket[i] = new EdgeItem();
}
for (i = 0; i {
pt0 = points[i];
pt1 = points[(i+1)%n];
if (pt0.y() == pt1.y()) con
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 1324076 2010-10-16 22:05 graph\graph\fill-polygon\Debug\FillPoly.pch
文件 582656 2010-11-04 12:43 graph\graph\fill-polygon\Debug\FillPoly.pdb
文件 3931 2010-08-29 22:23 graph\graph\fill-polygon\Debug\gpoint2d.obj
文件 77032 2010-08-29 22:23 graph\graph\fill-polygon\Debug\gpoint2darray.obj
文件 3737 2010-09-14 22:50 graph\graph\fill-polygon\Debug\gpoint2i.obj
文件 77473 2010-09-14 22:50 graph\graph\fill-polygon\Debug\gpoint2iarray.obj
文件 32057 2010-09-28 22:00 graph\graph\fill-polygon\Debug\main.obj
文件 353280 2010-11-30 22:30 graph\graph\fill-polygon\Debug\vc60.idb
文件 126976 2010-11-04 12:43 graph\graph\fill-polygon\Debug\vc60.pdb
文件 4137 2010-09-14 21:12 graph\graph\fill-polygon\FillPoly.dsp
文件 541 2010-08-29 22:22 graph\graph\fill-polygon\FillPoly.dsw
文件 156672 2010-11-30 22:30 graph\graph\fill-polygon\FillPoly.ncb
文件 50688 2010-11-30 22:30 graph\graph\fill-polygon\FillPoly.opt
文件 1247 2010-11-04 12:43 graph\graph\fill-polygon\FillPoly.plg
文件 4457 2010-11-04 12:43 graph\graph\fill-polygon\ggltools.cpp
文件 630 2010-09-28 11:06 graph\graph\fill-polygon\ggltools.h
文件 329 2010-09-14 21:07 graph\graph\fill-polygon\gpoint2i.cpp
文件 487 2010-09-25 14:17 graph\graph\fill-polygon\gpoint2i.h
文件 1773 2010-09-14 22:12 graph\graph\fill-polygon\gpoint2iarray.cpp
文件 927 2010-09-14 22:12 graph\graph\fill-polygon\gpoint2iarray.h
文件 4236 2010-09-28 22:00 graph\graph\fill-polygon\main.cpp
文件 65536 2010-09-14 22:50 graph\graph\fill-polygon\Release\FillPoly.exe
文件 1332136 2010-09-14 22:37 graph\graph\fill-polygon\Release\FillPoly.pch
文件 6446 2010-09-14 22:50 graph\graph\fill-polygon\Release\ggltools.obj
文件 1244 2010-08-29 22:43 graph\graph\fill-polygon\Release\gpoint2d.obj
文件 23847 2010-08-29 22:43 graph\graph\fill-polygon\Release\gpoint2darray.obj
文件 1216 2010-09-14 21:09 graph\graph\fill-polygon\Release\gpoint2i.obj
文件 24063 2010-09-14 22:12 graph\graph\fill-polygon\Release\gpoint2iarray.obj
文件 8554 2010-09-14 22:18 graph\graph\fill-polygon\Release\main.obj
文件 50176 2010-09-14 22:50 graph\graph\fill-polygon\Release\vc60.idb
............此处省略19个文件信息
- 上一篇:16位定点FFT-DSP的FPGA实现
- 下一篇:立方体动态隐线算法
评论
共有 条评论