How would you go about creating a camera in a square room in 3D, standing in the center of the room looking down negative z-axis and be able to walk around in x and z directions and when turning your head i.e. camera, have the camera then walk to the new direction? All I can do is move my head by changing the center_x and center_z values of the gluLookAt() function, and then my feet don't rotate to the new direction but continue walking along negative z-axis when pressing up arrow key. Anybody dealt with this problem before? I am thinking of having one grand fixed coordinate system where the center of the room is x=z=0 and y=-5 or 5 depending if I move the room down or camera up. I tried rotating the room around center first then translating it to new z-value, but all that did was make me face the wall and move me to the four corners of the room during rotation, however I was able to walk to new heading once the rotation stopped. Then I tried translating along z-axis first then rotate 90deg to right facing east wall (negative z is north wall), which worked properly, but the camera position hasn't changed (as if my head changed heading but my feet didn't)and I walked in north direction through the north wall while looking east, weird. Then I scrapped the translation and rotation, and used gluLookAt() but all I can do is move the position of camera in x,y and z-axis without turning it around itself. I messed with center_x and center_z values but that gave me a sweeping motion going from west wall to north wall then to east wall then stopping. Have and of you any idea how to move through the room like in Doom or other first person shooters? Any info is appreciated with a big Thank you, since I am slowly going mad

# Using gluLookAt() function

###
#1
Members - Reputation: **208**

Posted 03 November 1999 - 06:51 AM

###
#2
Members - Reputation: **122**

Posted 02 November 1999 - 01:14 PM

If you want to turn the camera to the right (clockwise around the y-axis), then essentially you need to rotate the world to the left (counter-clockwise around the y-axis).

It takes a little getting used to thinking this way and keeping this straight, but it'll become second nature soon.

###
#3
Members - Reputation: **122**

Posted 02 November 1999 - 02:19 PM

For something like this you can even just hold an angle for the direction CENTER is and use trig to translate it some arbitrary distance from the EYE. I'm getting back into this stuff and was going crazy with the same problem, and realized I did something really stupid. Since OpenGL uses degrees, and I had repressed radians from my memory, I kept on sending degrees to the math.h trig functions and was about ready to kill someone.

###
#4
Members - Reputation: **208**

Posted 02 November 1999 - 07:14 PM

Jerry

###
#5
Members - Reputation: **122**

Posted 02 November 1999 - 11:06 PM

I hope that i can help you with gluLookAt so let me begin:

In a room you are moving only along the x and z axis (until you will also move up or down). So you have e.g. float x = 0, z = 0, and angle = 0; angle is where you are looking at.

If you would like to move UP then you can compute it like this: z -= cos(angle), x += sin(angle). If you would like to move DOWN then use z += cos(angle), x -= sin(angle). To turn LEFT use: angle += (PI / 180.0f) * 1; if (angle > (PI * 2.0f)) angle = 0.0f; Zhis will turn you one degree clockwise and to turn RIGHT use: angle -= (PI / 180.0f) * 1; if (angle < 0.0f) angle = (PI * 2.0f); The only thing left is calling gluLookAt. This will lokk like this: gluLookAt(x, 0, z, x + sin(angle), 0, z - cos(angle), 0, 1, 0);

Try it...

VirtualNext

###
#6
Members - Reputation: **208**

Posted 03 November 1999 - 06:51 AM

I have solved the problem thanks to your suggestions and can now roam around the room It took me a while to realize how the LookAt function works. I came to the conclusion, as many of you have, that the look_at params of the function should be treated as a decomposed vector components. So if I want to look northeast I calculate the x and z components of the look_at vector then use them to move the eye point to the east by delta_x and north by delta_z. So now not only my head turned to the right corner of the room, but my feet travelled that direction also. I made the mistake of only updating my feet's z component and passing it to z_eye param without also updating my eye_x component, and the result was a movement in north direction (while looking east) but not also in east i.e. x direction. Thank you all