# position of camera?

Hi, Guys,

I am a beginner. My question is how can
I get the world coordinate of camera? Thanks
for help.

Andy

The camera’s origin is 0,0,0; in openGL you move the world around the camera, which tends to confuse some people at first.

gluLookAt or just using glTranslate/glRotate you can change where the world space is relative to the camera.

gluLookAt(…);
// Draw your world

note: you can not use things like loadidentity after you set your camera position, since it clears your camera location back to 0,0,0.

Originally posted by andy_andy:
[b]Hi, Guys,

I am a beginner. My question is how can
I get the world coordinate of camera? Thanks
for help.

Andy[/b]

Thanks.

Originally posted by nexusone:
[b]The camera’s origin is 0,0,0; in openGL you move the world around the camera, which tends to confuse some people at first.

gluLookAt or just using glTranslate/glRotate you can change where the world space is relative to the camera.

gluLookAt(…);
// Draw your world

note: you can not use things like loadidentity after you set your camera position, since it clears your camera location back to 0,0,0.

[/b]

By the way, in your note, you wrote you can
not use things like loadidentity after you
set your camera position. Since camera is
always at 0,0,0, how can you set the
position of the camera? Thanks.

If I move a camera forward, this means
the world goes towards camera and camera
stays. How can I get the new coordinates of
all components in the world? Thanks.

Andy

Originally posted by nexusone:
[b]The camera’s origin is 0,0,0; in openGL you move the world around the camera, which tends to confuse some people at first.

gluLookAt or just using glTranslate/glRotate you can change where the world space is relative to the camera.

gluLookAt(…);
// Draw your world

note: you can not use things like loadidentity after you set your camera position, since it clears your camera location back to 0,0,0.

[/b]

Hi, nexusone,

Can you tell me how to compute the relative coordinates of camera to the world?
Thanks.

Andy

Originally posted by andy_andy:
[b]By the way, in your note, you wrote you can
not use things like loadidentity after you
set your camera position. Since camera is
always at 0,0,0, how can you set the
position of the camera? Thanks.

If I move a camera forward, this means
the world goes towards camera and camera
stays. How can I get the new coordinates of
all components in the world? Thanks.

Andy

[/b]

Generally there is a pretend camera, and you store its position. Then you translate the scene by the inverse of the camera position ie
glTranslatef(-Camera.X, -Camera.Y, -Camera.Z);
in this case the relative position of an object relative to the camera is Obj.X-Camera.X etc.
in general it’s ok to talk about the camera, but you should understand that it actually doesn’t exist

You must remember every time you change anything in your world, view, object,etc; you must redraw the world. So we have to store each objects location in a variable, from this we can track where they are at any point in time.

The objects in the world stay relative to each other, so if we move our camera say forward 10 units, then every thing in the world is also moved 10 units by only in relationship to our view of the world.

If we have two objects in our world that are say 4 units apart, there position relative to each other does not change. Only there position relative to the camera has changed.

Also think about how it would be in real life, you are watching a car moving say south. I start watching the car looking north, as the car goes pass, you turn to watch it. And at some point you have turned south to watch it drive off into the distance.

In openGL even though we are moving the world to the camera, to the car moving in our world it is still moving south.

Does this make any sense?

You really don’t need too since you have to set it each time you re-draw the scene. You set up a variable to store it current location and track its movement.

And from this and a little math you can come up with the relative position of it to any object in the scene.

If you need some help with 3D math, a google search will come up with some good sites on that.

Originally posted by andy_andy:
[b]Hi, nexusone,

Can you tell me how to compute the relative coordinates of camera to the world?
Thanks.

Andy

[/b]