OpenGL计算机图形学梁友栋裁剪算法实验代码及运行结果 下载本文

《计算机图形学实验》报告

实验时间:实验地点:信息学院实验目的:掌握梁友栋裁剪

任课教师:钱文华

2016年春季学期

实验:梁友栋裁剪

2016年11月17日 2204

程序代码:#include #include #include #include

class wcPt2D{ public:

GLfloat x,y; void

setCoords(GLfloat

xCoord,GLfloat

yCoord){x=xCoord;y=yCoord;} };

inline GLint round(const GLfloat a){return GLint(a+0.5);} void setPixel(int x,int y){ }

glBegin(GL_POINTS);

glVertex2i(x,y);

GLfloat getx() const{return x;} GLfloat gety() const{return y;}

glEnd();

void init(){ }

void lineBres(GLfloat x0,GLfloat y0,GLfloat xEnd,GLfloat yEnd){

int dx = fabs(xEnd - x0),dy = fabs(yEnd - y0); int p = 2*dy - dx;

int twoDy = 2*dy,twoDyMinusDx = 2*(dy - dx); int x,y; if(x0>xEnd){ } else{ }

setPixel(x,y); x = x0; y = y0; x = xEnd; y = yEnd; xEnd = x0;

glMatrixMode (GL_PROJECTION); gluOrtho2D(-200.0,200.0,-200.0,200.0); glClearColor(1.0,1.0,1.0,0.0);