基于OpenGL实现的多段Bezier曲线拼接(3)

void reshape(int w, int h)
{
 glViewport(0, 0, (GLsizei) w, (GLsizei) h);
 glMatrixMode(GL_PROJECTION);
 glLoadIdentity();
 if (w <= h)
  glOrtho(-5.0, 5.0, -5.0*(GLfloat)h/(GLfloat)w,
  5.0*(GLfloat)h/(GLfloat)w, -5.0, 5.0);
 else
  glOrtho(-5.0*(GLfloat)w/(GLfloat)h,
  5.0*(GLfloat)w/(GLfloat)h, -5.0, 5.0, -5.0, 5.0);
 glMatrixMode(GL_MODELVIEW);
 glLoadIdentity();
}

void keyboard(unsigned char key, int x, int y)
{
 switch (key) {
  case 27:
    exit(0);
    break;
 }
}

void mouse(int button, int state, int x, int y)
{
 double vertex[3];

//获取矩阵信息
 glGetIntegerv(GL_VIEWPORT, g_Viewport);
 glGetDoublev(GL_MODELVIEW_MATRIX, g_ModelMatrix);
 glGetDoublev(GL_PROJECTION_MATRIX, g_ProjMatrix);

y = g_Viewport[3] - y;
 gluUnProject( x, y, 0,
  g_ModelMatrix, g_ProjMatrix, g_Viewport,
  &vertex[0], &vertex[1], &vertex[2] );

if (button==GLUT_LEFT && state==GLUT_DOWN)
 {
  myBezier.mouseSynchro( BezierCurve::LButtonDown, vertex );
  glutSetCursor( GLUT_CURSOR_RIGHT_ARROW );
 }
 else if (button == GLUT_LEFT && state == GLUT_UP)
 {
  myBezier.mouseSynchro( BezierCurve::LButtonUp, vertex );
 }

glutPostRedisplay();
}

//////////////////////////////////////////////////////////////////////////
// 计算控制节点
void motion(int x, int y)
{
 double vertex[3];

glutSetCursor( GLUT_CURSOR_CROSSHAIR );
 y = g_Viewport[3] - y;

gluUnProject( x, y, 0,
  g_ModelMatrix, g_ProjMatrix, g_Viewport,
  &vertex[0], &vertex[1], &vertex[2] );

myBezier.mouseSynchro( BezierCurve::MouseMove, vertex );
 glutPostRedisplay();
}

相关阅读

OpenGL 渲染篇

Ubuntu 13.04 安装 OpenGL

OpenGL三维球体数据生成与绘制【附源码】

Ubuntu下OpenGL编程基础解析

如何在Ubuntu使用eclipse for c++配置OpenGL

《OpenGL超级宝典》学习笔记

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/270729584dbf2311efb6e609bfc79018.html