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();
Rotation (dumb problem)
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.:
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.
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.
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?
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.
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.
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);
if your object is positioned at, say, 1,1,-2 do the following
glTranslatef(-1,-1,2)
glRotatef()
glTranslatef(1,1,-2);
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement