ok, this is more the math side of the translating
Now, if i remember correct from pre-cal..
you use A and D to rotate around the Y axis, and you get an angle..
and, if you want it to move in a certain angle, you have to add an X and a Z. And, i remember that (on a 2d plane) COS is the x and SIN is the y
well why doesn't moving around just work if you do
x+=cos(yrotation);
z+=sin(yrotation);
and then glTranslatef(x,0,z); (since, you don't want to move up or down the y axis, just forward)
BUT that does not work at all, the moving is completely off and i have no idea why
here are the actual equations.. if it helps at all
and the translationCode:if (keys['W']) //if pressing forward { xmov += sin(yrot) / 1000; //figure out how much to move x zmov += cos(yrot) / 1000; //figure out how much to move z } if (keys['S']) // if pressing back { xmov -= sin(yrot) / 1000; //figure out how much to move x zmov -= cos(yrot) / 1000; //figure out how much to move z } if (keys['A']) // if rotating left { if (yrot > 359.9) //if the yrot is getting too big yrot = 0; //then reset it back to 0 yrot+=0.14f; //rotate it .14 deg } if (keys['D']) //if rotating right { if (yrot < 0.1) //if the yrot is getting too small yrot = 359.9; //then reset it yrot-=0.14f; //rotate it .14 deg }
the rotation works, but the moving is weird.Code:glTranslatef(xmov,0,zmov); //translate it with the distances glRotatef(yrot,0.0f,1.0f,0.0f); //rotate it
**i'm moving a box i've created using 6 squares
and heres the question: why doesn't that work, and how do you actually do it?



LinkBack URL
About LinkBacks


