change camera position via modelview matrix


I’m trying to manipulate the camera position from within a vertex shader. (The question is about the math, not using the shader)

Background: I want to render from a light position to calculate an opacity shadow map. I don’t have full control over the rendering pipeline and have to perform this transformation in a vertex shader.

I can be confident that there are no modelling transformations applied to my geometry - I only ever move the camera. But the camera position can obviously be a combination of rotations and translations.

Is there a way I can generate my own modelview matrix if I know the camera target and position?

EDIT… googles Glulookat, finds answer

I’ve now constructed my matrix but can’t seem to get the next step correct.
I thought I could use my new matrix as follows:

gl_Position = gl_ProjectionMatrix * myviewmatrix * gl_Vertex;

  • in order to generate a view from a particular position.
    I’ve tried reversing the order of the to matrix multiplies but the result is most definitely wrong.

Am I missing something?

well i solved the problem. I was constructing the matrix as per the glulookat documentation , but missed the line at the end stating that “gluLookAt is equivalent to glMultMatrixf(M); glTranslated (-eyex, -eyey, -eyez);”
As soon as I add the translation to the last column of my matrix all is good.