How do I rotate a gluCynlinder in OpenGL?
For context, I'm trying to model a simple 1x1 lego brick in OpenGL. I setup my camera to look at the origin and 'up' is in the Y direction. I'm trying to draw a cylinder for the little nub on the cube, and cannot figure out how to rotate it. C++ code:
//draw cylinder
glPushMatrix();
glTranslated(0.0, 0.4 , 0.0);
//glRotatef(an开发者_运维问答gle, 1.0f, 0.0f, 0.0f);
GLUquadricObj * qobj = gluNewQuadric();
gluCylinder(qobj, 0.24, 0.24, 0.18, 16, 16);
glPopMatrix();
I'm trying to rotate it around the x axis by 90 degrees but glRotatef doesn't appear to do anything, or just makes the whole thing disappear. What am I missing?
Worked well for me:
glPushMatrix();
GLUquadricObj * qobj = gluNewQuadric();
glTranslated(0.0, 0.4 , 0.0);
glRotatef(angle * 10, 0.0f, 1.0f, 0.0f);
gluCylinder(qobj, 1.24, 1.24, 1.18, 16, 16);
gluDeleteQuadric(qobj);
glPopMatrix();
No matter which order of glRotate and glTranslate i've used.
精彩评论