#include<glut.h>
#include<iostream>
#define L 00001
#define R 00002
#define B 00004
#define T 00010
#define M 00000
#define LT 00011
#define LB 00005
#define RT 00012
#define RB 00006
//#define L 0x0001
//#define R 0x0002
//#define B 0x0004
//#define T 0x0008
//#define M 0x0000
//
//#define LT 0x0009
//#define LB 0x0005
//#define RT 0x000a
//#define RB 0x0006
using namespace std;
struct rectan {
int xx0, yy0;
int xx1, yy1;
}rec;
int temX = 0, tempY = 0;
int c0 = 0, c1 = 0, c3 = 0;
bool f = false;
int CSLine(float xwl, float xwr, float ywb, float ywt, float x, float y) { //得到编码区
int temp = 0;
if (x < xwl) {
temp |= L;
}
else if (x > xwr) {
temp |= R;
}
if (y < ywb) {
temp |= B;
}
else if (y > ywt) {
temp |= T;
}
return temp;
}
void CSLineP(int temp, float xwl, float xwr, float ywb, float ywt, float &x1, float &y1, float x2, float y2, float& x, float& y) {
float k = (y2 - y1) / (x2 - x1);
if ((temp & L) == 1) {
y1 = y1 + k * (xwl - x1);
x1 = xwl;
}
if ((temp & R) == 2) {
y1 = y1 + k * (xwr - x1);
x1 = xwr;
}
if ((temp & B) == 4 && y1 < ywb) {
x1 = x1 + (ywb - y1) / k;
y1 = ywb;
}
if ((temp & T) == 8 && y1 > ywt) {
x1 = x1 + (ywt - y1) / k;
y1 = ywt;
opengl实现cs、liang-barsky直线裁剪算法
最新推荐文章于 2022-07-09 09:00:00 发布
该博客详细介绍了如何使用OpenGL实现计算机图形学中的CS(Crossing Segment)和Liang-Barsky直线裁剪算法,包括代码示例,用于在指定矩形区域内进行直线裁剪。读者将学习到两种裁剪算法的原理及其在OpenGL环境中的应用。
摘要由CSDN通过智能技术生成