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();
}
相关阅读:
Ubuntu 13.04 安装 OpenGL
如何在Ubuntu使用eclipse for c++配置OpenGL