This topic is now archived and is closed to further replies.



Recommended Posts

Hey, Can neone tell me what is the exact matrix operation applied by gluPerspective(fovy,aspect,near,far) I do have some idea but i am not sure how to do the same thing which this command does. I need to know the exact details so that i can write my own function which does the same thing.(just for learning!!) Thanx On course to my first FPS engine , zoooooom

Share this post

Link to post
Share on other sites
Ripped out of various chunks of code I have on my HDD at the moment (had to modify it for general viewing, but it should work or be close to doing so):

GLfloat some_matrix[4][4];

void glFrustum(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near, GLdouble far) {
GLfloat RsubL = right - left;
GLfloat TsubB = top - bottom;
GLfloat FsubN = far - near;
GLfloat Nmul2 = 2.0f * near;

some_matrix[0][1] = some_matrix[0][2] = some_matrix[0][3] = some_matrix[1][0] = some_matrix[1][2] = some_matrix[1][3] = some_matrix[3][0] = some_matrix[3][1] = some_matrix[3][3] = 0.0f;
some_matrix[2][3] = -1.0f;

some_matrix[0][0] = Nmul2 / RsubL;
some_matrix[2][0] = (right + left) / RsubL;

some_matrix[1][1] = (Nmul2) / TsubB;
some_matrix[2][1] = (top + bottom) / TsubB;

some_matrix[2][2] = -(far + near) / FsubN;
some_matrix[3][2] = (-far * Nmul2) / FsubN;

void gluPerspective(GLdouble fov, GLdouble aspect, GLdouble near, GLdouble far) {
GLdouble ymax = near * tan(0.5 * fov);
GLdouble ymin = -ymax;
GLdouble xmin = ymin * aspect;
GLdouble xmax = ymax * aspect;

glFrustum(xmin, xmax, ymin, ymax, near, far);

The source code of Mesa3D is helpful for questions like these.

Share this post

Link to post
Share on other sites