Retriving camera position

hi all,
i am working on a project based on a graphic library named OpenSG.
I want to add a couple of vertex/fragment programs, but i can’t get the position of the camera (it is stored into a private variable).
Is there a state variable holding that data?
something like the ole good

PARAM mvp[4] = { state.matrix.mvp };


PARAM camera[4] = { }

thank you!
the G.

No, because there is no OpenGL state that holds the camera position. However, you know that in eye space, the camera is always at the origin, so if you really need it, you could multiply the vector [0, 0, 0] with the inverse of the modelview matrix.

– Tom

thanks for the answer Tom,
just to check whether i’ve understood it clear, you are suggesting me this:

eye_cam * inv_mod_view
[0,0,0,1] *  | mvi00 mvi01 mvi02 mvi03 |
             | mvi10 mvi11 mvi12 mvi13 |
             | mvi20 mvi21 mvi22 mvi23 |
             | mvi30 mvi31 mvi32 mvi33 |

whis is equal, if i am not wrong to

camera pos = [mvi30 mvi31 mvi32 mvi33]

am I right? Thank you G.

That looks good to me. Make sure that you have only view transformations on the modelview stack, as I assume you don’t want model transformations to affect the view position.

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