大家帮忙看下这段程序!
这个程序是用来把鼠标的输入和图形联系起来的,用鼠标的左右中键来控制图形的位置,下面这段只是其中的一部分,我用的是Visual Studio 2008的C++,下面这段是老师给的,我看不太懂,switch的作用是什么?是不是把鼠标的位置分别赋给x和y,望高手给解释下,如果可能的最好每句都翻译解释一下,谢谢!!!void mouseFunc(int button, int state, int x, int y )
{
switch( button )
{
case GLUT_LEFT_BUTTON:
switch( state )
{
case GLUT_DOWN:
m_LButtonDown = TRUE;
m_LDownPos.x = x;
m_LDownPos.y = y;
break;
case GLUT_UP:
m_LButtonDown = FALSE;
break;
}
break;
case GLUT_RIGHT_BUTTON:
switch( state )
{
case GLUT_DOWN:
m_RButtonDown = TRUE;
m_RDownPos.x = x;
m_RDownPos.y = y;
break;
case GLUT_UP:
m_RButtonDown = FALSE;
break;
}
break;
case GLUT_MIDDLE_BUTTON:
switch(state)
{
case GLUT_DOWN:
m_MButtonDown = TRUE;
m_MDownPos.x = x;
m_MDownPos.y = y;
break;
case GLUT_UP:
m_MButtonDown = FALSE;
break;
}
break;
default:
break;
} //End of switch
}
还有下面这段程序,到底是干什么用的,-=是什么意思?+=是什么意思?x和y前面(double)是什么意思,为什么要放在x和y的前面加上括号?望高手解释下,最好把每句都解释下,谢谢。本科毕业三年后读研中,又用到了C语言,本科本来学的就不太好,现在更是快忘光了!
void mouseMotionFunc(int x, int y)
{
/* find out what action to perform */
if (m_LButtonDown)
{
m_yRotate -= (m_LDownPos.x - (double)x)/2.0;
m_xRotate -= (m_LDownPos.y - (double)y)/2.0;
m_LDownPos.x = x;
m_LDownPos.y = y;
}
if (m_RButtonDown)
{
m_transX -= (m_RDownPos.x - (double)x)/10.0f;
m_transY += (m_RDownPos.y - (double)y)/10.0f;
m_RDownPos.x = x;
m_RDownPos.y = y;
}
if (m_MButtonDown)
{
m_transZ -= (m_MDownPos.y - (double)y)/10.0f;
m_MDownPos.x = x;
m_MDownPos.y = y;
}
glutSetWindow(win_id);
glutPostRedisplay();
}