我只想在opengl中画一个圆柱体。我找到了很多样本,但它们都在z轴上画圆柱体。我想让它们在x或y轴上。我怎么能这么做呢?下面的代码是在z方向绘制圆柱体的代码,我不想让它
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);
http://www.opengl.org/sdk/docs/man/xhtml/glRotate.xml 每次渲染时使用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
}