RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
#include <gl/glut.h>
  • #include <gl/GL.h>
  • #define DIMENSION 2//定义维度为2维
  • typedef GLfloat VECTOR [DIMENSION];
  • VECTOR points[4]= {{-1.0,-1.0},{0.0,2.0},{1.0,2.0},{2.0,1.0}};//四个控制点
  • GLint count =10000;//绘制10000个点
  • int ww,hh;
  • void display()
  • {
  •  VECTOR c[4];//此矩阵是P和M的积,就是控制点阵和Bezier基矩阵的乘积
  •  for (int i =0;i<DIMENSION;i++)
  •  {
  •  
  •  c[3][i] = (0-points[0][i])+3*points[1][i]-3*points[2][i]+points[3][i];
  •  c[2][i] =       3*points[0][i]-6*points[1][i]+3*points[2][i];
  •  c[1][i] =               (0-3*points[0][i])+3*points[1][i];
  •  c[0][i] =                       points[0][i];
  •  
  •  
  •  
  •  }
  •  GLfloat v[DIMENSION];
  •  GLfloat newV[DIMENSION];
  •  GLfloat deltat = 1.0/count;
  •  GLfloat t = 0.0;
  •  
  •  
  •  glBegin(GL_LINE_STRIP);//绘制控制曲线
  •   glVertex2fv(points[0]);
  •   glVertex2fv(points[1]);
  •   glVertex2fv(points[2]);
  •   glVertex2fv(points[3]);
  •  glEnd();
  •  glFlush();
  •   
  •  v[0] = points[0][0];v[1] = points[0][1];
  •  for (int i = 0;i<count;i++)//绘制最终结果
  •  {
  •  t += deltat;
  •  newV[0] = c[0][0] + t*(c[1][0] + t*(c[2][0] + t*c[3][0]));
  •  newV[1] = c[0][1] + t*(c[1][1] + t*(c[2][1] + t*c[3][1]));
  •  glColor3f(0.0,0.0,1.0);
  •  glBegin(GL_LINES);
  •  glVertex2fv(v);
  •  glVertex2fv(newV);
  •  glEnd();
  •  glFlush();
  •  v[0] = newV[0];v[1] = newV[1];
  •  
  •  
  •  }
  •  
  • }
  • void init()
  • {
  •  
  •  glClearColor(0.0 , 0.0 ,0.0 , 0.0);
  •  glColor3f(1.0 ,1.0 ,1.0);
  •  
  •  glMatrixMode(GL_PROJECTION);
  •  glLoadIdentity();
  •  gluOrtho2D(-4.0 ,4.0 ,-4.0 ,4.0);
  •  
  • }
  •  
  • void main(int argc,char **argv)
  • {
  •  glutInit(&argc,argv);
  •  glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
  •  glutInitWindowSize(500,500);
  •  glutInitWindowPosition(500,200);
  •  glutCreateWindow("reshape");
  •  //glutReshapeFunc(myreshape);
  •  glutDisplayFunc(display);
  •  init();
  •  //glutIdleFunc(myidle);
  •  //glutKeyboardFunc(mykeyboard);
  •  //glutSpecialFunc(myspecialkey);
  •  
  •  glutMainLoop();
  • }
  • 使用OpenGL怎么实现一个Bezier曲线

    看完上述内容,你们对使用OpenGL怎么实现一个Bezier曲线有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注创新互联行业资讯频道,感谢大家的支持。


    网站栏目:使用OpenGL怎么实现一个Bezier曲线
    URL网址:http://www.xdwzjz.cn/article/jieccd.html
  • Top