Advertisement

First Person Shooter questions

Started by April 15, 2002 09:44 AM
3 comments, last by ironhell3 22 years, 10 months ago
Hi, i have made it to the point of making a simple world for a first person shooter,with mouse move but without collision.i just limit the up-down and left-right variables so as not hitting the walls (it is a suare room with four walls)The problem is that when you are at the center and press the left key the room rotates normally. but when you are very close to the edges, if i press the left key, the room rotates very weird( i cant describe it very good, it just looks light i have a tiny room with only the four walls)The drawing code is the following: glColor3f(1.0f,1.0f,1.0f); glTranslatef(0.0f,-1.0f,-10.0f+up); glRotatef(mx,0.0f,0.1f,0.0f);//mouse rotation glRotatef(left,0.0f,1.0f,0.0f);//left-right key rotation glTranslatef(0.0f,0.0f,0.0f+left/10); sample+=1; level1(); Thanks for your help!
Are you sure that you do rotate the room relatively to the viewer? If the code you presented here is the only one where you do all rotations, then the problem is in that you always rotate your room relatively to the one and the same point (independent of the viewer location), this point is - center of the room, because if you are in the center, rotations work fine!
So you have to translated(Player->x_coord, Player->y_coord, Player->z_coord); before you rotate

Best regards!
Advertisement
Thanks! i will try that!

I tried the above method but it seems i didn''t full understand.... I tried when i rotate the room to translate into the same direction(is''nt what you suggested?), but only weird problems happen.Cn you explain more?


The correct way would be to:

1) translate(-posX, -posY, -posZ)
2) rotate(-rotX, -rotY, -rotZ)
3) Draw level

pos being the position of the camera and rot being the rotation of the camera (duh!).
the minus signs are to ensure that the level is moved relative to the camera.

Happy coding!

<hr />
Sander Marechal<small>[Lone Wolves][Hearts for GNOME][E-mail][Forum FAQ]</small>

This topic is closed to new replies.

Advertisement