if(key == GLUT_KEY_RIGHT) yRot += 5.0f;
if(xRot > 356.0f) xRot = 0.0f;
if(xRot < -1.0f) xRot = 355.0f;
if(yRot > 356.0f) yRot = 0.0f;
if(yRot < -1.0f) yRot = 355.0f;
// Refresh the Window
glutPostRedisplay();// this will refresh the window, so, it works the same to call RenderScene() directly }
void DrawAxis() {
//绘制x、y、z坐标轴 {
glColor3f( 0.0f, 0.0f, 1.0f );//指定线的颜色,蓝色
glBegin( GL_LINES ); {
// x-axis
glVertex3f( 0.0f, 0.0f, 0.0f); glVertex3f( 200.0f, 0.0f, 0.0f);
// x-axis arrow
glVertex3f( 200.0f, 0.0f, 0.0f); glVertex3f( 193.0f, 3.0f, 0.0f); glVertex3f( 200.0f, 0.0f, 0.0f); glVertex3f( 193.0f,-3.0f, 0.0f); } glEnd();
glColor3f( 0.0f, 1.0f, 0.0f );//指定线的颜色,绿色
glBegin( GL_LINES ); {
// y-axis
glVertex3f( 0.0f, 0.0f, 0.0f); glVertex3f( 0.0f, 200.0f, 0.0f); glVertex3f( 0.0f, 200.0f, 0.0f); glVertex3f( 3.0f, 193.0f, 0.0f); glVertex3f( 0.0f, 200.0f, 0.0f); glVertex3f( -3.0f, 193.0f, 0.0f);
} glEnd();
glColor3f( 1.0f, 0.0f, 0.0f );//指定线的颜色,红色
glBegin( GL_LINES ); {
// z-axis
glVertex3f( 0.0f, 0.0f, 0.0f ); glVertex3f( 0.0f, 0.0f, 200.0f ); glVertex3f( 0.0f, 0.0f, 200.0f ); glVertex3f( 0.0f, 3.0f, 193.0f ); glVertex3f( 0.0f, 0.0f, 200.0f ); glVertex3f( 0.0f, -3.0f, 193.0f); } glEnd(); } }
运行效果图: