2011-12-25 183 views
7

我只想在opengl中繪製圓柱體。我發現了很多樣品,但是他們都在z軸上繪製柱面。我希望他們在x或y軸。我怎樣才能做到這一點。下面的代碼是代碼繪製缸Z方向,我不希望它如何在y或x軸上繪製圓柱體opengl

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

回答

6

您可以使用glRotate(angle, x, y, z)旋轉你的座標系:

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:米莎提供了很好的鏈接用它! – DaddyM 2011-12-25 19:36:14

4

在每一個渲染使用glPushMatrixglRotatef畫缸,並與glPopMatrix完成繪圖。

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

例:OnRender()功能例如

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 
} 
相關問題