Jump to content
  • Advertisement
Sign in to follow this  
AdamGL

Rotation (dumb problem)

This topic is 4861 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
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
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!