2011-12-25 10 views
7

Voglio solo disegnare un cilindro in opengl. Ho trovato molti campioni ma tutti disegnano cilindri sull'asse z. Voglio che siano in asse X o Y. Come posso fare questo. Il codice qui sotto è il codice disegnare il cilindro in direzione z e io non voglio cheCome disegnare cilindro in asse yo x in opengl

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

risposta

6

È possibile utilizzare glRotate(angle, x, y, z) per ruotare il sistema di coordinate:

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 fornito un buon collegamento Usalo! – DaddyM

4

Su ogni rendere l'uso glPushMatrixglRotatef disegnare il cilindro e finire il disegno con glPopMatrix.

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

Es .: OnRender() funzione di esempio

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 
}