// ConsoleApplication41.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include "iostream"
#include "vector"
#include "algorithm"
#include "GL/glut.h"
#define color_0 color(0,0,0)
#define color_1 color(0.25,0.9,0.8)
#define color_2 color(0.15,0.8,0.6)
#define color_3 color(1,0,0)
#define color_4 color(0,0,1)
#define color_5 color(1,1,0)
using namespace std;
const unsigned int maxn = 700;
int flag[maxn]; //用于标记边那些特定的 要y-1的点
int visit[maxn]; //用于在寻找 特定点 时 标记删除掉的点
int point_amount = 0; //顶点的个数(边的个数)
int Point[maxn][2];
int EDGE_PRO[maxn][2][2]; //没有处理的边
int minx_y = INT_MAX;
int setpoint_[maxn][maxn];
struct edge {
float y2;
float x1;
float m;
edge *next;
friend bool operator <(const edge&e1, const edge&e2) {
return e1.x1 < e2.x1;
}
}; //用vector 构建活化边表
edge *edge_table[maxn]; // edge_table
struct node {
int x, y;
node(int a, int b) {
x = a, y = b;
}
};
int ans = 0;
int time = 0;
int keytime = 0;
int time3 = 0;
float x1, y1_, x2, y2; //划线算法的 两个端点
float x3, y3, x4, y4, x5, y5, xmove0, ymove0, xmove1, ymove1;
float xr3, yr3;
float r1, c1, r2, c2;
int xpro, ypro;
int r;
float sf = 1;
int asn = 0;
bool determine = false;
bool check = true;
class color {
public:
float r, g, b;
color(float r_, float g_, float b_) {
r = r_, g = g_, b = b_;
}
color() {};
};
class screen
{
private:
color p[maxn][maxn];
int hight;
int width;
int length;
int xo, yo;
public:
screen(int a, int b, int c, int d, int e);
void initscreen();
void setpoint(int x, int y, color rgb);
void reviselength(int x); //修改方格的长度
int getlength();
void newxoyo(int x, int y); //修改方格左下角的x,y
int getxo();
int getyo();
int mapped_x(int x);
int mapped_y(int y);
void show();
void filling(int a, int b, int c);
};
screen::screen(int a, int b, int c, int d, int e) {
hight = a, width = b, length = c, xo = d, yo = e;
for (int i = 0; i < width; i++)
for (int j = 0; j < hight; j++) {
p[i][j] = color_0;
}
}
int screen::getlength() {
return length;
}
void screen::initscreen() {
memset(setpoint_, 0, sizeof setpoint_);
for (int i = 0; i < width; i++)
for (int j = 0; j < hight; j++) {
p[i][j] = color_0;
}
}
void screen::setpoint(int x, int y, color rgb) {
if (x < 0 || y < 0 || x >= 700 || y >= 700)
return;
p[x][y] = rgb;
}
void screen::reviselength(int x) {
length = length + x;
}
void screen::newxoyo(int x, int y) {
xo = x;
yo = y;
}
int screen::getxo() {
return xo;
}
int screen::getyo() {
return yo;
}
int screen::mapped_x(int x) {
return int(float(x - xo) / float(length));
}
int screen::mapped_y(int y) {
return int(float(700 - y - yo) / float(length));
}
void screen::show() {
glColor3f(0.5, 0.5, 0.5);
glBegin(GL_QUADS);
glVertex2i(xo, yo);
glVertex2i(xo, yo + hight*length);
glVertex2i(xo + width*length, yo + hight*length);
glVertex2i(xo + width*length, yo);
glEnd();
glFlush();
glColor3f(0.4
Opengl Scan-Line Fill of Convex Polygons (方格)
最新推荐文章于 2020-10-14 00:45:45 发布
这是一个使用OpenGL实现的扫描线填充算法,通过建立活化边表并使用排序来处理多边形的边界,从而填充图形。代码中包含了初始化屏幕、设置像素颜色、扫描线填充算法等功能,并提供了鼠标和键盘事件处理,可以进行画线、画圆和多边形填充操作。
摘要由CSDN通过智能技术生成