How to draw a cylinder along the y or x axis in opengl

I just want to draw a cylinder in opengl. I found many patterns, but they all draw cylinders along the z axis. I want them to be on the x or y axis. How can i do this. The code below is the code that draws the cylinder in the z direction, and I don't want it

GLUquadricObj *quadratic; quadratic = gluNewQuadric(); gluCylinder(quadratic,0.1f,0.1f,3.0f,32,32); 
+7
source share
2 answers

You can use glRotate(angle, x, y, z) to rotate your coordinate system:

 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

+6
source

Each time you use glPushMatrix rendering glPushMatrix glRotatef draw a cylinder and end the drawing with glPopMatrix .

Example: glRotatef(yRotationAngle, 0.0f, 1.0f, 0.0f); // Rotate your object around the y axis on yRotationAngle radians glRotatef(yRotationAngle, 0.0f, 1.0f, 0.0f); // Rotate your object around the y axis on yRotationAngle radians

Example: OnRender() function example

 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 } 
+4
source

All Articles