# Thread: Can anyone help me with perspective projection?

1. ## Can anyone help me with perspective projection?

Hey all...

I was wondering if anyone could tell me where I am going wrong when implementing a perspective matrix.
The math for creating the matrix appears to be correct from what I can tell, however the end result is a stretched out distorted shape that takes up the entire screen, which is a far cry from the basic cube i had rendering before.
This is purely an educational exercise, hence why I have laid out the matrix deceleration this way..

Creation

Code :
```static Matrix4 CreatePerspectiveMatrix(float fov, float aspect, float zNear, float zFar) {
Matrix4 r;

float zRange = zNear - zFar;
float zTotal = zNear + zFar;

r.m[0][0] = 1.0f / (tanThetaOver2);			r.m[0][1] = 0;						r.m[0][2] = 0;					r.m[0][3] = 0;
r.m[1][0] = 0;								r.m[1][1] = aspect / tanThetaOver2;	r.m[1][2] = 0;					r.m[1][3] = 0;
r.m[2][0] = 0;								r.m[2][1] = 0;						r.m[2][2] = zTotal/zRange;	    r.m[2][3] = 2 * zFar * zNear / zRange;
r.m[3][0] = 0;								r.m[3][1] = 0;						r.m[3][2] = -1;					r.m[3][3] = 0;

return r;
}```

Implementation

Code :
```	void Game::Draw()
{
m_display->SwapBuffer();
m_renderer.Draw();
Matrix4 mtxModel = m_transform.GetMatrix();
Matrix4 mtxProjection = Matrix4::CreatePerspectiveMatrix(60.0f, m_display->GetAspectRatio(), 10.0f, 1000);
Matrix4 mtxModelProjection = mtxProjection * mtxModel;
m_renderer.DrawMesh(m_mesh);
//assert(glGetError() == GL_NO_ERROR);
}```

End result
Capture_1.jpg