Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to rotate a specific object in openGL?

I have some objects on the screen and would like to rotate only one of them. I tried using the glRotatef(...) function but turns out glRotatef(...) rotates all my objects (rotates the camera, maybe?). How can I rotate only one?

I use openGL ES 1.1

like image 661
snakile Avatar asked Aug 18 '10 17:08

snakile


People also ask

How do I rotate a single object in OpenGL?

In GLUT we rotate the object by glRotate3f(angle_rotation,GLfloat x, GLfloat y ,GLfloat z) function angle_rotation parameter is value of angle to rotate and x,y,z co-ordinate are axis of rotation.

How do I rotate a 2d object in OpenGL?

What you want is this: glPushMatrix(); glTranslatef(center. getX(), center. getY(), 0.0f); glRotatef(rotation, 0.0, 0.0, 1.0); glBegin(GL_LINE_LOOP); glColor3f(1.0, 1.0, 1.0); glVertex2f(0.0, 1.0); // more vertices glEnd(); glPopMatrix();

How do I rotate a rectangle in OpenGL?

Here is the code: glPushMatrix(); glRotatef(30.0f, 0.0f, 0.0f, 1.0f); glTranslatef(vec_vehicle_position_. x, vec_vehicle_position_.


1 Answers

You need the rotation to be in effect only when the geometry you're interested in is being drawn.

... draw stuff ...
glPushMatrix();
glRotatef(angle, 0, 1, 0);
... draw rotated stuff ...
glPopMatrix();
... draw more stuff ...
like image 118
Jay Kominek Avatar answered Sep 17 '22 17:09

Jay Kominek