⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bezier曲线.txt

📁 实现bezier曲线画法
💻 TXT
字号:
#include <glut.h>
#include "iostream.h"
double x0;double y0;
			double x1;double y1;
			double x2;double y2;
			double x3;double y3;

void drawpixel(float x1,float y1,float x2,float y2)
{
	
    glBegin(GL_POINTS);
        //glVertex2f(m,n);
		glVertex2f(x1,y1);
		glVertex2f(x2,y2);
    glEnd();
	glFlush();
}
//void Bresenhamline(int x0,int y0,int x1, int y1)
void Bezier(double x0,double y0,
			double x1,double y1,
			double x2,double y2,
			double x3,double y3)
{
	double x,y,X,Y;
	x=x0;y=y0;
	for (double t=0.0; t<= 1.0;t=t+0.001)
	{
		X=x;Y=y;
		x=(1-t)*(1-t)*(1-t)*x0+3*t*(1-t)*(1-t)*x1+3*t*t*(1-t)*x2+t*t*t*x3;
        y=(1-t)*(1-t)*(1-t)*y0+3*t*(1-t)*(1-t)*y1+3*t*t*(1-t)*y2+t*t*t*y3;
		drawpixel(X,Y,x,y);
	}
}
void Render(void){
	glClear(GL_COLOR_BUFFER_BIT);
	glColor3f(1.0f, 0.0f, 0.0f);
	glPointSize(1.0);
	Bezier(x0,y0,x1,y1,x2,y2,x3,y3);
	//Bresenhamline(0,0,0,100);
	  

}
//该函数用于设置渲染状态
void SetupRC(void)
{
	glClearColor(0.0f, 1.0f, 0.0f,0.0f);
	//设置背景的颜色
}

//当窗口大小改变时由GLUT函数调用,保证所绘正方形的形状

void ChangeSize(GLsizei width, GLsizei Height)
{
	GLfloat aspectRatio;

	if (Height == 0) {
		Height = 1;
	}

	glViewport(0, 0, width, Height);

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();

	aspectRatio = (GLfloat)width / (GLfloat) Height;

	if (width <= Height) {
		glOrtho(-200.0, 200.0, -200.0 / aspectRatio, 200.0 / aspectRatio, 1.0, -1.0);
	}
	else{
		glOrtho(-200.0 * aspectRatio, 200.0 * aspectRatio, -200.0, 200.0, 1.0, -1.0);
	}

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
}

//主程序入口
void main(void)
{
   cout<<"请输入坐标:"<<endl;	
   cin>>x0>>y0>>x1>>y1>>x2>>y2>>x3>>y3;
	glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
	glutCreateWindow("      Bezier画线      ");
	glutDisplayFunc(Render);
	glutReshapeFunc(ChangeSize);
	SetupRC();
	glutMainLoop();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -