# coordinate problems

Hi.
I am a student attempting to develop what would to me appear to be a very
basic application
On screen is a wire frame sphere. Its purpose is to roll around the screen
under cursor key controll.
If user presses up then it rolls forward in that direction (back inverse)
and left and right steer the marble.
I have one large problem. In order to make the marble roll, i have to (i
believe) do a glRotatef(degs,x,y,z) to rotate it prior to re-drawing the
marble. However, when i do this it naturally rotates the whole axis system
and so i can no longer do a simple glTranslatef(x,y,z) to move the marble
The only way i could see to do it was to glLoadIdentity() to reset the coord
system, but then i loose the rotation!
Note because is simulating on a flat surface, Z plane is fixed.

How can i solve this simple problem please??

call glTranslatef before glRotate

that’s all well and good for one movement & rotation combination but when i come to move it a second time, the coodrinate system is still rotatated after the last combination. the only thing i could do to reset this was to glLoadIdentity but then i loose the rotation position!!

Originally posted by sdom100:
that’s all well and good for one movement & rotation combination but when i come to move it a second time, the coodrinate system is still rotatated after the last combination. the only thing i could do to reset this was to glLoadIdentity but then i loose the rotation position!!

You could store the rotation information and add the second rotation to it. Each frame do a glLoadIdentity(), glTranslate() and glRotate() based on the stored global translation and rotation information

HTH

Jean-Marc.

sounds like we are getting closer to the ans.
but when you say store the position and rotation. how exactly do you mean… variables?
if so then i get into problems of having to track its xy position and orientation through a number of arbitrary turns and moves

It might be easier to set up variables to track you’re ball’s location and rotation. However, you can keep your translations/rotations using glPushMatrix() and glPopMatrix()

ie.

glPushMatrix(); // Save your current matrix.
glRotated(…); // Rotate.
glPopMatrix(); // Restore matrix.
glTranslated(…); // Move ball.

You’d still have to track the rotations though.

thanks, that’s exactly what i’ve ended up working out. I move the ball, save to the stack, rotate it (rotation is held in variable) then when i come to move it again i load off the stack the ball with no rotation and do over again