I want to create a projection matrix without using D3dx. This is the code I have so far:
They are both Left Handed matrices.
Code:
void Engine::CameraSetProjection(float fov, float aspect, float znear, float zfar)
{
float yscale = cos(fov)/sin(fov);
float xscale = aspect/yscale;
D3DMATRIX mat;
mat._11 = xscale;
mat._22 = yscale;
mat._33 = zfar/(zfar-znear);
mat._34 = 1;
mat._43 = -znear*zfar/(zfar-znear);
device->SetTransform(D3DTS_PROJECTION, &mat);
}
This is the formula d3dx uses to create a projection matrix:
Code:
xScale 0 0 0
0 yScale 0 0
0 0 zf/(zf-zn) 1
0 0 -zn*zf/(zf-zn) 0
where:
yScale = cot(fovY/2)
xScale = aspect ratio / yScale
How ever, that doesn't seem to be working. I am not seeing the triangles that I did when I used d3dx (I don't see any triangles). And the paramters stayed the same.
I belive my error is in the cot function, I read cot = cos/sin. I also tried cot = 1/tan but neither seem to work.
Any ideas?