Sign in to follow this  
PS2

projection matrix

Recommended Posts

PS2    122
Hi guys,

I followed the information regarding building a perspective projection matrix from this link: [url="http://www.songho.ca/opengl/gl_projectionmatrix.html"]http://www.songho.ca...tionmatrix.html[/url] 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);
////////////////////////////////////////////////////////////////////////////////
//http://www.songho.ca/opengl/gl_projectionmatrix.html
///////////////////////////////////////////////////////////////////////////////
//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);
perspective.update();
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;
ortho.update();
}
}[/source]


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
};[/source]


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

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