PDA

View Full Version : Beginner trying to use transformations.

Running_Wolf
01-08-2001, 06:41 PM
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.

zed
01-09-2001, 10:13 AM
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