# Position of the camera?

Hi
I need to know the position of the camera and use it in a vertex shader. I know how to define it (glulookat(…)) but is there a way to have it directly in the vertex shader or a function in OpengL, that return the position of the camera (then, i can simply give the position as parameter to the vertex shader)?
Thanks

OpenGL has no “camera”. The eye coordinates are such that the eye is in the origin (0,0,0), which means the camera position in model space can be found as the inverse translation of the modelview matrix’ third column.
Check the OpenGL Programming Guide Appendix F: “Homogenous Coordinates and Transformation Matrices”.

gl_ModelViewMatrixInverse[3]

OpenGL has no “camera”.
hehe…sure it does

as i see it, “camera” is just shorthand for “coordinate system”. so in asking for the position of the camera, he’s really asking for the origin of the camera’s coordinate system relative to some other coordinate system (like the world’s). after all it takes two to tango.

i’ve seen this a lot and i don’t understand the reluctance to accept the camera analogy. it’s no biggie though…i just think the camera metaphor is a particularly good one. it sure helps this boney knob…

regards,

Yes, I wanted to emphasize that OpenGL doesn’t offer a special camera object like you would find it in scenegraph APIs, but you need to handle it via the modelview and projection matrices which is not difficult. You do not move a camera in OpenGL, you move the world inversely. It’s just a different point of view (pun intended ) to get used to on the way to understand OpenGL transformations.

how can we find the camera target which have values that are not the origin ?

Originally posted by airseb:
how can we find the camera target which have values that are not the origin ?
Hi airseb,
The camera target, which is not a single point, can be parameterized with t in [0, inf]:
target: [0, inf] -> R^3
target(t) = invMW * [0,0,t,1]’ =
t*invMW[third column]+invMW[fourth column]

Diego

actually I forget a minus:
target(t) = invMW * [0,0,-t,1]’
since the increasing depth direction is -z.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.