create custom modelviewmatrix in GLSL
hello,
in GLSL how can i create a modelviewmatrix from a camerapoint and a targetpoint. (and possibly upvector)
the two points are given as vec3.
(pretty much the same as gluLookAt does)
thanks!
You need to have a look at the source code. This is my own version of gluLookAt.
camerapoint is eyePosition3D
and
target would be center3D
Of course, you need to supply a upVector.
camerapoint is eyePosition3D
and
target would be center3D
Of course, you need to supply a upVector.
void glhLookAtf2(GLfloat *matrix, GLfloat *eyePosition3D, GLfloat *center3D, GLfloat *upVector3D){ GLfloat forward[3], side[3], up[3]; GLfloat matrix2[16], constant, resultMatrix[16]; forward[0]=center3D[0]-eyePosition3D[0]; forward[1]=center3D[1]-eyePosition3D[1]; forward[2]=center3D[2]-eyePosition3D[2]; NormalizeVectorFLOAT_1(forward, &constant); //Side = forward x up ComputeNormalOfPlaneFLOAT_2(side, forward, upVector3D); NormalizeVectorFLOAT_1(side, &constant); //Recompute up as: up = side x forward ComputeNormalOfPlaneFLOAT_2(up, side, forward); matrix2[0]=side[0]; matrix2[4]=side[1]; matrix2[8]=side[2]; matrix2[12]=0.0; matrix2[1]=up[0]; matrix2[5]=up[1]; matrix2[9]=up[2]; matrix2[13]=0.0; matrix2[2]=-forward[0]; matrix2[6]=-forward[1]; matrix2[10]=-forward[2]; matrix2[14]=0.0; matrix2[3]=matrix2[7]=matrix2[11]=0.0; matrix2[15]=1.0; MultiplyMatrices4by4OpenGL_FLOAT(resultMatrix, matrix, matrix2); glhTranslatef2(resultMatrix, -eyePosition3D[0], -eyePosition3D[1], -eyePosition3D[2]); memcpy(matrix, resultMatrix, 16*sizeof(GLfloat));}
Quote:Original post by ehmdjii
because i would like to do it in GLSL and there is no glulookat as far as i know.
huh? Why would you want to do it in GLSL?
[Edited by - V-man on June 28, 2008 7:53:20 PM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement