Beginner trying to use transformations.

I am trying to make a maze that someone can move through. The problem is that when I rotate the ‘camera’ in the ModelView matrix and then try to move forward the ‘player’ stills moves straight forward. Meaning that the ‘player’ continues along the z axis with no respect as to the angle of the view. I decided to use some trigonometry to find the amount of x and z that the ‘player’ moves each time using sin and cos. But when I put these equations into my program I get unpredictable results. Sometimes I go up, others I go straight along the z axis. It even messes up when I try to go forwards without even turning. It usually goes off to the left. I don’t have my code with me but basically I:

  • do rotations
  • do translations
  • draw world

Should I do it in a different order or something? Am I using the wrong trig functions? Thanks for any replies. My friend and I are just starting with OpenGL. When I have me code I will post it. Thanks again.

dir = players direction from 0-360 degrees
pos = players position
x-z is the ground plane , y is up

pos.x += sin( dir* degrees to radians)
pos.z += cos( dir* degrees to radians)

glPushMatrix()
glTranslatef(pos.x,pos.y,pos.z)
glRotatef(dir,0,1,0)
draw player
glPopMAtrix()

hopefully that should work

I just worked out a method for moving around quake3/half-life style if you want to look at it its here http://members.home.net/gradyfield/project2.zip on my slow web space that the @home cheapskates give out to their customers. questions you can email to gradyfield@home.com

[This message has been edited by grady (edited 01-09-2001).]

Thanks for all the replies.