Public Group

# Basic OpenGL Rotation

This topic is 4092 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi guys, Im fairly new to OpenGL, and i cannot work out how to do this, im just trying to rotate a rectangle (GL_QUAD) around the Y axis. Here is my attempt (from my main draw function):
	glPushMatrix();
glRotated(angle, 0,1,0);
glVertex3d(0, 0, 0);
glVertex3d(100, 0, 0);
glVertex3d(100, -50, 0);
glVertex3d(0, -50, 0);
glEnd();
glPopMatrix();

if(angle == 360)
angle = 0;
else
angle+=1;

This just results in a static rectangle. Any tips on what im doing wrong? Thanks, Jack

##### Share on other sites
In your code glRotate() is called between glBegin() and glEnd(). Try moving the glRotate call before glBegin. Most other OpenGL functions should not be called between glBegin and glEnd neither.

##### Share on other sites
Thanks that seems to be working now :), however the rotation is incredibly fast and barely visible, how can i get the speed of the rotation under control?

I have calculated and used delta time for some other areas of my program and linked it up with velocity calculations, but im not sure how or if you can apply delta time to a rotation movement to get the speed under control?

Thanks again,

Jack

##### Share on other sites
First of all you should make 'angle' a float if it isn't already.
This way you can make smaller changes to the angle.
To control the speed of rotation in relation with delta time,
you need to add delta time to the angle calculation.

For example:
If you want the quad to rotate 360 degrees in two seconds,
you must calculate a speed for the rotation.

speed = 360 deg / 2000 ms = 0.18

"Speed" means the amount of degrees to rotate in one millisecond.
To get the correct rotation, just multiply with delta time(milliseconds):

angle += delta_time * speed

This should produce the same speed of rotation on different computers.

##### Share on other sites
Thanks alot, works perfectly.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 13
• 9
• 15
• 14
• 46
• ### Forum Statistics

• Total Topics
634060
• Total Posts
3015300
×