PDA

View Full Version : How to get eye (observer) position in space ?



aistee
10-17-2009, 06:14 PM
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. :)

ZbuffeR
10-18-2009, 01:29 AM
The camera is always at 0, 0, 0.
Simply translate the world in the opposite direction :
glMatrixMode(GL_MODELVIEW);
glTranslate(-x,-y,-z);

aistee
10-18-2009, 06:46 AM
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).

vivek vyas
10-18-2009, 07:36 AM
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

aistee
10-18-2009, 07:50 AM
Thx for replying,

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?

vivek vyas
10-18-2009, 08:01 AM
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

marshats
10-18-2009, 08:04 AM
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 (http://www.songho.ca/opengl/gl_transform.html) 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. (http://glprogramming.com/red/chapter03.html) 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 (http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Main=50855&Number=2631 34#Post263134)

vivek vyas
10-18-2009, 08:09 AM
while thread is not created by me but i want to say thanks

aistee
10-19-2009, 06:58 AM
thats it. I was looking for it.

Thank you marshats :)