2011-12-25 12 views
7

Solo quiero dibujar un cilindro en OpenGL. Encontré muchas muestras, pero todas dibujan cilindros en el eje Z. Quiero que estén en el eje X o Y Cómo puedo hacer esto. El código siguiente es el código de dibujar el cilindro en dirección Z y yo no quiero queCómo dibujar el cilindro en el eje y o x en OpenGL

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

Respuesta

6

Puede utilizar glRotate(angle, x, y, z) girar su sistema de coordenadas:

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 proporcionado buen enlace. Úselo! – DaddyM

4

En cada render uso glPushMatrixglRotatef extraer el cilindro y terminar su dibujo con glPopMatrix.

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

Ej .: OnRender() Ejemplo de función

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 
} 
Cuestiones relacionadas