PDA

View Full Version : Making alternativ gl_ModelViewMatrix

Mobsan
04-04-2005, 02:17 AM
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(lightPos.xyz - 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 * TI can't get this to work, what is wrong with my matrix?

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

Mobsan
04-05-2005, 03:00 AM
Could someone tell me which transfomations gl_ModelViewMatrix consists?

sqrt[-1]
04-05-2005, 04:22 AM
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);

once the standard matrix has been setup.

Mobsan
04-05-2005, 04:34 AM
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.

V-man
04-05-2005, 09:41 AM
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);