Jump to content
  • Advertisement
Sign in to follow this  
ehmdjii

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.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
Share on other sites
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]

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!