才刚学opengl不久,还有很多地方不清楚,所以正一边练习一边自学,还请各位高手讲解时能详细一点。
我想写一个基于MFC的旋转的立方体程序,加入了如下代码: glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
glLoadIdentity(); // Reset The Current Modelview Matrix


//NEW//////////////////NEW//////////////////NEW//////////////////NEW////////////////// glTranslatef(0.0f, 0.0f,0.0f); // Translate Into The Screen 7.0 Units
glRotatef(m_rotate,0.0f,1.0f,0.0f); // Rotate The cube around the Y axis
glRotatef(m_rotate,1.0f,1.0f,1.0f);
glScalef(0.5,0.5,0.5);
glBegin(GL_QUADS); // Draw a cube with quads
glColor3f(0.0f,1.0f,0.0f); // Color Blue
glVertex3f( 1.0f, 1.0f,-1.0f); // Top Right Of The Quad (Top)
glVertex3f(-1.0f, 1.0f,-1.0f); // Top Left Of The Quad (Top)
glVertex3f(-1.0f, 1.0f, 1.0f); // Bottom Left Of The Quad (Top)
glVertex3f( 1.0f, 1.0f, 1.0f); // Bottom Right Of The Quad (Top)
glColor3f(1.0f,0.5f,0.0f); // Color Orange
glVertex3f( 1.0f,-1.0f, 1.0f); // Top Right Of The Quad (Bottom)
glVertex3f(-1.0f,-1.0f, 1.0f); // Top Left Of The Quad (Bottom)
glVertex3f(-1.0f,-1.0f,-1.0f); // Bottom Left Of The Quad (Bottom)
glVertex3f( 1.0f,-1.0f,-1.0f); // Bottom Right Of The Quad (Bottom)
glColor3f(1.0f,0.0f,0.0f); // Color Red
glVertex3f( 1.0f, 1.0f, 1.0f); // Top Right Of The Quad (Front)
glVertex3f(-1.0f, 1.0f, 1.0f); // Top Left Of The Quad (Front)
glVertex3f(-1.0f,-1.0f, 1.0f); // Bottom Left Of The Quad (Front)
glVertex3f( 1.0f,-1.0f, 1.0f); // Bottom Right Of The Quad (Front)
glColor3f(1.0f,1.0f,0.0f); // Color Yellow
glVertex3f( 1.0f,-1.0f,-1.0f); // Top Right Of The Quad (Back)
glVertex3f(-1.0f,-1.0f,-1.0f); // Top Left Of The Quad (Back)
glVertex3f(-1.0f, 1.0f,-1.0f); // Bottom Left Of The Quad (Back)
glVertex3f( 1.0f, 1.0f,-1.0f); // Bottom Right Of The Quad (Back)
glColor3f(0.0f,0.0f,1.0f); // Color Blue
glVertex3f(-1.0f, 1.0f, 1.0f); // Top Right Of The Quad (Left)
glVertex3f(-1.0f, 1.0f,-1.0f); // Top Left Of The Quad (Left)
glVertex3f(-1.0f,-1.0f,-1.0f); // Bottom Left Of The Quad (Left)
glVertex3f(-1.0f,-1.0f, 1.0f); // Bottom Right Of The Quad (Left)
glColor3f(1.0f,0.0f,1.0f); // Color Violet
glVertex3f( 1.0f, 1.0f,-1.0f); // Top Right Of The Quad (Right)
glVertex3f( 1.0f, 1.0f, 1.0f); // Top Left Of The Quad (Right)
glVertex3f( 1.0f,-1.0f, 1.0f); // Bottom Left Of The Quad (Right)
glVertex3f( 1.0f,-1.0f,-1.0f); // Bottom Right Of The Quad (Right)
glEnd(); // End drawing cube with quads
glFlush();
m_rotate +=(float)0.9f;
这代码应该是没问题的,但出现的结果好像是六个面独自旋转,而不是以一个整体旋转,所以问一下,还要在什么地方再加上什么代码或进行什么修改才能得到想要的结果。
由于代码太多,所以其它代码就不粘上来了,解决后立即结帖。

解决方案 »

  1.   

     glRotatef(m_rotate,0.0f,1.0f,0.0f);        // Rotate The cube around the Y axis
     glRotatef(m_rotate,1.0f,1.0f,1.0f);  
    你到底想要绕哪个轴旋转?
      

  2.   

    这个没多大关系,就让它绕x,y,z好了,呵呵...
      

  3.   

    你这段代码如果画立方体没问题的话,那就看不出什么了,不知道你看过NeHe教程没,从第5课就开始将旋转的问题了,你可以下载下来看看~
      

  4.   

    NeHe的正在看,由于六个面好像是独立旋转(原因不明),所以就组不成正方体了