Perspective Projection Matrix

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

Recommended Posts

Hi everyone! I'm trying to use a perspective projection matrix for a uni assignment. My current problem is when I times my verticies against the matrix I get some form of distance perspective but as my shape moves towards the screen it moves from bottom right to top left staying the same size and then suddenly gets bigger and jumps back down to the bottom right. I'm probably doing something silly as I havn't done prospective projection before. Hopfully my code is straight forward. I normalise my vectors within my draw algorithm.
static double mat[4][4] = { { 1, 0, 0, 0 },
{ 0, 1, 0, 0 },
{ 0, 0, 1, -2*FRAME_WIDE },
{ 0, 0, 1, 0 } };
static double mat1[4][4];
static double mat2[4][4];
static double matp[4][4];
static double pointx = FRAME_WIDE/2;
static double pointy = FRAME_HIGH/2;
memcpy( mat1, identityd, sizeof(double) * 16);
mat1[0][3] = pointx;
mat1[1][3] = pointy;
MatrixTimes44by44( mat1, mat, mat2 );
mat1[0][3] = -pointx;
mat1[1][3] = -pointy;
MatrixTimes44by44( mat2, mat1, matp );
for( int i = 0; i < vjs->vertices->size; ++i ) {
MatrixTimes44by44( matp, vjs->mat, mat1 );
MatrixTimes44by4( mat1, (int*)&vjs->original->v.pos, (int*)&vjs->vertices->v.pos );
}


Thanks for your help!

Share on other sites
Creating a perspective matrix really depends on which subsystem you are using. DirectX and OpenGL use different matrices (since one use lefthanded and the other righthanded coordinate systems).

A good reference for perspective matrices are the microsoft directx webpage or the opengl reference book. Another good reference on how they work would be this

1. 1
2. 2
Rutin
23
3. 3
JoeJ
20
4. 4
5. 5

• 22
• 40
• 23
• 13
• 13
• Forum Statistics

• Total Topics
631733
• Total Posts
3001927
×