资源简介
将绘制的折线连接成多边形,并选择种子填充法或扫描线填充法进行填充
鼠标交互生成矩形裁剪框,实现对绘制的折线的裁剪
鼠标交互生成矩形裁剪框,实现对绘制的折线的裁剪
代码片段和文件信息
#include
#include
#include
#include
#include
#include
#include
#define pointSize 1
class point4
{
public:
point4(){startx=0;starty=0;endx=0;endy=0;}
int startx;
int starty;
int endx;
int endy;
};
point4 array[20];
int line_number;
int startXstartYendXendY;
int mouse_button_state;//0:没有操作 1:第一个点刚按下 2:松开点
int mark;
void lineBresPlane(int xStartint yStartint xEndint yEnd)
{
int x y xx yy;
if( xStart>xEnd )
{
x = xEnd;
y = yEnd;
xx = xStart;
yy = yStart;
}
else
{
x = xStart;
y = yStart;
xx = xEnd;
yy = yEnd;
}
glBegin(GL_POINTS);
glVertex2i(x y);
glEnd();
while(x {
x ++;
glBegin(GL_POINTS);
glVertex2i(x y);
glEnd();
}
}
void lineBresApeak(int xStartint yStartint xEndint yEnd)
{
int x y xx yy;
if( yStart>yEnd )
{
y = yEnd;
x = xEnd;
yy = yStart;
xx = xStart;
}
else
{
y = yStart;
x = xStart;
yy = yEnd;
xx = xEnd;
}
glBegin(GL_POINTS);
glVertex2i(x y);
glEnd();
while(y {
y ++;
glBegin(GL_POINTS);
glVertex2i(x y);
glEnd();
}
}
void lineBresDiagonal(int xStartint yStartint xEndint yEnd)
{
int x y xx yy;
if( xStart>xEnd )
{
x = xEnd;
y = yEnd;
xx = xStart;
yy = yStart;
}
else
{
x = xStart;
y = yStart;
xx = xEnd;
yy = yEnd;
}
glBegin(GL_POINTS);
glVertex2i(x y);
glEnd();
bool flag = false;
if(yy>y) flag = true;
while(x {
x ++;
if(flag)
y ++;
else
y --;
glBegin(GL_POINTS);
glVertex2i(x y);
glEnd();
}
}
void lineBresXbig(int xStartint yStartint xEndint yEnd)
{
int dx = fabs(xEnd - xStart) dy = fabs(yEnd - yStart);
int p = 2*dy - dx;
int twoDy = 2*dy twoDyMinusDx = 2*(dy-dx);
int x y xx yy;
if( xStart>xEnd )
{
x = xEnd;
y = yEnd;
xx = xStart;
yy = yStart;
}
else
{
x = xStart;
y = yStart;
xx = xEnd;
yy = yEnd;
}
glBegin(GL_POINTS);
glVertex2i(x y);
glEnd();
bool flag = false;
if(yy>y) flag = true;
while(x {
x ++;
if(p<0)
p += twoDy;
else
{
if(flag)
y ++;
else
y --;
p += twoDyMinusDx;
}
glBegin(GL_POINTS);
glVertex2i(x y);
glEnd();
}
}
void lineBresYbig(int xStartint yStartint xEndint yEnd)
{
int dx = fabs(xEnd - xStart) dy = fabs(yEnd - yStart);
int p = 2*dx - dy;
int twoDx = 2*dx twoDxMinusDy = 2*(dx-dy);
int x y xx yy;
if( yStart>yEnd )
{
y = yEnd;
x = xEnd;
yy = yStart;
xx = xStart;
}
else
{
y = yStart;
x = xStart;
yy = yEnd;
xx = xEnd;
}
glBegin(GL_POINTS);
glVertex2i(x y);
glEnd();
bool flag = false;
if(xx>x) flag = true;
while(y {
y ++;
if(p<0)
p += twoDx;
else
{
if(flag)
x ++;
else
x --;
p += twoDxMinusDy;
}
glBegin(GL_P
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 6327 2009-12-14 19:25 Bresenham.cpp
----------- --------- ---------- ----- ----
6327 1
- 上一篇:农场开发项目
- 下一篇:jQuery ajax实现简单登录验证
评论
共有 条评论