9

OpenGLで円柱を描きたいだけです。たくさんのサンプルを見つけましたが、それらはすべて z 軸に円柱を描いています。私はそれらがxまたはy軸にあることを望みます。これどうやってするの。以下のコードは、円柱を z 方向に描画するコードであり、私はそれを望んでいません

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

2 に答える 2

9

を使用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

于 2011-12-25T19:11:58.027 に答える
4

すべてのレンダリングglPushMatrix glRotatefでシリンダーを描画し、 で描画を終了します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  
}  
于 2011-12-25T19:02:32.297 に答える