Jump to content

  • Log In with Google      Sign In   
  • Create Account

Using gluLookAt() function


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 JD   Members   -  Reputation: 208

Like
Likes
Like

Posted 03 November 1999 - 06:51 AM

Hi all,

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


Sponsor:

#2 Kyle Radue   Members   -  Reputation: 122

Like
Likes
Like

Posted 02 November 1999 - 01:14 PM

You want to keep track of the camera's rotation and position and as the player turns/moves use those variables to rotate/translate the world.

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 logistix   Members   -  Reputation: 122

Like
Likes
Like

Posted 02 November 1999 - 02:19 PM

You probably want to set up a point that tells where the EYE (x,y,z) is and a vector that tells what direction the CENTER is from the eye. When you set up gluLookAt() you add the Eye Position to the Vector Coords and use that for the CENTER. So if you're turning right or left, the vector rotates accordingly, and if you're going forward or back, you move the EYE towards or away from the vector.

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 JD   Members   -  Reputation: 208

Like
Likes
Like

Posted 02 November 1999 - 07:14 PM

Thank you all for the suggestions you've made. I am still trying to figure this out. One thing I did was to use sin() and cos() functions to get the new x and z coordinates for the look_at params that I use in gluLookAt(). When I press delete key I increment angle by 2 degrees and my head moves west, when I press end key I decrement the angle and my head rotates east, so far so good. I haven't thought about the translation though just yet. Meanwhile, I've been messing with D3DX utility lib and so far I like how they let you left and right multiply your vectors with the matrix. I think this would help when thinking about having one grand fixed coord system or many local ones attached to the objects, I think Thank you once more.

Jerry


#5 VirtualNext   Members   -  Reputation: 122

Like
Likes
Like

Posted 02 November 1999 - 11:06 PM

Hi JD

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 JD   Members   -  Reputation: 208

Like
Likes
Like

Posted 03 November 1999 - 06:51 AM

Once again you guys are the greatest!!!

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





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS