View Full Version : How to get eye (observer) position in space ?
10-17-2009, 07:14 PM
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. :)
10-18-2009, 02:29 AM
The camera is always at 0, 0, 0.
Simply translate the world in the opposite direction :
10-18-2009, 07: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).
10-18-2009, 08:36 AM
if i m not wrong
if observer at
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
10-18-2009, 08: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?
10-18-2009, 09:01 AM
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?
10-18-2009, 09: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
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)
10-18-2009, 09:09 AM
while thread is not created by me but i want to say thanks
10-19-2009, 07:58 AM
thats it. I was looking for it.
Thank you marshats :)
Powered by vBulletin® Version 4.2.3 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.