2011-12-25 30 views
7

Po prostu chcę narysować cylinder w opengl. Znalazłem mnóstwo próbek, ale wszystkie z nich ciągną cylindry w osi Z. Chcę, żeby były na osi x lub y. Jak mogę to zrobić. Poniższy kod jest kodem wyciągnąć cylinder w kierunku Z i nie chcę goJak narysować cylinder w osi y lub x w opengl

GLUquadricObj *quadratic; 
    quadratic = gluNewQuadric(); 
    gluCylinder(quadratic,0.1f,0.1f,3.0f,32,32); 

Odpowiedz

6

Można użyć glRotate(angle, x, y, z) aby obrócić układ współrzędnych:

GLUquadricObj *quadratic; 
quadratic = gluNewQuadric(); 
glRotatef(90.0f, 0.0f, 1.0f, 0.0f); 
gluCylinder(quadratic,0.1f,0.1f,3.0f,32,32); 

http://www.opengl.org/sdk/docs/man/xhtml/glRotate.xml

+1

@cerq: Micha pod warunkiem, dobry link. Użyj tego! – DaddyM

4

Na każdy czyni korzystanie glPushMatrixglRotatef wyciągnąć cylinder i zakończyć swój rysunek z glPopMatrix.

Np .: glRotatef(yRotationAngle, 0.0f, 1.0f, 0.0f); // Rotate your object around the y axis on yRotationAngle radians

Np .: OnRender() przykład funkcja

void OnRender() { 
    glClearColor(1.0f, 0.0f, 0.0f, 1.0f); // Clear the background 
    glClear(GL_COLOR_BUFFER_BIT); //Clear the colour buffer 
    glLoadIdentity(); // Load the Identity Matrix to reset our drawing locations 

    glRotatef(yRotationAngle, 0.0f, 1.0f, 0.0f); // Rotate our object around the y axis on yRotationAngle radians 

    // here *render* your cylinder (create and delete it in the other place. Not while rendering) 
    gluCylinder(quadratic,0.1f,0.1f,3.0f,32,32); 

    glFlush(); // Flush the OpenGL buffers to the window 
} 
Powiązane problemy