2个简单的物体无法正确旋转

时间:2014-01-19 00:39:38

标签: c++ opengl

所以我基本上想要以不同方式旋转2个对象(金字塔和立方体)。   在使用不同的值渲染glRotatef()函数之前,我使用了两个对象。   但是发生的是,两者都是独立旋转,它们都旋转相同(第二个物体围绕第一个)。

两个物体的原始位置: Starting position

这就是旋转时的样子: As you can see the second object(cube) is rotating around the first(pyramid)

在绘制第二个要重置的对象之前,我尝试使用第二个LoadIdentity()函数   观点?(我不会非常理解这个函数的工作,所以如果有人向我解释,我会非常感激),但是第二个对象甚至没有被绘制出来。

有没有人有任何建议?我是OpenGL的新手,所以它可能是一些新手的错误,但我看不到它。

作为参考,我使用了本教程(你可以看到LoadIdentity()被使用了两次):http://nehe.gamedev.net/tutorial/picking_alpha_blending_alpha_testing_sorting/16005/

以下是代码:

    System::Void Render(System::Void)
    {

        // Sfera sprem
        float kot1, kot2;
        float xx,yy,zz,xxp,yyp,zzp;

        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Počistimo ekran




            glLoadIdentity();
            glTranslatef(-2.0f, -1.0f, -6.0f); // Translacija objekta, parametri x,y,z os       

            glRotatef(rtri,0,1,0.0);
            //glScalef(risiPiramidaScaleX,risiPiramidaScaleY,risiPiramidaScaleZ);           
            glColor3f(risiPiramidaR,risiPiramidaG,risiPiramidaB);    


        glBegin(GL_TRIANGLES); // Začetek Risanja trikotnikov


                // Stran 1
                glVertex3f(0.0f, 1.0f, 0.0f); // Top          
                glVertex3f(-1.0f, -1.f, 0.0f); // Spodaj Levo  
                glVertex3f(1.0f, -1.0f, 0.0f); // Spodaj Desno

                // Stran 2


                glVertex3f(1.0f, -1.0f, 0.0f); // Top  
                glVertex3f(1.0f, -1.f, -2.0f); // Spodaj Levo   
                glVertex3f(0.0f, 1.0f, 0.0f); // Spodaj Desno

                // Stran 3

                glVertex3f(1.0f, -1.f, -2.0f); // Top
                glVertex3f(-1.0f, -1.f, -2.0f); // Spodaj Levo 
                glVertex3f(0.0f, 1.0f, 0.0f); // Spodaj Desno

                // Stran 4


                glVertex3f(-1.0f, -1.f, -2.0f); // Top                 
                glVertex3f(-1.0f, -1.f, 0.0f); // Spodaj Levo 
                glVertex3f(0.0f, 1.0f, 0.0f); // Spodaj Desno

                // Stran 5


                glVertex3f(1.0f, -1.0f, 0.0f); // Top
                glVertex3f(1.0f, -1.0f, -2.0f); // Spodaj Levo    
                glVertex3f(-1.0f, -1.0f, -2.0f); // Spodaj Desno


                // Stran 6


                glVertex3f(-1.0f, -1.0f, -2.0f); // Top
                glVertex3f(-1.0f, -1.0f, 0.0f); // Spodaj Levo    
                glVertex3f(1.0f, -1.0f, 0.0f); // Spodaj Desno




                glEnd(); // Konec Risanja Trikotnikov







                glTranslatef(3.0f, 0.0f, 0.0f);             
            //  glScalef(risiKockaScaleX,risiKockaScaleY,risiKockaScaleZ);
                glRotatef(rquad,1,0,0.5);

                glColor3f(risiKockaR,risiKockaG,risiKockaB);    

                glBegin(GL_QUADS); // Risanje kocke
                glVertex3f( -1.0f, 1.0f, 0.0f); // Zgornji levi 
                glVertex3f(  1.0f, 1.0f, 0.0f); // Zgornji desni
                glVertex3f(  1.0f, -1.0f, 0.0f); // Spodnji desni
                glVertex3f( -1.0f, -1.0f , 0.0f); // Spodnji levi

                //stranica 2
                glVertex3f(  1.0f, 1.0f, 0.0f); // Zgornji desni
                glVertex3f(  1.0f, -1.0f, 0.0f); // spodnji desni                   
                glVertex3f(  1.0f, -1.0f, -2.0f); // Spodaj z os            
                glVertex3f(  1.0f,  1.0f, -2.0f); // Spodnji desni


                //str 3
                glVertex3f(   1.0f,  1.0f, -2.0f); // Zgornji desni
                glVertex3f(  -1.0f, 1.0f, -2.0f); // zgornji desni                  
                glVertex3f(  -1.0f, -1.0f, -2.0f); // Spodnji levi          
                glVertex3f(  1.0f, -1.0f, -2.0f); // Spodnji desni

                //str 4
                glVertex3f(  -1.0f, 1.0f, -2.0f); // Zgornji desni
                glVertex3f(  -1.0f, -1.0f, -2.0f); // zgornji desni                 
                glVertex3f(  -1.0f, -1.0f, 0.0f); // Spodnji levi           
                glVertex3f(  -1.0f, 1.0f, 0.0f); // Spodnji desni

                //str 5
                glColor3f(0.0f,1.0f,0.0f);    

                glVertex3f(  -1.0f, 1.0f, -2.0f); // Zgornji desni
                glVertex3f(  1.0f, 1.0f, -2.0); // zgornji desni                    
                glVertex3f(  1.0f, 1.0f, 0.0f); // Spodnji levi         
                glVertex3f(  -1.0f, 1.0f, 0.0f); // Spodnji desni

                //str 6
                glColor3f(1.0f,0.0f,0.0f);    
                glVertex3f(  -1.0f, -1.0f, -2.0f); // Zgornji desni
                glVertex3f(  1.0f, -1.0f, -2.0); // zgornji desni                   
                glVertex3f(  1.0f, -1.0f, 0.0f); // Spodnji levi            
                glVertex3f(  -1.0f, -1.0f, 0.0f); // Spodnji desni




            glEnd(); // Konec risanja kocke
        rquad += 0.2;
        rtri += 0.5;




    }

0 个答案:

没有答案