Sign in to follow this  
AdamGL

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();
        glLoadIdentity();
        glTranslatef(x, y, z);
        glRotatef(var, 0.0f, 1.0f, 0.0f);
          
          glPushMatrix();
              DrawHead(textureID);
          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 this post


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


Link to post
Share on other sites
Quote:
Original post by AdamGL
That 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 this post


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


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

Share this post


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


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


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


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


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


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