• Advertisement
Sign in to follow this  

projection matrix

This topic is 2407 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 guys,

I followed the information regarding building a perspective projection matrix from this link: http://www.songho.ca...tionmatrix.html but it doesn't work as expected. Here are my projection and orthogonal matrices:
[source]void init()
float fovY = imomath::PI/2.0;
float aspect = MainWnd().sizex/(float)MainWnd().sizey;
float zn = 1.0;
float zf = 100.0f;

float f = 1 / tan(fovY * float(0.5));
float n = 1 / (zf - zn);
//projection/ortho perspective
using imomath::matrix44;
using imomath::vector4;
perspective.proj = matrix44::Zero();
perspective.proj(0,0) = f/aspect;
perspective.proj(1,1) = f;
perspective.proj(2,2) = -(zn+zf)*n; perspective.proj(2,3) = -1.0;
perspective.proj(3,2) = -2*zn*zf*n;
perspective.position = imomath::vector4f(0.0f, 0.0f, 0.0f, 0.0f);
ortho.position = imomath::vector4::Zero();
ortho.proj = matrix44::Identity();
ortho.proj(0,0) = 2.0f/MainWnd().sizex;
ortho.proj(1,1) = 2.0f/MainWnd().sizey;
ortho.proj(2,2) = -2.0f * n; ortho.proj(2,3) = -(zn+zf)*n;

My vertices array looks like the following:

[source] GLfloat vVertices[] = { -0.5f, 0.5f, 0.0f, //pos
0.0f, 0.0f, 1.0f,1.0f, //color
-0.5f, -0.5f, 0.0f,
0.0f, 0.0f, 1.0f,1.0f,
0.5f, -0.5f, 0.0f,
0.0f, 0.0f, 1.0f,1.0f,
0.5f, 0.5f, 0.0f,
0.0f, 0.0f, 1.0f,1.0f

Only the orthogonal matrix seems to work when the z value of each vertex is 0 and the near plane is set to z=0. The perspective projection matrix doesn't work at all since when z=0 the vertex ends up with w=0.

Any help is appreciated. Thanks.

Share this post

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

  • Advertisement