我只想在opengl中绘制圆柱体。我发现了很多样品,但是他们都在z轴上绘制柱面。我希望他们在x或y轴。我怎样才能做到这一点。下面的代码是代码绘制缸Z方向,我不希望它如何在y或x轴上绘制圆柱体opengl
GLUquadricObj *quadratic;
quadratic = gluNewQuadric();
gluCylinder(quadratic,0.1f,0.1f,3.0f,32,32);
我只想在opengl中绘制圆柱体。我发现了很多样品,但是他们都在z轴上绘制柱面。我希望他们在x或y轴。我怎样才能做到这一点。下面的代码是代码绘制缸Z方向,我不希望它如何在y或x轴上绘制圆柱体opengl
GLUquadricObj *quadratic;
quadratic = gluNewQuadric();
gluCylinder(quadratic,0.1f,0.1f,3.0f,32,32);
您可以使用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);
在每一个渲染使用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
}
@cerq:米莎提供了很好的链接用它! – DaddyM 2011-12-25 19:36:14