Rotation (dumb problem)

Recommended Posts

I'm making a little game where you got this guy who can aim up or down. So I make him aim up but the rotation seems to rotate at an origin off screen so it goes around a wide circle. I don't know how to change it so that the object rotates in the middle of itself. Here is some code.:
glPushMatrix();
glTranslatef(x, y, z);
glRotatef(var, 0.0f, 1.0f, 0.0f);

glPushMatrix();
glPopMatrix();

glPushMatrix();
glTranslatef(1.0f, -26.0f, 0.0f);
DrawBody(textureID);
glPopMatrix();

glPushMatrix();
glRotatef(aimer, 0.0f, 0.0f, 1.0f);
glTranslatef(-9.0f, -26.0f, 0.0f);
DrawGun(textureID);
glPopMatrix();

glPushMatrix();
glTranslatef(0.0f, 200.0f, 0.0f);
DrawLegs(textureID);
glPopMatrix();
glPopMatrix();


where the function calls to the different parts of the body is simply a textured quad. anyone know what I am doing wrong? P.S. The 'aimer' variable is what changes the angle of rotation for the gun.

Share on other sites
First translate, then rotate.

That didn't help

Share on other sites
make the player aim position [0,0,0].... and then use push/pop for targets etc..

Share on other sites
I don't get it. I draw my gun(translate to where i want it) and now i want to rotate it. I can't set anything to 0,0,0 if the guy is supposed to move around.

Share on other sites
Quote:
 Original post by AdamGLThat didn't help

What happened when you did it?

Also, what is the problem more specifically- the gun not rotating properly, or the entire object?

Share on other sites
the gun is not rotating properly. It completely moves off my guy and floats in the air. Its as if it rotates around a point off the screen, like its orbiting.

Share on other sites
Is this 2d? If so, do you mean for your first rotation to be about the y axis?

Share on other sites
this is 2d and my object has the proper rotation along the z axis so that it spins. Its just that it orbits a point instead of spinning in place.

Share on other sites
to rotate about the center of an object first translate it to the origin, do your rotation and then translate back.

if your object is positioned at, say, 1,1,-2 do the following

glTranslatef(-1,-1,2)
glRotatef()
glTranslatef(1,1,-2);

Share on other sites
i don't know it didn't seem to work. Think you can use my code in the example. Thta would clear things up and If it still doesn't work I have a pic to explain myself better:

IGNORE THE LEGS I DIDNT FINISH THEM

Share on other sites
your picture isn't showing up. put a link to the picture instead, because the file is too large or something for it to be posted it on here.

Share on other sites
looks like i can't get the picture to show up and I can't link to it because of my cruddy free hosting. srry.

Share on other sites
can't you just post it on image shack or something like that? try putting it on image shack, and then have a link to that page where your image is displayed.

Share on other sites
What kind of coordinates does DrawGun() use for it's vertices? It just makes a rectangle around (0, 0), right?

Share on other sites
Well, I actually draw using 0,0 as my top left corner. I use glVertexi().

Share on other sites
Allright, that should be good enough. Are you absolutely positively sure that swapping the two lines "glRotatef(aimer, 0.0f, 0.0f, 1.0f);" and "glTranslatef(-9.0f, -26.0f, 0.0f);" in the code you posted does not fix this?

Share on other sites
yup, it didn't do a thing to change it.

Share on other sites
After translating, push a matrix and then rotate.

Create an account

Register a new account

• Forum Statistics

• Total Topics
627778
• Total Posts
2979026

• 11
• 10
• 10
• 23
• 9