• Advertisement
Sign in to follow this  

Rotation (dumb problem)

This topic is 4564 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

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
Advertisement
make the player aim position [0,0,0].... and then use push/pop for targets etc..

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
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 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
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 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
Well, I actually draw using 0,0 as my top left corner. I use glVertexi().

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
After translating, push a matrix and then rotate.

Share this post


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

  • Advertisement