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
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.
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();
Here is the code: glPushMatrix(); glRotatef(30.0f, 0.0f, 0.0f, 1.0f); glTranslatef(vec_vehicle_position_. x, vec_vehicle_position_.
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 ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With