create custom modelviewmatrix in GLSL

This topic is 3816 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

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!

Share on other sites
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.

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));}

Share on other sites
thanks,

wow its way more code than i expected.

Share on other sites
Why aren't u using gluLookAt?

Share on other sites
because i would like to do it in GLSL and there is no glulookat as far as i know.

Share on other sites
Quote:
 Original post by ehmdjiibecause 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]

Share on other sites
because i would like to generate a depthmap for shadow mapping in ATIs rendermonkey software. and there you dont have access to the fixed function pipeline, only to the shaders, afaik.

1. 1
2. 2
3. 3
Rutin
15
4. 4
khawk
13
5. 5
frob
12

• 9
• 9
• 11
• 11
• 23
• Forum Statistics

• Total Topics
633665
• Total Posts
3013246
×