Making alternativ gl_ModelViewMatrix

Hi I got a problem with making an alternativ gl_ModelViewMatrix matrix.

   mat4 T; // T-matrix
   T[0] = vec4( 1.0, 0.0, 0.0, -lightPos.x );
   T[1] = vec4( 0.0, 1.0, 0.0, -lightPos.y );
   T[2] = vec4( 0.0, 0.0, 1.0, -lightPos.z );
   T[3] = vec4( 0.0, 0.0, 0.0, 1.0 );

   vec3 n; vec3 u; vec3 v;
   n = -normalize( - vec3(0.0, 0.0, 0.0)); // LOOK AT
   v = normalize(cross(vec3(0.0, 0.0, 1.0),n)); // UP Vector
   u = normalize(cross(v,n));

mat4 viewTOlight; //R
   viewTOlight[0].x = u.x;  viewTOlight[0].y = u.y;  viewTOlight[0].z = u.z;  viewTOlight[0].w = 0.0;
   viewTOlight[1].x = v.x;  viewTOlight[1].y = v.y;  viewTOlight[1].z = v.z;  viewTOlight[1].w = 0.0;
   viewTOlight[2].x = n.x;  viewTOlight[2].y = n.y;  viewTOlight[2].z = n.z;  viewTOlight[2].w = 0.0;
   viewTOlight[3].x = 0.0;  viewTOlight[3].y = 0.0;  viewTOlight[3].z = 0.0;  viewTOlight[3].w = 1.0;

   mat4 V = viewTOlight * T; // R * T

I can’t get this to work, what is wrong with my matrix?
Im using this for shadowMapping.

I want these to be identical
gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * gl_Vertex;
gl_Position = gl_ProjectionMatrix * V * gl_Vertex;

Could someone tell me which transfomations gl_ModelViewMatrix consists?

The model view matrix consists of whatever you set when the glMatrixMode is set to GL_MODELVIEW. (ie all the glRotate, glTranslate etc calls)
It usually consists of the tranformation from model space into camera space (hence modelview) How this is setup is app specific so I doubt anyone can help you. (This is not even really that advanced)

If you just want the value in a sepeate matrix, just call

GLfloat array[16];
glGetFloatv(GL_MODELVIEW_MATRIX, array);

//Pass array to shader

once the standard matrix has been setup.

Forgot to tell that I am only using RenderMonkey.
I am not able to make any OpenGL commands.

I want to make a modelViewMatrix out of my light possition, so i can use it for shadowMapping.

For mat4 T
T[0] and the others are for setting up the columns of the matrices so you need to transpose your matrix.

The last column would be
T[3] = vec4(-lightPos.x, -lightPos.y, -lightPos.z, 1.0);

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