View Full Version : Position of the camera?
05-03-2005, 08:11 AM
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)?
05-03-2005, 08:23 AM
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".
Java Cool Dude
05-03-2005, 10:59 AM
05-03-2005, 11:19 AM
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...
05-03-2005, 11:19 PM
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.
05-08-2005, 06:22 AM
how can we find the camera target which have values that are not the origin ?
05-09-2005, 05:31 AM
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]
05-09-2005, 05:42 AM
actually I forget a minus:
target(t) = invMW * [0,0,-t,1]'
since the increasing depth direction is -z.
Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.