Sign in to follow this  
Darobat

Rotating Around a point

Recommended Posts

Greetings. I have a quad that I am trying to rotate around the z axis. However, it rotates from the top left of the screen, not from the center of the quad. I currently have
	glRotatef(guy.rot, 0.0f, 0.0f, 1.0f);
	EnableTextures();
	guyTex.Bind();
	glBegin(GL_QUADS);
		glTexCoord2f(0.0f, 1.0f); glVertex2f(guy.x, guy.y);	// Top Left
		glTexCoord2f(1.0f, 1.0f); glVertex2f(guy.x + 32, guy.y);	// Top Right
		glTexCoord2f(1.0f, 0.0f); glVertex2f(guy.x + 32, guy.y + 32);	// Bottom Right
		glTexCoord2f(0.0f, 0.0f); glVertex2f(guy.x, guy.y + 32);	// Bottom left
	glEnd();
I tried glTranslatef() to move to the center of the bitmap, but that didn't work either. 32 is the height of the bitmap Thanks.

Share this post


Link to post
Share on other sites
You said you tried glTranslatef, but where did you place it because placement is important. If you want to rotate around a specific point, then you would, generally, translate to that point and then rotate . . . if this doesn't work then make sure you are not messing up the matrices by pushing a matrix at the beginning and poping after you draw.

Also, what are you doing in EnableTextures(), because that could be throwing values off.

Share this post


Link to post
Share on other sites
window.BeginOrtho();
glTranslatef(guy.x + 16, guy.y + 16, 0.0f);
glRotatef(guy.rot, 0.0f, 0.0f, 1.0f);
EnableTextures();
guyTex.Bind();
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 1.0f); glVertex2f(guy.x - 16, guy.y - 16); // Top Left
glTexCoord2f(1.0f, 1.0f); glVertex2f(guy.x + 16, guy.y - 16); // Top Right
glTexCoord2f(1.0f, 0.0f); glVertex2f(guy.x + 16, guy.y + 16); // Bottom Right
glTexCoord2f(0.0f, 0.0f); glVertex2f(guy.x - 16, guy.y + 16); // Bottom left
glEnd();
window.EndProjection();
Thats what I'm trying when i go to the middle of the bitmap first. EnableTexture() only calls glEnable(GL_TEXTURE_2D). Begin Ortho looks like:
void COGLWindow::BeginOrtho()
{
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();

gluOrtho2D(0, width, height, 0);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
}

Share this post


Link to post
Share on other sites
When you translate the position, try
glTranslatef(guy.x,guy.y,0.0f);

and then when you specify the vertices, use -16, and 16 instead of guy.x+16 . . . and so on, because you've translated the position, so all you need are the width and height.

I think the problem you are having is that you are adding 16 to the translation which will through off your results along with specifying the position as if it weren't in model view coordinates.

If you are not sure what I'm talking about, then reply and I'll explain.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this