# How to get eye (observer) position in space ?

Hi,

how can I get the position of my eye in opengl ? I mean i have some data displayed, adn i’m moving, rotating, etc and i need to specify the exact position of position where am I on screen.

I need it to display some data in case of reaching exact area in space (x, y, z).

Thanks for help in advence.

The camera is always at 0, 0, 0.
Simply translate the world in the opposite direction :
glMatrixMode(GL_MODELVIEW);
glTranslate(-x,-y,-z);

i dont quite understand … I will explain what i want to accomplish.

In 0,0,0 i have some object, and I’m rotating around him, and also zooming.

What i need is current position of eye (observer).

if i m not wrong
if observer at
10,10,10
using gluLookAt to positioned at 10,10,10

do you want to display that position

then it will be use of fprintf (for console application) function
otherwise i don’t get it

I’m not using GluLookAt, but:

glTranslatef for zooming (z axis)
glRotatef for spinning - one for y and one for x axis.

The only way to get position is to transform somehow arguments from this functions, or if there is any other way?

hay dude

i don’t know how to make a look At
but i think you had saw the function definition of the gluLookAt
but the Q i think you know the definition

while i think the position is given by User/Developer(You)
why you want the position(x,y,z) value while you already knew/gave?
Good Luck

It sounds like what you are trying to find is the eye in Local Coordinates of your original object, not in global fixed coordinates. Is that correct?

Take a look at OpenGL Transformations and scroll down to section “Eye Coordinates”. When you scale and rotate your object you are computing the ModelView MAtrix. You can get that matrix with code

``````
GLfloat m[16];
glGetFloatv(GL_MODELVIEW_MATRIX, m);

``````

then since [x,y,z,w]_eye = (0,0,0,1), you can compute your eye location in local object coordinates with your [x,y,z] = Inverse(m)[x,y,z,w]_eye=Inverse(m)[0,0,0,1]. This is messy because you have to compute the inverse of m manually.

This is a common problem, so common that OpenGL provides a better way to think of the eye/camera and locating objects in the scene – gluLookAt. gluLookAt places your camera where you want in relation to your fixed scaled object. You can then think about moving the camera that way you always “know” the camera position explicitly. Try looking at OpenGL Redbook Chapter 3. and give it a good read. It is well worth the effort.

There was another post that may be helpful explaining gluLookAt after you read Chapter 3 – see Post263134

while thread is not created by me but i want to say thanks

thats it. I was looking for it.

Thank you marshats