Jump to content
• Advertisement

# projection matrix

This topic is 2558 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);
////////////////////////////////////////////////////////////////////////////////
//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

##### Share on other sites
Advertisement

• Advertisement
• Advertisement

• ### Popular Contributors

1. 1
2. 2
3. 3
Rutin
19
4. 4
5. 5
• Advertisement

• 10
• 14
• 30
• 13
• 11
• ### Forum Statistics

• Total Topics
631782
• Total Posts
3002338
×

## 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!