Sign in to follow this  
BabyGGuy

Perspective Projection Matrix

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[i].pos, (int*)&vjs->vertices->v[i].pos );
}

Thanks for your help!

Share this post


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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this