Making gl_ModelViewMatrix

uniform vec4 viewPos;
void main(void)
{
   vec3 n = normalize(-viewPos.xyz); // MOT
   vec3 v = normalize(cross(vec3(0.0,1.0,0.0),n)); //SIDEN
   vec3 u = normalize(cross(v,n)); // OPP

   mat4 T;
   T[0].x = 1.0;  T[0].y = 0.0;  T[0].z = 0.0;  T[0].w = -viewPos.x;
   T[1].x = 0.0;  T[1].y = 1.0;  T[1].z = 0.0;  T[1].w = -viewPos.y;
   T[2].x = 0.0;  T[2].y = 0.0;  T[2].z = 1.0;  T[2].w = -viewPos.z;
   T[3].x = 0.0;  T[3].y = 0.0;  T[3].z = 0.0;  T[3].w = 1.0; 

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

V = R * T;

gl_Position = gl_ProjectionMatrix * V * gl_Vertex;
}

Whats wrong?
do it have something to do with right/left handed system?

Shouldn’t the last line read:

 gl_Position = V * gl_ProjectionMatrix * gl_Vertex;
 

?
Also, how do you declare the V?

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