2011-12-25 37 views
7

私はちょうどopenglで円柱を描きたいと思います。私は多くのサンプルを見つけましたが、それらのすべてがz軸に円筒を描画します。私はそれらをx軸またはy軸にしたい。これどうやってするの。以下のコードは、コードは、z方向に円柱を描くと私はすべての上にOpenGLでy軸またはx軸に円柱を描く方法

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

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 
} 
関連する問題