资源简介
计算机图形学的扫描线填充算法 结合了与win32写的橡皮筋程序,希望对大家有帮助
代码片段和文件信息
// DEMO3_13.CPP - WM_MOUSEMOVE demo
// INCLUDES ///////////////////////////////////////////////
#define WIN32_LEAN_AND_MEAN // just say no to MFC
#include // include all the windows headers
#include // include useful macros
#include // very important and include WINMM.LIB too!
#include
#include
#include
// DEFINES ////////////////////////////////////////////////
// defines for windows
#define WINDOW_CLASS_NAME “WINCLASS1“
// GLOBALS ////////////////////////////////////////////////
HWND main_window_handle = NULL; // globally track main window
HINSTANCE hinstance_app = NULL; // globally track hinstance
int tag=NULL;
int x_move_app=NULL;
int y_move_app=NULL;
int x_click_app=NULL;
int y_click_app=NULL;
int x_move_temp=NULL;
int y_move_temp=NULL;
int x_end_app=NULL;
int y_end_app=NULL;
//int i=0;
//POINT record[100];
//-------------------------------------------------------
struct Edge
{
float ymax;
float x;
float ymin;
float reciSlope;
Edge* next;
};
typedef Edge* PEdge;
struct Point
{
float x;
float y;
};
Point point[100];
int pnum=0;//存储点的个数
float yminymax;//最大y,最小y
PEdge *ET;//边表
Edge *AEL=NULL;
//-------------------------------------------------------
/*void getPoint()//获取多边形各个顶点(边不能交叉)
{
point[0].x=100;
point[0].y=100;
point[1].x=300;
point[1].y=200;
point[2].x=200;
point[2].y=300;
point[3].x=300;
point[3].y=400;
point[4].x=100;
point[4].y=500;
}*/
void getMiny(float &ymin)//获得多边形的最小Y值
{
ymin=point[0].y;
for(int i=1;i {
if(point[i].y ymin=point[i].y;
}
}
void getMaxy(float &ymax)//获得多边形的最大Y值
{
ymax=point[0].y;
for(int i=1;i {
if(point[i].y>ymax)
ymax=point[i].y;
}
}
void getEdge(Point &pbeginPoint &pendint i)//获取第i个顶点和其后一个顶点组成的边
{
if(point[i].y {
pbegin.y=point[i].y;
pbegin.x=point[i].x;
pend.y=point[(i+1)%pnum].y;
pend.x=point[(i+1)%pnum].x;
if(point[(i+2)%pnum].y>point[(i+1)%pnum].y)
pend.y--;
}
else if(point[i].y>point[(i+1)%pnum].y)
{
pbegin.y=point[(i+1)%pnum].y;
pbegin.x=point[(i+1)%pnum].x;
pend.y=point[i].y;
pend.x=point[i].x;
if(point[(i-1+pnum)%pnum].y>point[i].y)//(i-1+pnum)%pnum
pend.y--;
}
else
{
pbegin.y=point[i].y;
pbegin.x=point[i].x;
pend.y=point[(i+1)%pnum].y;
pend.x=point[(i+1)%pnum].x;
}
}
void createET(PEdge* &ET)//构建边表
{
for(int i=0;i ET[i]=NULL;
Point pbegin;
Point pend;
for(int v=0;v {
getEdge(pbeginpendv);
if(pbegin.y!=pend.y)
{
Edge *t=new Edge;
t->ymax=pend.y;
t->reciSlope=(pend.x-pbegin.x)/(pend.y-pbegin.y);
t->x=pbegin.x;
t->ymin=pbegin.y;
t->next=NULL;
if(ET[int(pbegin.y-ymin)]==NULL)
ET[int(pbegin.y-ymin)]=t;
else
{
Edge *p = ET[int(pbegin.y-ymin)];
Edge *q;
w
- 上一篇:Ogre for mfc
- 下一篇:mini2440开发板上的录音程序
评论
共有 条评论