用链表方法实现:
#include<iostream>
#include<glut.h>
using namespace std;
int result[50][2] = { {10, 80},{70, 10},{80, 80},{90, 10},{130, 80},{80, 130}};
enum mark { L, B, R, T};
int c = -1;
struct node {
float data[2];
node* next;
node* pre;
};
void initNode(node *&head) {
head = new node;
head->data[0] = 0;
head->data[1] = 0;
head->next = NULL;
head->pre = NULL;
node *p = head;
node *q = NULL;
//此处直接输入的点的起始数目进行初始化
for (int i = 0; i < 6; ++i) {
q = new node;
q->data[0] = result[i][0];
q->data[1] = result[i][1];
q->pre = p;
p->next = q;
p = q;
}
p->next = head;
head->pre = p;
}
//分别对应每个边裁剪
void testPoint(node *&first, node *&head, int& edg, float xl, float xr, float yb, float yt) {
if (edg == 4) {
return;
}
node* p = first;
node* q = p->pre;
//依次对每个点处理,在线内的就存入result数组
while (p