Jump to content
  • Advertisement
Sign in to follow this  
BabyGGuy

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.

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

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


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

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!