MATRIX* ComputeViewMatrixRH(MATRIX *pOut, const VECTOR3 *pEye, const VECTOR3 *pLookAt, const VECTOR3 *pUp) { VECTOR3 zAxis = *pEye - *pLookAt; Vector3Normalize(&zAxis, &zAxis); VECTOR3 xAxis; Vector3Cross(&xAxis, pUp, &zAxis); Vector3Normalize(&xAxis, &xAxis); VECTOR3 yAxis; Vector3Cross(&yAxis, &zAxis, &xAxis); pOut->m[0][0] = xAxis.x; pOut->m[0][1] = yAxis.x; pOut->m[0][2] = zAxis.x; pOut->m[0][3] = 0.0f; pOut->m[1][0] = xAxis.y; pOut->m[1][1] = yAxis.y; pOut->m[1][2] = zAxis.y; pOut->m[1][3] = 0.0f; pOut->m[2][0] = xAxis.z; pOut->m[2][1] = yAxis.z; pOut->m[2][2] = zAxis.z; pOut->m[2][3] = 0.0f; pOut->m[3][0] = Vector3Dot(&xAxis, pEye); pOut->m[3][1] = Vector3Dot(&yAxis, pEye); pOut->m[3][2] = Vector3Dot(&zAxis, pEye); pOut->m[3][3] = 1.0f; return pOut; }

The perspective Matrix I compute like DirectX in Right Hand System

MATRIX* ComputeProjectionMatrixRH(MATRIX* pOut, float fovY, float aspectRatio, float zn, float zf) { float yScale = 1/tan(fovY/2); float xScale = yScale / aspectRatio; pOut->m[0][0] = xScale; pOut->m[0][1] = 0.0f; pOut->m[0][2] = 0.0f; pOut->m[0][3] = 0.0f; pOut->m[1][0] = 0.0f; pOut->m[1][1] = yScale; pOut->m[1][2] = 0.0f; pOut->m[1][3] = 0.0f; pOut->m[2][0] = 0.0f; pOut->m[2][1] = 0.0f; pOut->m[2][2] = zf/(zn-zf); pOut->m[2][3] = -1.0f; pOut->m[3][0] = 0.0f; pOut->m[3][1] = 0.0f; pOut->m[3][2] = zn*zf/(zn-zf);pOut->m[3][3] = 0.0f; return pOut; }

Now I'm confused with that because some books and pages in Internet show the projection matrix different. I tested all matrix but anything works.

For example other perspective projection matrix for right hand system is this:

1/tan(alpha/2)*aspect, 0 , 0 , 0 0 , 1/tan(alpha/2), 0 , 0 0 , 0 ,(f+n)/(f-n) , 1 0 , 0 , 2*f*n/(n-f), 0

What's the correct matrix?? Why many matrices for perspective projection???

Thanks!