//yrot is the value I passed into OpenGl
//this way: glRotatef(yrot,0,1,0)
It works perfectly. However if I want to strafe left\right I have to swap sin and cos(at least I calculated this with pencil&paper) but this doesn´t work.
Why?
P.s.:Perhaps I did something wrong ´cause I cannot find a precise definition of the angle
-part of glrotatef(…);
I think you must also swap the sin-cos :
to strafe right try using:
xpos+= cos(yrotpiover180) * speed;
zpos-= sin(yrotpiover180) * speed;
update:
And perhaps you must clean your code.
If your code works, then you probably using something like that :
glRotate(360-yrot,0,1,0);
I found that because in my code I use glRotate(yrotation,0,1,0); and I walk with :
void walk(float a)
{
position[0] -= (float)sin(yrotation0.0174532925f) * adt;
position[2] += (float)cos(yrotation0.0174532925f) * adt;
}
//speed=a*dt
[This message has been edited by pavlos (edited 09-20-2000).]
I looked at the problem and your solutions are both right:One needs to swap cos\sin and negate one of them to strafe.I just ignored the signs in my drawing.
Thanx for your help!
Greets, XBTC!
[This message has been edited by XBCT (edited 09-23-2000).]
I walk through a maze in one of my programs and this is what I use to do the strafe:
case ‘0’: //sidestep left
incrementX = sin(Theta*(pi/180)-pi/2) * 0.2;
incrementY = cos(Theta*(pi/180)-pi/2) * 0.2;
tempX = transX - (2incrementX) + int((gridsize-1)/2);
tempY = transY - (2incrementY) + int((gridsize-1)/2);
if (maze.showcolor(int((gridsize-1) - tempX),int((gridsize-1) - tempY))>0)
{
transX = transX - incrementX;
transY = transY - incrementY;
}
break;
case ‘.’: //sidestep right
incrementX = sin(Theta*(pi/180)-pi/2) * 0.2;
incrementY = cos(Theta*(pi/180)-pi/2) * 0.2;
tempX = transX + (2incrementX) + int((gridsize-1)/2);
tempY = transY + (2incrementY) + int((gridsize-1)/2);
if (maze.showcolor(int((gridsize-1) - tempX),int((gridsize-1) - tempY))>0)
{
transX = transX + incrementX;
transY = transY + incrementY;
}
break;
and it works. I know it’s been resolved but it is helpful to see it again sometimes.
If it makes it easier to under stand, you could simply add 90 degrees and subtract 90 degrees and use the same equation. It adds a little to the computation, but if its easier/faster to get something done versus sitting down a calculating, then you could optimize later.