• Advertisement
Sign in to follow this  

Basic OpenGL Rotation

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

If you intended to correct an error in the post then please contact us.

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();
	glBegin(GL_QUADS);
	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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement